initial commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_shopping_list/models/category.dart';
|
||||
|
||||
const categories = {
|
||||
Categories.vegetables: Category(
|
||||
'Vegetables',
|
||||
Color.fromARGB(255, 0, 255, 128),
|
||||
),
|
||||
Categories.fruit: Category(
|
||||
'Fruit',
|
||||
Color.fromARGB(255, 145, 255, 0),
|
||||
),
|
||||
Categories.meat: Category(
|
||||
'Meat',
|
||||
Color.fromARGB(255, 255, 102, 0),
|
||||
),
|
||||
Categories.dairy: Category(
|
||||
'Dairy',
|
||||
Color.fromARGB(255, 0, 208, 255),
|
||||
),
|
||||
Categories.carbs: Category(
|
||||
'Carbs',
|
||||
Color.fromARGB(255, 0, 60, 255),
|
||||
),
|
||||
Categories.sweets: Category(
|
||||
'Sweets',
|
||||
Color.fromARGB(255, 255, 149, 0),
|
||||
),
|
||||
Categories.spices: Category(
|
||||
'Spices',
|
||||
Color.fromARGB(255, 255, 187, 0),
|
||||
),
|
||||
Categories.convenience: Category(
|
||||
'Convenience',
|
||||
Color.fromARGB(255, 191, 0, 255),
|
||||
),
|
||||
Categories.hygiene: Category(
|
||||
'Hygiene',
|
||||
Color.fromARGB(255, 149, 0, 255),
|
||||
),
|
||||
Categories.other: Category(
|
||||
'Other',
|
||||
Color.fromARGB(255, 0, 225, 255),
|
||||
),
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter_shopping_list/models/grocery_item.dart';
|
||||
import 'package:flutter_shopping_list/models/category.dart';
|
||||
import 'package:flutter_shopping_list/data/categories.dart';
|
||||
|
||||
final groceryItems = [
|
||||
GroceryItem(
|
||||
id: 'a',
|
||||
name: 'Milk',
|
||||
quantity: 1,
|
||||
category: categories[Categories.dairy]!),
|
||||
GroceryItem(
|
||||
id: 'b',
|
||||
name: 'Bananas',
|
||||
quantity: 5,
|
||||
category: categories[Categories.fruit]!),
|
||||
GroceryItem(
|
||||
id: 'c',
|
||||
name: 'Beef Steak',
|
||||
quantity: 1,
|
||||
category: categories[Categories.meat]!),
|
||||
];
|
||||
+10
-106
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_shopping_list/widgets/grocery_list.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
@@ -11,115 +13,17 @@ class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
// This is the theme of your application.
|
||||
//
|
||||
// TRY THIS: Try running your application with "flutter run". You'll see
|
||||
// the application has a purple toolbar. Then, without quitting the app,
|
||||
// try changing the seedColor in the colorScheme below to Colors.green
|
||||
// and then invoke "hot reload" (save your changes or press the "hot
|
||||
// reload" button in a Flutter-supported IDE, or press "r" if you used
|
||||
// the command line to start the app).
|
||||
//
|
||||
// Notice that the counter didn't reset back to zero; the application
|
||||
// state is not lost during the reload. To reset the state, use hot
|
||||
// restart instead.
|
||||
//
|
||||
// This works for code too, not just values: Most code changes can be
|
||||
// tested with just a hot reload.
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
title: 'Flutter Groceries',
|
||||
theme: ThemeData.dark().copyWith(
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
// This widget is the home page of your application. It is stateful, meaning
|
||||
// that it has a State object (defined below) that contains fields that affect
|
||||
// how it looks.
|
||||
|
||||
// This class is the configuration for the state. It holds the values (in this
|
||||
// case the title) provided by the parent (in this case the App widget) and
|
||||
// used by the build method of the State. Fields in a Widget subclass are
|
||||
// always marked "final".
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
// This call to setState tells the Flutter framework that something has
|
||||
// changed in this State, which causes it to rerun the build method below
|
||||
// so that the display can reflect the updated values. If we changed
|
||||
// _counter without calling setState(), then the build method would not be
|
||||
// called again, and so nothing would appear to happen.
|
||||
_counter++;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// This method is rerun every time setState is called, for instance as done
|
||||
// by the _incrementCounter method above.
|
||||
//
|
||||
// The Flutter framework has been optimized to make rerunning build methods
|
||||
// fast, so that you can just rebuild anything that needs updating rather
|
||||
// than having to individually change instances of widgets.
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
// TRY THIS: Try changing the color here to a specific color (to
|
||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
||||
// change color while the other colors stay the same.
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
// Here we take the value from the MyHomePage object that was created by
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
// Center is a layout widget. It takes a single child and positions it
|
||||
// in the middle of the parent.
|
||||
child: Column(
|
||||
// Column is also a layout widget. It takes a list of children and
|
||||
// arranges them vertically. By default, it sizes itself to fit its
|
||||
// children horizontally, and tries to be as tall as its parent.
|
||||
//
|
||||
// Column has various properties to control how it sizes itself and
|
||||
// how it positions its children. Here we use mainAxisAlignment to
|
||||
// center the children vertically; the main axis here is the vertical
|
||||
// axis because Columns are vertical (the cross axis would be
|
||||
// horizontal).
|
||||
//
|
||||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
|
||||
// action in the IDE, or press "p" in the console), to see the
|
||||
// wireframe for each widget.
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'You have pushed the button this many times:',
|
||||
),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
],
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: const Color.fromARGB(255, 147, 229, 250),
|
||||
brightness: Brightness.dark,
|
||||
surface: const Color.fromARGB(255, 42, 51, 59),
|
||||
),
|
||||
scaffoldBackgroundColor: const Color.fromARGB(255, 50, 58, 60),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
), // This trailing comma makes auto-formatting nicer for build methods.
|
||||
home: const GroceryList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum Categories {
|
||||
vegetables,
|
||||
fruit,
|
||||
meat,
|
||||
dairy,
|
||||
carbs,
|
||||
sweets,
|
||||
spices,
|
||||
convenience,
|
||||
hygiene,
|
||||
other
|
||||
}
|
||||
|
||||
class Category {
|
||||
const Category(this.title, this.color);
|
||||
|
||||
final String title;
|
||||
final Color color;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter_shopping_list/models/category.dart';
|
||||
|
||||
class GroceryItem {
|
||||
const GroceryItem({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.quantity,
|
||||
required this.category,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String name;
|
||||
final int quantity;
|
||||
final Category category;
|
||||
}
|
||||
@@ -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) {}),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -66,10 +66,10 @@ packages:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: flutter_lints
|
||||
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
|
||||
sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.3"
|
||||
version: "3.0.1"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@@ -79,10 +79,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: lints
|
||||
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
|
||||
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
version: "3.0.0"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -185,4 +185,4 @@ packages:
|
||||
source: hosted
|
||||
version: "0.4.2"
|
||||
sdks:
|
||||
dart: ">=3.2.6 <4.0.0"
|
||||
dart: ">=3.2.0 <4.0.0"
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
name: flutter_shopping_list
|
||||
description: "A new Flutter project."
|
||||
description: A new Flutter project.
|
||||
# The following line prevents the package from being accidentally published to
|
||||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
@@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: '>=3.2.6 <4.0.0'
|
||||
sdk: '>=2.19.2 <3.0.0'
|
||||
|
||||
# Dependencies specify other packages that your package needs in order to work.
|
||||
# To automatically upgrade your package dependencies to the latest versions
|
||||
@@ -45,7 +45,7 @@ dev_dependencies:
|
||||
# activated in the `analysis_options.yaml` file located at the root of your
|
||||
# package. See that file for information about deactivating specific lint
|
||||
# rules and activating additional ones.
|
||||
flutter_lints: ^2.0.0
|
||||
flutter_lints: ^3.0.1
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
Reference in New Issue
Block a user