Skip to content

Commit 452d447

Browse files
committed
update changes & bug fixes
1 parent c309eac commit 452d447

File tree

8 files changed

+159
-54
lines changed

8 files changed

+159
-54
lines changed

lib/constants/app_themes.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ class AppThemes {
1515
popupMenuTheme: const PopupMenuThemeData(
1616
color: lightBGColor,
1717
),
18+
elevatedButtonTheme: ElevatedButtonThemeData(
19+
style: ButtonStyle(
20+
backgroundColor: MaterialStateProperty.all(Colors.redAccent),
21+
),
22+
),
23+
textButtonTheme: TextButtonThemeData(
24+
style: ButtonStyle(
25+
foregroundColor: MaterialStateProperty.all(darkColor),
26+
),
27+
),
1828
textTheme: const TextTheme(
1929
bodyText1: TextStyle(color: darkColor),
2030
bodyText2: TextStyle(color: darkColor),
@@ -43,6 +53,16 @@ class AppThemes {
4353
popupMenuTheme: const PopupMenuThemeData(
4454
color: darkColor2,
4555
),
56+
elevatedButtonTheme: ElevatedButtonThemeData(
57+
style: ButtonStyle(
58+
backgroundColor: MaterialStateProperty.all(Colors.redAccent),
59+
),
60+
),
61+
textButtonTheme: TextButtonThemeData(
62+
style: ButtonStyle(
63+
foregroundColor: MaterialStateProperty.all(lightColor),
64+
),
65+
),
4666
textTheme: const TextTheme(
4767
bodyText1: TextStyle(color: lightColor),
4868
bodyText2: TextStyle(color: lightColor),

lib/models/pdf_data.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import 'package:grocery_list_maker/models/grocery_item.dart';
33
class PdfData {
44
final String? name;
55
final String? address;
6+
final String? title;
67
final List<GroceryItem?>? items;
78

8-
PdfData({this.name = '', this.address = '', required this.items});
9+
PdfData({
10+
this.name = '',
11+
this.address = '',
12+
this.title = '',
13+
required this.items,
14+
});
915
}

lib/pdf_helper/grocery_list.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Future<Uint8List> generateGroceryList(
1313
PdfData data,
1414
) async {
1515
final groceryList = GroceryListPdf(
16+
title: data.title ?? '',
1617
customerName: data.name ?? '',
1718
customerAddress: data.address ?? '',
1819
items: data.items,
@@ -31,6 +32,7 @@ String _formatDate(DateTime date) {
3132
class GroceryListPdf {
3233
final String customerName;
3334
final String customerAddress;
35+
final String title;
3436
final List<GroceryItem?>? items;
3537

3638
final PdfColor baseColor;
@@ -40,6 +42,7 @@ class GroceryListPdf {
4042
static const _lightColor = PdfColors.white;
4143

4244
GroceryListPdf({
45+
required this.title,
4346
required this.customerName,
4447
required this.baseColor,
4548
required this.accentColor,
@@ -102,7 +105,7 @@ class GroceryListPdf {
102105
pw.Container(
103106
alignment: pw.Alignment.center,
104107
child: pw.Text(
105-
'Grocery List',
108+
title,
106109
style: pw.TextStyle(
107110
color: baseColor,
108111
fontWeight: pw.FontWeight.bold,

lib/pdf_helper/pdf_builder.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import 'package:pdf/pdf.dart';
66
typedef LayoutCallbackWithData = Future<Uint8List> Function(
77
PdfPageFormat pageFormat, PdfData data);
88

9-
class Example {
10-
const Example(this.name, this.file, this.builder, [this.needsData = false]);
9+
class PdfLayout {
10+
const PdfLayout(this.name, this.file, this.builder, [this.needsData = false]);
1111

1212
final String name;
1313

lib/views/home.dart

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,26 @@ class HomePage extends StatelessWidget {
7676
);
7777
}
7878
if (items.isEmpty) {
79-
return Column(
80-
mainAxisSize: MainAxisSize.min,
81-
mainAxisAlignment: MainAxisAlignment.center,
82-
children: [
83-
SvgPicture.asset(
84-
"assets/empty_cart.svg",
85-
width: _deviceSize.width * 0.75,
86-
),
87-
const SizedBox(height: 20.0),
88-
Text(
89-
"No lists.",
90-
style: GoogleFonts.montserrat(
91-
color: Colors.grey,
92-
fontSize: 20.0,
79+
return SingleChildScrollView(
80+
child: Column(
81+
mainAxisSize: MainAxisSize.min,
82+
mainAxisAlignment: MainAxisAlignment.center,
83+
children: [
84+
SvgPicture.asset(
85+
"assets/empty_cart.svg",
86+
width: _deviceSize.width * 0.75,
87+
height: _deviceSize.height * 0.5,
9388
),
94-
)
95-
],
89+
const SizedBox(height: 20.0),
90+
Text(
91+
"No lists.",
92+
style: GoogleFonts.montserrat(
93+
color: Colors.grey,
94+
fontSize: 20.0,
95+
),
96+
)
97+
],
98+
),
9699
);
97100
}
98101
return ListView.builder(
@@ -144,22 +147,22 @@ class HomePage extends StatelessWidget {
144147
child: ListBody(
145148
children: const [
146149
Text(
147-
"Tap YES to confirm item deletion."),
150+
"Tap YES to delete the list."),
148151
],
149152
),
150153
),
151154
actions: [
152155
TextButton(
153156
onPressed: () {
154-
Navigator.pop(ctx, true);
157+
Navigator.pop(ctx, false);
155158
},
156-
child: const Text('YES'),
159+
child: const Text('NO'),
157160
),
158-
TextButton(
161+
ElevatedButton(
159162
onPressed: () {
160-
Navigator.pop(ctx, false);
163+
Navigator.pop(ctx, true);
161164
},
162-
child: const Text('NO'),
165+
child: const Text('YES'),
163166
),
164167
],
165168
);

lib/views/list_details.dart

Lines changed: 96 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ class ListDetailsPage extends StatefulWidget {
2323
class _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

Comments
 (0)