diff --git a/lib/models/process.dart b/lib/models/process.dart index 6d5a6cb..bb2964f 100644 --- a/lib/models/process.dart +++ b/lib/models/process.dart @@ -20,12 +20,13 @@ class Process { int step = 1; String note = ''; int inSeconds; + int totalWater; String get typeText { return ProcessType.values[type].toString().split('.')[1]; } - String get title { + String get titleForList { List result = ['Duration ' + duration.toString() + 's']; if (type != 1) { result.add('Water ' + water.toString() + 'ml'); @@ -33,6 +34,21 @@ class Process { return result.join(', '); } + String get textForTimer { + switch (ProcessType.values[type]) { + case ProcessType.Bloom: + return 'Pour ${water.toString()}g of water ${duration.toString()} seconds and wait to bloom'; + case ProcessType.Wait: + return 'Wait for ${duration.toString()} seconds'; + case ProcessType.Pour: + return 'Pour ${water.toString()}g of water ${duration.toString()} seconds'; + case ProcessType.Stir: + return 'Stir for ${duration.toString()} seconds'; + case ProcessType.Other: + return '${duration.toString()} seconds $note'; + } + } + Map toMap() { var map = { columnRecipeId: recipeId, diff --git a/lib/pages/process/new.dart b/lib/pages/process/new.dart index 9304917..3c0f51f 100644 --- a/lib/pages/process/new.dart +++ b/lib/pages/process/new.dart @@ -31,7 +31,6 @@ class _ProcessNewState extends State { } }, child: Text('Save', style: TextStyle(color: Colors.white)), - shape: CircleBorder(side: BorderSide(color: Colors.transparent)), ), ], ), diff --git a/lib/pages/recipe/new.dart b/lib/pages/recipe/new.dart index 8514c36..514f218 100644 --- a/lib/pages/recipe/new.dart +++ b/lib/pages/recipe/new.dart @@ -41,7 +41,6 @@ class _RecipeNewState extends State { } }, child: Text('Save', style: TextStyle(color: Colors.white)), - shape: CircleBorder(side: BorderSide(color: Colors.transparent)), ), ], ), @@ -138,7 +137,7 @@ class _RecipeNewState extends State { // subtitle: Text('hoghoge'), leading: Text(process.step.toString()), trailing: Icon(Icons.more_vert), - subtitle: Text(process.title), + subtitle: Text(process.titleForList), ), ); }).toList(); diff --git a/lib/pages/recipe/show.dart b/lib/pages/recipe/show.dart index 7f05072..6733eee 100644 --- a/lib/pages/recipe/show.dart +++ b/lib/pages/recipe/show.dart @@ -61,7 +61,7 @@ class _RecipeShowState extends State { fontWeight: FontWeight.bold, ), )), - Text(widget.recipe.water.toString() + 'ml'), + Text(widget.recipe.water.toString() + 'g'), Padding( padding: EdgeInsets.only(top: 16.0, bottom: 8.0), child: Text( @@ -97,7 +97,7 @@ class _RecipeShowState extends State { ), // subtitle: Text('hoghoge'), leading: Text(process.step.toString()), - subtitle: Text(process.title), + subtitle: Text(process.titleForList), ), ); }).toList(); diff --git a/lib/pages/recipe/timer.dart b/lib/pages/recipe/timer.dart index 3f47a3c..65b7e5a 100644 --- a/lib/pages/recipe/timer.dart +++ b/lib/pages/recipe/timer.dart @@ -19,6 +19,7 @@ class _RecipeTimerState extends State { Duration _tmpDuration = Duration(); bool _doing = true; List _processes; + double _currentWater = 0; @override void initState() { @@ -30,9 +31,14 @@ class _RecipeTimerState extends State { void _setupProcsses() { List result = []; int time = 0; + int water = 0; widget.processes.forEach((process) { time += process.duration; process.inSeconds = time; + if (process.water != null) { + water += process.water; + } + process.totalWater = water; result.add(process); }); setState(() => _processes = result); @@ -40,17 +46,28 @@ class _RecipeTimerState extends State { void _onTimer(Timer timer) { Process process = _currentProcess(); + int seconds = _duration().inSeconds; if (_processes.length > 0) { - if (process.inSeconds <= _duration().inSeconds) { + if (process.inSeconds <= seconds) { _processes.removeAt(0); } } else { _stopTimer(); } + if (process.water != null || process.water != 0) { + double a = (process.inSeconds - + process.duration - + (_duration().inMilliseconds / 1000)) * + -1; + double b = a.toDouble() / process.duration.toDouble(); + _currentWater = b * process.water; + } + setState(() { _now = DateTime.now(); _processes = _processes; + _currentWater = _currentWater; }); } @@ -123,13 +140,24 @@ class _RecipeTimerState extends State { String _text() { if (_currentProcess() != null) { - return _currentProcess().title; - } - { + return _currentProcess().textForTimer; + } else { return ' '; } } + String _waterText() { + Process process = _currentProcess(); + if (process == null) { + return ''; + } + int prevWater = process.totalWater - process.water; + return (prevWater + _currentWater).toStringAsFixed(1) + + '/' + + process.totalWater.toStringAsFixed(1) + + ' g'; + } + @override Widget build(BuildContext context) { return Scaffold( @@ -138,8 +166,14 @@ class _RecipeTimerState extends State { ), body: Center( child: Column(mainAxisSize: MainAxisSize.min, children: [ + Padding( + padding: EdgeInsets.all(32.0), + child: Text( + _title(), + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 40), + )), Text( - _title(), + _waterText(), style: TextStyle(fontWeight: FontWeight.bold, fontSize: 40), ), Padding( diff --git a/pubspec.yaml b/pubspec.yaml index 618a85b..8a44a5d 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.2.2+5 +version: 0.3.0+6 environment: sdk: '>=2.2.0 <3.0.0'