import 'package:demo_hive/bloc/reminder_bloc.dart'; import 'package:demo_hive/bloc/reminder_event.dart'; import 'package:demo_hive/bloc/reminder_state.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'box_text_field.dart'; class ReminderWidget extends StatefulWidget { const ReminderWidget({Key key}) : super(key: key); @override _ReminderWidgetState createState() => _ReminderWidgetState(); } class _ReminderWidgetState extends State { TextEditingController notesController = TextEditingController(); TextEditingController titlesController = TextEditingController(); @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return BlocBuilder(builder: (context, state) { return Scaffold( appBar: AppBar( title: Text("Reminder Test"), automaticallyImplyLeading: false, actions: [Icon(Icons.delete)], ), body: Container( padding: EdgeInsets.symmetric(horizontal: 5).copyWith(top: 10), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Column( children: [ BoxTextField( colorIcon: state.isEmpty ? Colors.grey : Colors.red, textEditingController: titlesController, onPress: () { titlesController.clear(); BlocProvider.of(context).add(RemoveEvent()); }, onChanged: (value) { BlocProvider.of(context) .add(GetValueTitleEvent( title: value, )); }, hintText: "Title", maxLength: 20, ), SizedBox( height: 10, ), BoxTextField( textEditingController: notesController, onChanged: (value) {}, hintText: "Notes", maxLength: 50, ), ], ), RaisedButton( splashColor: Colors.transparent, highlightColor: Colors.transparent, onPressed: () { if (!state.isEmpty) { BlocProvider.of(context) .add(AddTitleEvent(title: titlesController.text)); } }, color: state.isEmpty ? Colors.grey : Colors.blue, child: Text( "Add", style: TextStyle(color: Colors.white), ), ), Padding( padding: const EdgeInsets.symmetric(vertical: 10), child: Text( "List Reminder", style: TextStyle( fontSize: 18, fontWeight: FontWeight.bold, ), ), ), Expanded( child: buildListView(state, context), ) ], ), ), ); }); } Widget buildListView(ReminderState state, BuildContext context) { if (state.list.isEmpty) { return Center( child: Text( "List is Empty", style: TextStyle(fontSize: 18), )); } if(state.isLoading == true){ return CircularProgressIndicator(); } return ListView.builder( physics: BouncingScrollPhysics(), itemCount: state.list.length, itemBuilder: (_, index) { return Container( height: 55, decoration: BoxDecoration( borderRadius: BorderRadius.circular(5), color: Colors.blue, ), padding: EdgeInsets.symmetric(horizontal: 20), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( state.list[index].title, style: TextStyle(color: Colors.white), ), InkWell( onTap: () { BlocProvider.of(context) .add(RemoveTitle(index: index)); }, child: Icon( Icons.delete, color: Colors.red, )) ], ), ); }, ); } }