Skip to content

Commit 9990575

Browse files
committed
NotesView dimissible improved and longpress inkwell fixed
1 parent 3a2aa9e commit 9990575

8 files changed

+326
-240
lines changed

lib/pages/notesView.dart

+110-55
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/cupertino.dart';
22
import 'package:flutter/material.dart';
3+
import 'package:flutter_slidable/flutter_slidable.dart';
34
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
45
import 'package:givnotes/database/HiveDB.dart';
56
import 'package:givnotes/packages/unicorndial/speed_dial_controller.dart';
@@ -58,6 +59,13 @@ class NotesViewState extends State<NotesView> {
5859
return AnimationLimiter(
5960
child: ListView.builder(
6061
itemCount: _notes.length,
62+
//TODO maybe remove divider in const_notes_view and use separator
63+
// separatorBuilder: (context, index) => Divider(
64+
// height: 0.057 * wm,
65+
// color: Colors.black,
66+
// indent: 10,
67+
// endIndent: 10,
68+
// ),
6169
itemBuilder: (context, index) {
6270
_animateIndex = index;
6371
index = _notes.length - index - 1;
@@ -70,37 +78,43 @@ class NotesViewState extends State<NotesView> {
7078
child: SlideAnimation(
7179
verticalOffset: 25.0,
7280
child: FadeInAnimation(
73-
child: Dismissible(
81+
child: Slidable(
7482
key: UniqueKey(),
75-
background: Container(
76-
color: Var.isTrash ? Colors.teal[300] : Color(0xffEC625C),
77-
width: double.infinity,
78-
child: Row(
79-
mainAxisAlignment: MainAxisAlignment.end,
80-
children: [
81-
Icon(
82-
Var.isTrash ? Icons.restore : Icons.delete,
83-
size: 10 * wm,
84-
),
85-
SizedBox(width: 10 * wm)
86-
],
87-
),
88-
),
89-
direction: DismissDirection.endToStart,
90-
onDismissed: (direction) {
91-
if (!Var.isTrash) {
92-
note.trash = !note.trash;
93-
note.save();
83+
actionPane: SlidableBehindActionPane(),
84+
actionExtentRatio: 1.0,
85+
dismissal: SlidableDismissal(
86+
child: SlidableDrawerDismissal(),
87+
onDismissed: (actionType) {
88+
if (!Var.isTrash) {
89+
note.trash = !note.trash;
90+
note.save();
91+
print('moved to Trash');
92+
// Scaffold.of(context).showSnackBar(SnackBar(content: Text('moved to Trash')));
9493

95-
_multiSelectController.set(_notes.length);
96-
} else {
97-
note.trash = false;
98-
note.save();
99-
print('moved to notes');
94+
_multiSelectController.set(_notes.length);
95+
} else {
96+
note.trash = false;
97+
note.save();
98+
print('moved to Notes');
99+
// Scaffold.of(context).showSnackBar(SnackBar(content: Text('moved to Notes')));
100100

101-
_multiSelectController.set(_notes.length);
102-
}
103-
},
101+
_multiSelectController.set(_notes.length);
102+
}
103+
},
104+
),
105+
secondaryActions: <Widget>[
106+
!Var.isTrash
107+
? iconSlideAction(
108+
Colors.red,
109+
Icons.delete,
110+
'Trash',
111+
)
112+
: iconSlideAction(
113+
Color(0xff66a9e0),
114+
Icons.restore,
115+
'Resotre',
116+
),
117+
],
104118
child: NotesCard(
105119
note: note,
106120
index: index,
@@ -118,6 +132,7 @@ class NotesViewState extends State<NotesView> {
118132
),
119133
floatingActionButton: !_multiSelectController.isSelecting && !Var.isTrash
120134
? UnicornDialer(
135+
parentHeroTag: 'parent',
121136
parentButton: Icon(
122137
CupertinoIcons.add,
123138
color: Colors.white,
@@ -172,6 +187,37 @@ class NotesViewState extends State<NotesView> {
172187
);
173188
}
174189

190+
Widget iconSlideAction(Color color, IconData icon, String caption) {
191+
return IconSlideAction(
192+
// caption: 'Trash',
193+
color: color,
194+
// icon: Icons.delete,
195+
iconWidget: Row(
196+
crossAxisAlignment: CrossAxisAlignment.center,
197+
mainAxisAlignment: MainAxisAlignment.end,
198+
children: [
199+
Padding(
200+
padding: const EdgeInsets.only(right: 40),
201+
child: Column(
202+
mainAxisAlignment: MainAxisAlignment.center,
203+
children: [
204+
Icon(
205+
icon,
206+
color: Colors.white,
207+
),
208+
Text(
209+
caption,
210+
style: TextStyle(color: Colors.white),
211+
),
212+
],
213+
),
214+
)
215+
],
216+
),
217+
onTap: () => Scaffold.of(context).showSnackBar(SnackBar(content: Text('moved to Trash'))),
218+
);
219+
}
220+
175221
List<UnicornButton> unicornButton = [
176222
Var.isTrash
177223
? UnicornButton(
@@ -291,35 +337,44 @@ class NotesViewState extends State<NotesView> {
291337
}
292338
}
293339

294-
class NotesCardTemp extends StatefulWidget {
295-
NotesCardTemp({
296-
Key key,
297-
@required this.index,
298-
@required this.note,
299-
@required this.multiSelectController,
300-
this.notesViewUpdate,
301-
}) : super(key: key);
340+
// Dismissible(
341+
// key: UniqueKey(),
342+
// background: Container(
343+
// color: Var.isTrash ? Colors.teal[300] : Color(0xffEC625C),
344+
// width: double.infinity,
345+
// child: Row(
346+
// mainAxisAlignment: MainAxisAlignment.end,
347+
// children: [
348+
// Icon(
349+
// Var.isTrash ? Icons.restore : Icons.delete,
350+
// size: 10 * wm,
351+
// ),
352+
// SizedBox(width: 10 * wm)
353+
// ],
354+
// ),
355+
// ),
356+
// direction: DismissDirection.endToStart,
357+
// onDismissed: (direction) {
358+
// if (!Var.isTrash) {
359+
// note.trash = !note.trash;
360+
// note.save();
302361

303-
final int index;
304-
final NotesModel note;
305-
final MultiSelectController multiSelectController;
306-
final Function notesViewUpdate;
362+
// _multiSelectController.set(_notes.length);
363+
// } else {
364+
// note.trash = false;
365+
// note.save();
366+
// print('moved to notes');
307367

308-
@override
309-
_NotesCardTempState createState() => _NotesCardTempState();
310-
}
311-
312-
class _NotesCardTempState extends State<NotesCardTemp> {
313-
@override
314-
Widget build(BuildContext context) {
315-
return NotesCard(
316-
note: widget.note,
317-
index: widget.index,
318-
multiSelectController: widget.multiSelectController,
319-
notesViewUpdate: widget.notesViewUpdate,
320-
);
321-
}
322-
}
368+
// _multiSelectController.set(_notes.length);
369+
// }
370+
// },
371+
// child: NotesCard(
372+
// note: note,
373+
// index: index,
374+
// multiSelectController: _multiSelectController,
375+
// notesViewUpdate: refreshNotesView,
376+
// ),
377+
// ),
323378

324379
// return multiSelectController.isSelecting == false
325380
// ? OpenContainer(

lib/pages/zefyrEdit.dart

+12-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:intl/intl.dart';
1818

1919
enum NoteMode { Editing, Adding }
2020
Map<String, int> noteTagsMap = {};
21+
// final GlobalKey<ScaffoldState> zefyrScaffoldKey = GlobalKey<ScaffoldState>();
2122

2223
class ZefyrEdit extends StatefulWidget {
2324
ZefyrEdit({this.noteMode, this.note});
@@ -94,6 +95,7 @@ class ZefyrEditState extends State<ZefyrEdit> {
9495
@override
9596
void dispose() {
9697
// prefsBox.put('allTagsMap', _allTagsMap);
98+
noteTagsMap = {};
9799

98100
_zefyrController?.dispose();
99101
_zefyrfocusNode?.dispose();
@@ -156,12 +158,13 @@ class ZefyrEditState extends State<ZefyrEdit> {
156158
return WillPopScope(
157159
onWillPop: _onPop,
158160
child: Scaffold(
161+
// key: zefyrScaffoldKey,
159162
resizeToAvoidBottomInset: true,
160163
resizeToAvoidBottomPadding: true,
161164
extendBody: true,
162165
backgroundColor: Colors.white,
163166
appBar: ZefyrEditAppBar(
164-
saveNote: saveNote,
167+
saveNote: _saveNote,
165168
controls: controls,
166169
),
167170
body: SafeArea(
@@ -288,12 +291,14 @@ class ZefyrEditState extends State<ZefyrEdit> {
288291
note: _notesModel,
289292
noteTagsMap: noteTagsMap,
290293
noteIndex: _noteIndex,
294+
saveNote: _saveNote,
291295
),
292296
floatingActionButton: Var.noteMode == NoteMode.Editing && !Var.isEditing
293297
? Container(
294-
height: 18 * wm,
295-
margin: EdgeInsets.only(bottom: 5),
298+
// height: 18 * wm,
299+
margin: EdgeInsets.only(bottom: 15),
296300
child: FloatingActionButton(
301+
heroTag: 'parent',
297302
tooltip: 'Edit',
298303
backgroundColor: Colors.black,
299304
elevation: 5,
@@ -427,16 +432,17 @@ class ZefyrEditState extends State<ZefyrEdit> {
427432

428433
return true;
429434
} else if (title.isNotEmpty || note.isNotEmpty) {
430-
saveNote();
435+
_saveNote();
431436
//
432437
} else {
433438
updateEditMode(false);
434439
}
435440
return false;
436441
}
437442

438-
void saveNote() async {
439-
if (Var.isEditing == false) {
443+
void _saveNote({isDrawerSave = false}) async {
444+
print('isDrawerSave: $isDrawerSave');
445+
if (Var.isEditing == false && isDrawerSave == false) {
440446
//
441447
Var.noteMode = NoteMode.Adding;
442448
Navigator.pop(context);

lib/ui/addTagsDialog.dart

+11-3
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,16 @@ class _AddTagsDialogState extends State<AddTagsDialog> {
260260
String tagName = _newTagTextController.text.trim();
261261

262262
if (tagName.isEmpty) {
263-
showToast("Tag name is required");
263+
// showToast("Tag name is required");
264+
// zefyrScaffoldKey.currentState.showSnackBar(SnackBar(content: Text('Tag name is required')));
265+
// OneContext().showSnackBar(
266+
// builder: (_) => SnackBar(content: Text('My awesome snackBar!')),
267+
// );
268+
showFlashToast(context, 'Tag name is required');
269+
//
264270
} else if (selectTagColors.length != 1) {
265-
showToast("Please select a color");
271+
// showToast("Please select a color");
272+
showFlashToast(context, 'Please select a color');
266273
} else {
267274
colorValue = selectTagColors.first;
268275

@@ -288,7 +295,8 @@ class _AddTagsDialogState extends State<AddTagsDialog> {
288295
else
289296
noteTagsMap[tagName] = flag;
290297
} else {
291-
showToast("Tag already added");
298+
// showToast("Tag already added");
299+
showFlashToast(context, "Tag already added");
292300
}
293301
}
294302

0 commit comments

Comments
 (0)