initial commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_shopping_list/data/dummy_items.dart';
|
||||
import 'package:flutter_shopping_list/widgets/new_item.dart';
|
||||
|
||||
class GroceryList extends StatefulWidget {
|
||||
const GroceryList({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _GroceryListState();
|
||||
}
|
||||
|
||||
class _GroceryListState extends State<GroceryList> {
|
||||
void _addItem() {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (ctx) => const NewItem()),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Your Groceries'),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: _addItem,
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemCount: groceryItems.length,
|
||||
itemBuilder: (ctx, index) => ListTile(
|
||||
title: Text(groceryItems[index].name),
|
||||
leading: Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
color: groceryItems[index].category.color,
|
||||
),
|
||||
trailing: Text(
|
||||
groceryItems[index].quantity.toString(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_shopping_list/data/categories.dart';
|
||||
|
||||
class NewItem extends StatefulWidget {
|
||||
const NewItem({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _NewItemState();
|
||||
}
|
||||
}
|
||||
|
||||
class _NewItemState extends State<NewItem> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Add a new item'),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
maxLength: 50,
|
||||
decoration: InputDecoration(
|
||||
label: Text('name'),
|
||||
),
|
||||
validator: (value) {
|
||||
return 'Demo...';
|
||||
},
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
label: Text('Quantity'),
|
||||
),
|
||||
initialValue: '1',
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
Expanded(
|
||||
child: DropdownButtonFormField(items: [
|
||||
for (final category in categories.entries)
|
||||
DropdownMenuItem(
|
||||
value: category.value,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 16,
|
||||
height: 16,
|
||||
color: category.value.color,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(category.value.title),
|
||||
],
|
||||
),
|
||||
),
|
||||
], onChanged: (value) {}),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user