Reputation: 21
*My error is the data add for but homepage not display and hot restart for data is the show Navigate(context) for not rebuild ui please right answer and solution there. *
github link is the here....
https://github.com/IamNikunjParmar/DataBase_Sqflite/tree/master/hive_DataBase_crud/lib
please check this link and my error sol this problem
floatingActionButton: FloatingActionButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text("Emp Details"),
actions: [
ElevatedButton(
onPressed: () {
EmployeeModal emp = EmployeeModal(
id: DateTime.now().millisecondsSinceEpoch,
name: nameController.text,
email: emailController.text,
number: 45456,
);
context.read<HomePageCubit>().onInsertEmp(emp);
// nameController.clear();
// emailController.clear();
Navigator.pop(context, true);
print("add: $emp");
},
child: const Text("Add"),
),
],
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: nameController,
decoration: const InputDecoration(
label: Text("name"),
),
),
TextField(
controller: emailController,
decoration: const InputDecoration(
label: Text("email"),
),
),
],
),
);
},
);
},
child: const Icon(Icons.add),
),
void onInsertEmp(EmployeeModal emp) {
try {
emit(const HomePageLoading());
empHelper.insertEmp(emp);
final currentState = state;
if (currentState is HomePageLoaded) {
final newList = List<EmployeeModal>.from(currentState.empList);
emit(HomePageLoaded(empList: newList));
eventBus.fire(EmpDataChanged());
}
} catch (e) {
emit(HomePageError(msg: e.toString()));
}
}
Upvotes: 2
Views: 52