From ced382d0aba85414e933009cb49f9738b94f9a81 Mon Sep 17 00:00:00 2001 From: akinov Date: Sat, 9 May 2020 14:10:58 +0900 Subject: [PATCH 1/7] Edit Model db drop --- lib/models/process.dart | 2 ++ lib/models/recipe.dart | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/models/process.dart b/lib/models/process.dart index b0f35e9..fa8edf2 100644 --- a/lib/models/process.dart +++ b/lib/models/process.dart @@ -127,11 +127,13 @@ create table $_tableName ( Future close() async { Database dbClient = await db; + _db = null; return await dbClient.close(); } Future dropTable() async { Database dbClient = await db; await dbClient.execute('DROP TABLE IF EXISTS $_tableName'); + close(); } } diff --git a/lib/models/recipe.dart b/lib/models/recipe.dart index a5ff3d9..91953c4 100644 --- a/lib/models/recipe.dart +++ b/lib/models/recipe.dart @@ -107,11 +107,13 @@ create table $_tableName ( Future close() async { Database dbClient = await db; + _db = null; return await dbClient.close(); } Future dropTable() async { Database dbClient = await db; await dbClient.execute('DROP TABLE IF EXISTS $_tableName'); + close(); } } From fdd8357f4c259dd6f1d79a129ab431fe45aeb74a Mon Sep 17 00:00:00 2001 From: akinov Date: Sat, 9 May 2020 14:11:35 +0900 Subject: [PATCH 2/7] Edit title --- lib/main.dart | 2 +- lib/pages/home.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index aafde49..566c05d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -9,7 +9,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( // debugShowCheckedModeBanner: false, - title: 'Dripper', + title: 'dripper', home: HomePage(), theme: ThemeData( textTheme: diff --git a/lib/pages/home.dart b/lib/pages/home.dart index 392b241..703dba1 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -31,7 +31,7 @@ class _HomePageState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text('Dripper'), + title: Text('dripper'), ), body: ListView.builder( itemBuilder: (BuildContext context, int index) { From 8dc225ea40b5a4d59bddd0762e061b1f693eb104 Mon Sep 17 00:00:00 2001 From: akinov Date: Sat, 9 May 2020 14:11:59 +0900 Subject: [PATCH 3/7] Add note text to Process --- lib/models/process.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/models/process.dart b/lib/models/process.dart index fa8edf2..5fe8cf9 100644 --- a/lib/models/process.dart +++ b/lib/models/process.dart @@ -7,6 +7,7 @@ final String columnType = 'type'; final String columnDuration = 'duration'; final String columnWater = 'water'; final String columnStep = 'step'; +final String columnNote = 'note'; enum ProcessType { Bloom, Wait, Pour, Stir, Other } @@ -17,6 +18,7 @@ class Process { int duration; int water; int step = 1; + String note = ''; int inSeconds; String get typeText { @@ -38,6 +40,7 @@ class Process { columnDuration: duration, columnWater: water, columnStep: step, + columnNote: note, }; if (id != null) { map[columnId] = id; @@ -54,12 +57,13 @@ class Process { duration = map[columnDuration]; water = map[columnWater]; step = map[columnStep]; + note = map[columnNote]; } } class ProcessProvider { static Database _db; - static String _tableName = 'todo2'; + static String _tableName = 'todo3'; Process fromMap(Map map) { return Process.fromMap(map); @@ -97,6 +101,7 @@ create table $_tableName ( $columnType integer not null, $columnDuration integer not null, $columnStep integer not null, + $columnNote text not null, $columnWater integer) '''); } From 690d5b33d29501251ea0c35e8558305d3dc9c876 Mon Sep 17 00:00:00 2001 From: akinov Date: Sat, 9 May 2020 14:24:05 +0900 Subject: [PATCH 4/7] Edit primaryColor --- lib/main.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/main.dart b/lib/main.dart index 566c05d..f163c2c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,6 +12,7 @@ class MyApp extends StatelessWidget { title: 'dripper', home: HomePage(), theme: ThemeData( + primarySwatch: Colors.brown, textTheme: GoogleFonts.notoSansTextTheme(Theme.of(context).textTheme)), ); From 874561aa1fec7776fa496b4ab182289894f81a24 Mon Sep 17 00:00:00 2001 From: akinov Date: Sat, 9 May 2020 15:03:33 +0900 Subject: [PATCH 5/7] Update models --- lib/models/process.dart | 6 +++--- lib/models/recipe.dart | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/models/process.dart b/lib/models/process.dart index 5fe8cf9..6d5a6cb 100644 --- a/lib/models/process.dart +++ b/lib/models/process.dart @@ -93,7 +93,7 @@ class ProcessProvider { return theDb; } - void onCreate(Database db, int version) async { + Future onCreate(Database db, int version) async { await db.execute(''' create table $_tableName ( $columnId integer primary key autoincrement, @@ -136,9 +136,9 @@ create table $_tableName ( return await dbClient.close(); } - Future dropTable() async { + Future reCreateTable() async { Database dbClient = await db; await dbClient.execute('DROP TABLE IF EXISTS $_tableName'); - close(); + await onCreate(dbClient, 1); } } diff --git a/lib/models/recipe.dart b/lib/models/recipe.dart index 91953c4..da5518a 100644 --- a/lib/models/recipe.dart +++ b/lib/models/recipe.dart @@ -74,7 +74,7 @@ class RecipeProvider { return theDb; } - void onCreate(Database db, int version) async { + Future onCreate(Database db, int version) async { await db.execute(''' create table $_tableName ( $columnId integer primary key autoincrement, @@ -111,9 +111,9 @@ create table $_tableName ( return await dbClient.close(); } - Future dropTable() async { + Future reCreateTable() async { Database dbClient = await db; await dbClient.execute('DROP TABLE IF EXISTS $_tableName'); - close(); + await onCreate(dbClient, 1); } } From 8f3e2cff1021b24de5e04d0fb22cd1b02c29d245 Mon Sep 17 00:00:00 2001 From: akinov Date: Sat, 9 May 2020 15:04:31 +0900 Subject: [PATCH 6/7] Add reset function --- lib/pages/home.dart | 59 +++++++++++++++++++++++++++++------- lib/wigets/customAppBar.dart | 17 +++++++++++ 2 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 lib/wigets/customAppBar.dart diff --git a/lib/pages/home.dart b/lib/pages/home.dart index 703dba1..24b8015 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -1,6 +1,8 @@ +import 'package:dripper/models/process.dart'; import 'package:dripper/models/recipe.dart'; import 'package:dripper/pages/recipe/new.dart'; import 'package:dripper/pages/recipe/show.dart'; +import 'package:dripper/wigets/customAppBar.dart'; import 'package:flutter/material.dart'; class HomePage extends StatefulWidget { @@ -11,28 +13,63 @@ class HomePage extends StatefulWidget { } class _HomePageState extends State { + RecipeProvider _recipeProvider = RecipeProvider(); + ProcessProvider _processProvider = ProcessProvider(); List _recipes = []; + int _titleTapCount = 0; @override void initState() { super.initState(); - loadRecipes(); + _loadRecipes(); } - void loadRecipes() async { - RecipeProvider recipeProvider = RecipeProvider(); - List recipes = await recipeProvider.all(); - setState(() { - _recipes = recipes; - }); + void _loadRecipes() async { + List recipes = await _recipeProvider.all(); + setState(() => _recipes = recipes); + } + + void _tapTitle() { + _titleTapCount += 1; + if (_titleTapCount >= 7) { + _titleTapCount = 0; + + showDialog( + context: context, + builder: (_) { + return AlertDialog( + title: Text("登録データの一括削除"), + content: Text("データを削除してもよろしいですか?"), + actions: [ + // ボタン領域 + FlatButton( + child: Text("Cancel"), + onPressed: () => Navigator.pop(context), + ), + FlatButton( + child: Text("OK"), + onPressed: () async { + await _recipeProvider.reCreateTable(); + await _processProvider.reCreateTable(); + _loadRecipes(); + Navigator.pop(context); + }, + ), + ], + ); + }, + ); + } } @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text('dripper'), - ), + appBar: CustomAppBar( + onTap: _tapTitle, + appBar: AppBar( + title: Text('dripper'), + )), body: ListView.builder( itemBuilder: (BuildContext context, int index) { Recipe recipe = _recipes[index]; @@ -61,7 +98,7 @@ class _HomePageState extends State { }, )); print(result); - loadRecipes(); + _loadRecipes(); }, tooltip: 'Add Recipe', child: Icon(Icons.add), diff --git a/lib/wigets/customAppBar.dart b/lib/wigets/customAppBar.dart new file mode 100644 index 0000000..c0b72ee --- /dev/null +++ b/lib/wigets/customAppBar.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { + final VoidCallback onTap; + final AppBar appBar; + + const CustomAppBar({Key key, this.onTap, this.appBar}) : super(key: key); + + @override + Widget build(BuildContext context) { + return GestureDetector(onTap: onTap, child: appBar); + } + + // TODO: implement preferredSize + @override + Size get preferredSize => new Size.fromHeight(kToolbarHeight); +} From 2ab3584ea9608bf7191654b922de9ba43df4095b Mon Sep 17 00:00:00 2001 From: akinov Date: Sat, 9 May 2020 15:09:51 +0900 Subject: [PATCH 7/7] update v0.2.0 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 49748c8..f14bc5f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: Coffee drip timer # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.1.0+2 +version: 0.2.0+3 environment: sdk: '>=2.2.0 <3.0.0'