@@ -36,12 +36,48 @@ class _HomeState extends State<Home> {
3636 }
3737
3838 void _addTarefa () {
39+ if (_tarefaController.text == "" ) {
40+ showDialog (
41+ context: context,
42+ builder: (BuildContext context) {
43+ return AlertDialog (
44+ title: Text (
45+ "Sua tarefa está vazia!" ,
46+ ),
47+ content: Text ("Coloque alguma coisa nas suas tarefas :)" ),
48+ actions: < Widget > [
49+ IconButton (
50+ icon: Icon (Icons .close),
51+ onPressed: () {
52+ Navigator .of (context).pop ();
53+ })
54+ ],
55+ );
56+ });
57+ } else {
58+ setState (() {
59+ Map <String , dynamic > novaTarefa = Map ();
60+ novaTarefa["tittle" ] = _tarefaController.text;
61+ novaTarefa["estado" ] = false ;
62+ _tarefaController.text = "" ;
63+ _todoList.add (novaTarefa);
64+ _saveTarefas ();
65+ });
66+ }
67+ }
68+
69+ Future <Null > _recarregar () async {
70+ await Future .delayed (Duration (seconds: 1 ));
3971 setState (() {
40- Map <String , dynamic > novaTarefa = Map ();
41- novaTarefa["tittle" ] = _tarefaController.text;
42- novaTarefa["estado" ] = false ;
43- _tarefaController.text = "" ;
44- _todoList.add (novaTarefa);
72+ _todoList.sort ((a, b) {
73+ if (a["estado" ] && ! b["estado" ])
74+ return 1 ;
75+ else if (! a["estado" ] && b["estado" ])
76+ return - 1 ;
77+ else
78+ return 0 ;
79+ });
80+
4581 _saveTarefas ();
4682 });
4783 }
@@ -60,51 +96,51 @@ class _HomeState extends State<Home> {
6096 ),
6197 ),
6298 ),
63- body: SingleChildScrollView (
64- child: Column (
65- children: < Widget > [
66- Container (
67- padding: EdgeInsets .symmetric (vertical: 3 , horizontal: 15 ),
68- child: Row (
69- children: < Widget > [
70- Expanded (
71- child: TextField (
72- controller: _tarefaController,
73- style:
74- TextStyle (fontWeight: FontWeight .w500, fontSize: 14 ),
75- decoration: InputDecoration (
76- focusedBorder: UnderlineInputBorder (
77- borderSide: BorderSide (
78- color: Colors .indigo,
79- width: 1.4 ,
80- ),
81- ),
82- hintText: "Digite sua tarefa" ,
83- hintStyle: TextStyle (
84- fontSize: 15 ,
85- fontStyle: FontStyle .italic,
99+ body: Column (
100+ children: < Widget > [
101+ Container (
102+ padding: EdgeInsets .symmetric (vertical: 3 , horizontal: 15 ),
103+ child: Row (
104+ children: < Widget > [
105+ Expanded (
106+ child: TextField (
107+ controller: _tarefaController,
108+ style: TextStyle (fontWeight: FontWeight .w500, fontSize: 14 ),
109+ decoration: InputDecoration (
110+ focusedBorder: UnderlineInputBorder (
111+ borderSide: BorderSide (
112+ color: Colors .indigo,
113+ width: 1.4 ,
86114 ),
87115 ),
116+ hintText: "Digite sua tarefa" ,
117+ hintStyle: TextStyle (
118+ fontSize: 15 ,
119+ fontStyle: FontStyle .italic,
120+ ),
88121 ),
89122 ),
90- IconButton (
91- icon : Icon ( Icons .add),
92- onPressed : _addTarefa ,
93- iconSize : 40 ,
94- splashColor : Colors .lightGreenAccent ,
95- ) ,
96- ] ,
97- ) ,
123+ ),
124+ IconButton (
125+ icon : Icon ( Icons .add) ,
126+ onPressed : _addTarefa ,
127+ iconSize : 40 ,
128+ splashColor : Colors .lightGreenAccent ,
129+ ) ,
130+ ] ,
98131 ),
99- ListView .builder (
100- shrinkWrap: true ,
101- physics: ScrollPhysics (),
102- padding: EdgeInsets .only (top: 20.0 ),
103- itemCount: _todoList.length,
104- itemBuilder: itemBuilder,
132+ ),
133+ Expanded (
134+ child: RefreshIndicator (
135+ child: ListView .builder (
136+ padding: EdgeInsets .only (top: 20.0 ),
137+ itemCount: _todoList.length,
138+ itemBuilder: itemBuilder,
139+ ),
140+ onRefresh: _recarregar,
105141 ),
106- ] ,
107- ) ,
142+ ) ,
143+ ] ,
108144 ),
109145 );
110146 }
@@ -154,6 +190,7 @@ class _HomeState extends State<Home> {
154190 }),
155191 duration: Duration (seconds: 3 ),
156192 );
193+ Scaffold .of (context).removeCurrentSnackBar ();
157194 Scaffold .of (context).showSnackBar (snack);
158195 });
159196 },
0 commit comments