Skip to content

Commit

Permalink
Merge pull request #1 from akinov/feature/v0.2.0
Browse files Browse the repository at this point in the history
Feature/v0.2.0
  • Loading branch information
akinov authored May 9, 2020
2 parents 4c6c6ec + 2ab3584 commit 50b9349
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 18 deletions.
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
Expand Down
13 changes: 10 additions & 3 deletions lib/models/process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -17,6 +18,7 @@ class Process {
int duration;
int water;
int step = 1;
String note = '';
int inSeconds;

String get typeText {
Expand All @@ -38,6 +40,7 @@ class Process {
columnDuration: duration,
columnWater: water,
columnStep: step,
columnNote: note,
};
if (id != null) {
map[columnId] = id;
Expand All @@ -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<String, dynamic> map) {
return Process.fromMap(map);
Expand Down Expand Up @@ -89,14 +93,15 @@ 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,
$columnRecipeId integer not null,
$columnType integer not null,
$columnDuration integer not null,
$columnStep integer not null,
$columnNote text not null,
$columnWater integer)
''');
}
Expand Down Expand Up @@ -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);
}
}
6 changes: 4 additions & 2 deletions lib/models/recipe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
59 changes: 48 additions & 11 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -11,28 +13,63 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> {
RecipeProvider _recipeProvider = RecipeProvider();
ProcessProvider _processProvider = ProcessProvider();
List<Recipe> _recipes = [];
int _titleTapCount = 0;

@override
void initState() {
super.initState();
loadRecipes();
_loadRecipes();
}

void loadRecipes() async {
RecipeProvider recipeProvider = RecipeProvider();
List<Recipe> recipes = await recipeProvider.all();
setState(() {
_recipes = recipes;
});
void _loadRecipes() async {
List<Recipe> 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: <Widget>[
// ボタン領域
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];
Expand Down Expand Up @@ -61,7 +98,7 @@ class _HomePageState extends State<HomePage> {
},
));
print(result);
loadRecipes();
_loadRecipes();
},
tooltip: 'Add Recipe',
child: Icon(Icons.add),
Expand Down
17 changes: 17 additions & 0 deletions lib/wigets/customAppBar.dart
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 50b9349

Please sign in to comment.