Skip to content

Commit 06f7736

Browse files
change add note loading
1 parent a145c02 commit 06f7736

File tree

4 files changed

+46
-30
lines changed

4 files changed

+46
-30
lines changed

lib/cubits/add_note_cubit/add_note_cubit.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class AddNoteCubit extends Cubit<AddNoteState> {
1212
AddNoteCubit() : super(AddNoteInitial());
1313

1414
void addNote(NoteModel note) async {
15+
emit(AddNoteLoading());
1516
try {
16-
emit(AddNoteLoading());
1717
var notesBox = Hive.box<NoteModel>(kNoteBox);
1818
await notesBox.add(note);
1919
emit(AddNoteSuccess());

lib/views/widgets/add_note_bottom_sheet.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_bloc/flutter_bloc.dart';
3-
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
43
import 'package:notes_app/cubits/add_note_cubit/add_note_cubit.dart';
54
import 'package:notes_app/views/widgets/add_note_form.dart';
65

@@ -37,11 +36,9 @@ class AddNoteBottomSheet extends StatelessWidget {
3736
right: 16,
3837
bottom: MediaQuery.of(context).viewInsets.bottom,
3938
),
40-
child: ModalProgressHUD(
41-
inAsyncCall: state is AddNoteLoading ? true : false,
42-
child: const SingleChildScrollView(
43-
child: AddNoteForm(),
44-
),
39+
// state is AddNoteLoading ? true : false,
40+
child: const SingleChildScrollView(
41+
child: AddNoteForm(),
4542
),
4643
);
4744
},

lib/views/widgets/add_note_form.dart

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,35 @@ class _AddNoteFormState extends State<AddNoteForm> {
4141
subTitle = value;
4242
}),
4343
const SizedBox(height: 40),
44-
CustomerElevatedButtonInBottomSheet(
45-
onTap: () {
46-
if (formKey.currentState!.validate()) {
47-
formKey.currentState!.save();
48-
var noteModel = NoteModel(
49-
title: title!,
50-
subTitle: subTitle!,
51-
date: DateTime.now().toString(),
52-
coloe: Colors.yellow.value,
53-
);
54-
BlocProvider.of<AddNoteCubit>(context).addNote(noteModel);
55-
} else {
56-
autovalidateMode = AutovalidateMode.always;
57-
setState(() {});
58-
}
44+
BlocBuilder<AddNoteCubit, AddNoteState>(
45+
builder: (context, state) {
46+
return CustomerElevatedButtonInBottomSheet(
47+
isLoading: state is AddNoteLoading ? true : false,
48+
onTap: () {
49+
addNoteModel(context);
50+
},
51+
);
5952
},
6053
),
6154
const SizedBox(height: 20),
6255
],
6356
),
6457
);
6558
}
59+
60+
void addNoteModel(BuildContext context) {
61+
if (formKey.currentState!.validate()) {
62+
formKey.currentState!.save();
63+
var noteModel = NoteModel(
64+
title: title!,
65+
subTitle: subTitle!,
66+
date: DateTime.now().toString(),
67+
coloe: Colors.yellow.value,
68+
);
69+
BlocProvider.of<AddNoteCubit>(context).addNote(noteModel);
70+
} else {
71+
autovalidateMode = AutovalidateMode.always;
72+
setState(() {});
73+
}
74+
}
6675
}

lib/views/widgets/customer_elevated_button_in_bottom_sheet.dart

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ class CustomerElevatedButtonInBottomSheet extends StatelessWidget {
55
const CustomerElevatedButtonInBottomSheet({
66
super.key,
77
required this.onTap,
8+
this.isLoading = false,
89
});
910
final Function() onTap;
11+
final bool isLoading;
1012
@override
1113
Widget build(BuildContext context) {
1214
return GestureDetector(
@@ -19,14 +21,22 @@ class CustomerElevatedButtonInBottomSheet extends StatelessWidget {
1921
borderRadius: BorderRadius.circular(10),
2022
color: kPrimaryColor,
2123
),
22-
child: const Text(
23-
'Add Note',
24-
style: TextStyle(
25-
fontSize: 17,
26-
color: Colors.black,
27-
fontWeight: FontWeight.w600,
28-
),
29-
),
24+
child: isLoading
25+
? const SizedBox(
26+
height: 24,
27+
width: 24,
28+
child: CircularProgressIndicator(
29+
color: Colors.black,
30+
),
31+
)
32+
: const Text(
33+
'Add Note',
34+
style: TextStyle(
35+
fontSize: 17,
36+
color: Colors.black,
37+
fontWeight: FontWeight.w600,
38+
),
39+
),
3040
),
3141
);
3242
}

0 commit comments

Comments
 (0)