@@ -23,11 +23,21 @@ class ListDetailsPage extends StatefulWidget {
2323class _ListDetailsPageState extends State <ListDetailsPage > {
2424 int get _groceryListId => widget.initialItem.id.v! ;
2525 TextEditingController ? _nameTextController;
26+ TextEditingController ? _titleTextController;
2627 TextEditingController ? _addressTextController;
2728 List <GroceryItem ?>? items;
2829
2930 String _name = '' ;
3031 String _address = '' ;
32+ String _title = '' ;
33+
34+ @override
35+ void dispose () {
36+ _titleTextController? .dispose ();
37+ _nameTextController? .dispose ();
38+ _addressTextController? .dispose ();
39+ super .dispose ();
40+ }
3141
3242 @override
3343 Widget build (BuildContext context) {
@@ -66,14 +76,32 @@ class _ListDetailsPageState extends State<ListDetailsPage> {
6676 onSelected: (value) async {
6777 if (value == 0 ) {
6878 await showDialog (
69- barrierDismissible: false ,
7079 context: context,
80+ barrierDismissible: false ,
7181 builder: (ctx) {
7282 return AlertDialog (
7383 title: const Text ("Enter Details" ),
84+ actionsPadding: const EdgeInsets .symmetric (
85+ vertical: 16.0 ,
86+ horizontal: 16.0 ,
87+ ),
7488 content: SingleChildScrollView (
7589 child: ListBody (
7690 children: [
91+ TextFormField (
92+ decoration: const InputDecoration (
93+ labelText: 'Title' ,
94+ ),
95+ onChanged: (value) {
96+ setState (() {
97+ _title = value;
98+ });
99+ },
100+ controller: _titleTextController,
101+ textCapitalization:
102+ TextCapitalization .words,
103+ ),
104+ const SizedBox (height: 8.0 ),
77105 TextFormField (
78106 decoration: const InputDecoration (
79107 labelText: 'Name' ,
@@ -87,6 +115,7 @@ class _ListDetailsPageState extends State<ListDetailsPage> {
87115 textCapitalization:
88116 TextCapitalization .words,
89117 ),
118+ const SizedBox (height: 8.0 ),
90119 TextFormField (
91120 decoration: const InputDecoration (
92121 labelText: 'Address' ,
@@ -99,7 +128,6 @@ class _ListDetailsPageState extends State<ListDetailsPage> {
99128 controller: _addressTextController,
100129 keyboardType:
101130 TextInputType .multiline,
102- maxLines: 3 ,
103131 ),
104132 ],
105133 ),
@@ -111,7 +139,7 @@ class _ListDetailsPageState extends State<ListDetailsPage> {
111139 },
112140 child: const Text ('CANCEL' ),
113141 ),
114- TextButton (
142+ ElevatedButton (
115143 onPressed: () {
116144 Navigator .pop (ctx, true );
117145 Navigator .of (context).push (
@@ -121,6 +149,7 @@ class _ListDetailsPageState extends State<ListDetailsPage> {
121149 data: items,
122150 name: _name,
123151 address: _address,
152+ title: _title,
124153 );
125154 },
126155 ),
@@ -132,6 +161,43 @@ class _ListDetailsPageState extends State<ListDetailsPage> {
132161 );
133162 });
134163 }
164+ if (value == 1 ) {
165+ if (await showDialog (
166+ context: context,
167+ barrierDismissible: false ,
168+ builder: (ctx) {
169+ return AlertDialog (
170+ title: const Text ("Delete List?" ),
171+ content: SingleChildScrollView (
172+ child: ListBody (
173+ children: const [
174+ Text (
175+ "Tap YES to delete the list." ),
176+ ],
177+ ),
178+ ),
179+ actions: [
180+ TextButton (
181+ onPressed: () {
182+ Navigator .pop (ctx, false );
183+ },
184+ child: const Text ('NO' ),
185+ ),
186+ ElevatedButton (
187+ onPressed: () {
188+ Navigator .pop (ctx, true );
189+ },
190+ child: const Text ('YES' ),
191+ ),
192+ ],
193+ );
194+ }) ??
195+ false ) {
196+ await groceryProvider
197+ .deleteGroceryListItem (_groceryListId);
198+ Navigator .pop (context);
199+ }
200+ }
135201 },
136202 itemBuilder: (ctx) {
137203 return [
@@ -191,23 +257,26 @@ class _ListDetailsPageState extends State<ListDetailsPage> {
191257 );
192258 }
193259 if (items.isEmpty) {
194- return Column (
195- mainAxisSize: MainAxisSize .min,
196- mainAxisAlignment: MainAxisAlignment .center,
197- children: [
198- SvgPicture .asset (
199- "assets/empty_cart.svg" ,
200- width: deviceSize.width * 0.75 ,
201- ),
202- const SizedBox (height: 20.0 ),
203- Text (
204- "No items. List is empty." ,
205- style: GoogleFonts .montserrat (
206- color: Colors .grey,
207- fontSize: 20.0 ,
260+ return SingleChildScrollView (
261+ child: Column (
262+ mainAxisSize: MainAxisSize .min,
263+ mainAxisAlignment: MainAxisAlignment .center,
264+ children: [
265+ SvgPicture .asset (
266+ "assets/empty_cart.svg" ,
267+ width: deviceSize.width * 0.75 ,
268+ height: deviceSize.height * 0.5 ,
208269 ),
209- )
210- ],
270+ const SizedBox (height: 20.0 ),
271+ Text (
272+ "No items. List is empty." ,
273+ style: GoogleFonts .montserrat (
274+ color: Colors .grey,
275+ fontSize: 20.0 ,
276+ ),
277+ )
278+ ],
279+ ),
211280 );
212281 }
213282 return ListView .builder (
@@ -245,22 +314,22 @@ class _ListDetailsPageState extends State<ListDetailsPage> {
245314 child: ListBody (
246315 children: const [
247316 Text (
248- "Tap YES to confirm item deletion ." ),
317+ "Tap YES to delete the item ." ),
249318 ],
250319 ),
251320 ),
252321 actions: [
253322 TextButton (
254323 onPressed: () {
255- Navigator .pop (ctx, true );
324+ Navigator .pop (ctx, false );
256325 },
257- child: const Text ('YES ' ),
326+ child: const Text ('NO ' ),
258327 ),
259- TextButton (
328+ ElevatedButton (
260329 onPressed: () {
261- Navigator .pop (ctx, false );
330+ Navigator .pop (ctx, true );
262331 },
263- child: const Text ('NO ' ),
332+ child: const Text ('YES ' ),
264333 ),
265334 ],
266335 );
@@ -297,9 +366,9 @@ class _ListDetailsPageState extends State<ListDetailsPage> {
297366 );
298367 }));
299368 },
300- icon: Icon (
369+ icon: const Icon (
301370 Icons .add,
302- size: deviceSize.width * 0.1 ,
371+ size: 32.0 ,
303372 color: lightColor,
304373 ),
305374 padding: const EdgeInsets .all (0.0 ),
0 commit comments