diff --git a/lib/main.dart b/lib/main.dart index aafde49..f163c2c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -9,9 +9,10 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( // debugShowCheckedModeBanner: false, - title: 'Dripper', + title: 'dripper', home: HomePage(), theme: ThemeData( + primarySwatch: Colors.brown, textTheme: GoogleFonts.notoSansTextTheme(Theme.of(context).textTheme)), ); diff --git a/lib/models/process.dart b/lib/models/process.dart index b0f35e9..6d5a6cb 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); @@ -89,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, @@ -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) '''); } @@ -127,11 +132,13 @@ create table $_tableName ( Future close() async { Database dbClient = await db; + _db = null; return await dbClient.close(); } - Future dropTable() async { + Future reCreateTable() async { Database dbClient = await db; await dbClient.execute('DROP TABLE IF EXISTS $_tableName'); + await onCreate(dbClient, 1); } } diff --git a/lib/models/recipe.dart b/lib/models/recipe.dart index a5ff3d9..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, @@ -107,11 +107,13 @@ create table $_tableName ( Future close() async { Database dbClient = await db; + _db = null; return await dbClient.close(); } - Future dropTable() async { + Future reCreateTable() async { Database dbClient = await db; await dbClient.execute('DROP TABLE IF EXISTS $_tableName'); + await onCreate(dbClient, 1); } } diff --git a/lib/pages/home.dart b/lib/pages/home.dart index 392b241..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); +} 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'