11import 'dart:convert' ;
2- import 'package:flutter/cupertino .dart' ;
2+ import 'package:provider/provider .dart' ;
33import 'package:flutter/material.dart' ;
44import 'package:flutter_slidable/flutter_slidable.dart' ;
55import 'package:shared_preferences/shared_preferences.dart' ;
66import 'package:date_format/date_format.dart' ;
7- import 'package:todo_client/components/cursor_pointer.dart' ;
87import 'package:todo_client/main.dart' ;
8+ import 'package:todo_client/state/mainStore.dart' ;
99
1010class MainCore extends StatefulWidget {
1111 const MainCore ({Key ? key}) : super (key: key);
@@ -46,6 +46,12 @@ class TodoItem {
4646
4747enum TodoItemFilterType { all, active, compete }
4848
49+ Map <int , TodoItemFilterType > todoItemFilterTypeIndexMap = {
50+ 0 : TodoItemFilterType .all,
51+ 1 : TodoItemFilterType .active,
52+ 2 : TodoItemFilterType .compete,
53+ };
54+
4955class _MainCoreState extends State <MainCore > {
5056 String title = '' ;
5157 String description = '' ;
@@ -84,6 +90,10 @@ class _MainCoreState extends State<MainCore> {
8490 void initState () {
8591 super .initState ();
8692 init ();
93+ final window = WidgetsBinding .instance.window;
94+ window.onPlatformBrightnessChanged = () {
95+ context.read <MainStore >().changeTheme (window.platformBrightness);
96+ };
8797 }
8898
8999 void init () async {
@@ -122,7 +132,7 @@ class _MainCoreState extends State<MainCore> {
122132 spacing: 10 ,
123133 children: [
124134 TextFormField (
125- // initialValue: editTitle,
135+ initialValue: editTitle,
126136 onChanged: (value) => editTitle = value,
127137 decoration: titleDecoration,
128138 // decoration: titleDecoration,
@@ -167,11 +177,9 @@ class _MainCoreState extends State<MainCore> {
167177 border: OutlineInputBorder ());
168178
169179 var baseDeleteConfirmDialog = createDeleteConfirmDialog ();
170-
180+ final List < bool > _selectedListType = < bool > [ true , false , false ];
171181 @override
172182 Widget build (BuildContext context) {
173- Color primaryColor = Theme .of (context).primaryColor;
174-
175183 final ColorScheme colorScheme = Theme .of (context).colorScheme;
176184 final Color draggableItemColor = colorScheme.secondary;
177185
@@ -194,7 +202,9 @@ class _MainCoreState extends State<MainCore> {
194202 : filterType == TodoItemFilterType .active
195203 ? activeTodoList
196204 : completeTodoList;
197-
205+ Color actionBackgroundColor = context.watch <MainStore >().openNightMode
206+ ? Theme .of (context).cardColor
207+ : Colors .white;
198208 return Container (
199209 child: Column (children: [
200210 const Text (
@@ -207,6 +217,11 @@ class _MainCoreState extends State<MainCore> {
207217 controller: _tittleController,
208218 decoration: _titleInputDecoration,
209219 onChanged: (value) => setState (() => title = value),
220+ onSubmitted: (value) {
221+ if (value.isNotEmpty) {
222+ handleAddClick ();
223+ }
224+ },
210225 ),
211226 space,
212227 TextField (
@@ -247,10 +262,10 @@ class _MainCoreState extends State<MainCore> {
247262 children: [
248263 SlidableAction (
249264 icon: Icons .close_outlined,
265+ backgroundColor: actionBackgroundColor,
250266 onPressed: (BuildContext context) async {
251- bool res =
252- await baseDeleteConfirmDialog['show' ]! ();
253- if (res) {
267+ if (await baseDeleteConfirmDialog['show' ]! () !=
268+ null ) {
254269 setState (() {
255270 todoList.removeAt (index);
256271 });
@@ -262,6 +277,7 @@ class _MainCoreState extends State<MainCore> {
262277 ),
263278 SlidableAction (
264279 icon: Icons .edit,
280+ backgroundColor: actionBackgroundColor,
265281 onPressed: (_) =>
266282 handleEditPressed (index, renderTodoList),
267283 borderRadius:
@@ -270,39 +286,39 @@ class _MainCoreState extends State<MainCore> {
270286 ],
271287 ),
272288 child: Card (
273- child: ListTile (
274- title: Text (title,
275- style: TextStyle (
289+ child: AnimatedOpacity (
290+ opacity: checked ? 0.6 : 1 ,
291+ duration: const Duration (milliseconds: 300 ),
292+ child: ListTile (
293+ title: Text (title,
294+ style: TextStyle (
276295 decoration: decoration,
277- color:
278- checked ? Colors .grey : Colors .black)),
279- subtitle: description.isEmpty
280- ? null
281- : Text (description,
282- style: TextStyle (
296+ )),
297+ subtitle: description.isEmpty
298+ ? null
299+ : Text (description,
300+ style: TextStyle (
283301 decoration: decoration,
284- color: checked
285- ? Colors .grey
286- : const Color .fromRGBO (
287- 115 , 115 , 115 , 1 ))),
288- leading: Checkbox (
289- value: checked,
290- onChanged: (value) {
291- setState (() {
292- todoList[index].checked = value! ;
293- });
294- setPrefsTodoList ();
295- },
296- ),
297- trailing: Wrap (
298- spacing: 5 ,
299- children: [
300- Text (renderTodoList[index].updateTime),
301- ReorderableDragStartListener (
302- index: index,
303- child: const Icon (Icons .drag_handle_sharp),
304- )
305- ],
302+ )),
303+ leading: Checkbox (
304+ value: checked,
305+ onChanged: (value) {
306+ setState (() {
307+ todoList[index].checked = value! ;
308+ });
309+ setPrefsTodoList ();
310+ },
311+ ),
312+ trailing: Wrap (
313+ spacing: 5 ,
314+ children: [
315+ Text (renderTodoList[index].updateTime),
316+ ReorderableDragStartListener (
317+ index: index,
318+ child: const Icon (Icons .drag_handle_sharp),
319+ )
320+ ],
321+ ),
306322 ),
307323 ),
308324 ),
@@ -336,53 +352,35 @@ class _MainCoreState extends State<MainCore> {
336352 '${activeTodoList .length } item left' ,
337353 style: const TextStyle (fontSize: 16 ),
338354 ),
339- Wrap (
340- alignment: WrapAlignment .spaceBetween,
341- spacing: 10 ,
342- children: [
343- baseCursorPointer (CupertinoButton (
344- child: Text (
345- 'All' ,
346- style: TextStyle (
347- color: filterType == TodoItemFilterType .all
348- ? primaryColor
349- : Colors .black),
350- ),
351- onPressed: () =>
352- setState (() => filterType = TodoItemFilterType .all),
353- padding: const EdgeInsets .all (0 ),
354- )),
355- const SizedBox (
356- width: 10 ,
357- ),
358- baseCursorPointer (CupertinoButton (
359- child: Text (
360- 'Active' ,
361- style: TextStyle (
362- color: filterType == TodoItemFilterType .active
363- ? primaryColor
364- : Colors .black),
365- ),
366- onPressed: () =>
367- setState (() => filterType = TodoItemFilterType .active),
368- padding: const EdgeInsets .all (0 ),
369- )),
370- const SizedBox (
371- width: 10 ,
372- ),
373- baseCursorPointer (CupertinoButton (
374- child: Text (
375- 'Complete' ,
376- style: TextStyle (
377- color: filterType == TodoItemFilterType .compete
378- ? primaryColor
379- : Colors .black),
380- ),
381- onPressed: () =>
382- setState (() => filterType = TodoItemFilterType .compete),
383- padding: const EdgeInsets .all (0 ),
384- )),
355+ ToggleButtons (
356+ constraints: const BoxConstraints (
357+ minHeight: 40.0 ,
358+ minWidth: 80.0 ,
359+ ),
360+ children: const < Widget > [
361+ Text ('All' ),
362+ Text ('Active' ),
363+ Text ('Complete' )
385364 ],
365+ onPressed: (int index) {
366+ setState (() {
367+ for (int buttonIndex = 0 ;
368+ buttonIndex < _selectedListType.length;
369+ buttonIndex++ ) {
370+ if (buttonIndex == index) {
371+ _selectedListType[buttonIndex] =
372+ ! _selectedListType[buttonIndex];
373+ } else {
374+ _selectedListType[buttonIndex] = false ;
375+ }
376+ }
377+ filterType = todoItemFilterTypeIndexMap[index]! ;
378+ });
379+ },
380+ isSelected: _selectedListType,
381+ renderBorder: false ,
382+ fillColor: Colors .transparent,
383+ hoverColor: Colors .transparent,
386384 ),
387385 TextButton (
388386 child: const Text ('Clear complete' ),
@@ -410,16 +408,16 @@ Map<String, Function> createDeleteConfirmDialog(
410408 Widget baseAlertDialog = AlertDialog (
411409 title: const Text (
412410 "Tips" ,
413- textAlign: TextAlign .center,
414411 ),
415- actionsAlignment: MainAxisAlignment .center,
416412 content: Column (
417413 mainAxisSize: MainAxisSize .min,
414+ crossAxisAlignment: CrossAxisAlignment .start,
418415 children: < Widget > [
419- const Text ("Confirm delete?" ),
416+ const Text (
417+ "Confirm delete?" ,
418+ ),
420419 if (showNotTipsCheckBox)
421420 Row (
422- mainAxisAlignment: MainAxisAlignment .center,
423421 children: < Widget > [
424422 const Text ("Not tips?" ),
425423 StatefulBuilder (builder: (context, setState) {
0 commit comments