-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from p2hacks2024/issue/4-main-add-riverpod
refactor: visible content #4
- Loading branch information
Showing
2 changed files
with
54 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
export 'package:flutter/material.dart'; | ||
|
||
final alcoholRatioProvider = NotifierProvider<alcoholRatioNotifier, double>(() { | ||
return alcoholRatioNotifier(); | ||
}); | ||
|
||
class alcoholRatioNotifier extends Notifier<double> { | ||
// 初期値を設定する | ||
@override | ||
double build() { | ||
return 0.0; | ||
} | ||
|
||
void set(double ratio) { | ||
if (ratio > 1.0) { | ||
state = 1.0; | ||
} else if (ratio < 0.0) { | ||
state = 0.0; | ||
} else { | ||
state = ratio; | ||
} | ||
} | ||
|
||
void add(double ratio) { | ||
state += ratio; | ||
if (state > 1.0) { | ||
state = 1.0; | ||
} else if (state < 0.0) { | ||
state = 0.0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters