feat: implement autoregulation for kettlebell training
This commit is contained in:
parent
a3e36b1975
commit
4fac48e81e
9 changed files with 417 additions and 117 deletions
|
|
@ -1,37 +1,34 @@
|
|||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SettingsState {
|
||||
final int trainingTimeMinutes;
|
||||
final double weightLeft;
|
||||
final double weightRight;
|
||||
final int repsPerSet;
|
||||
final int goalSets;
|
||||
final String notes;
|
||||
final String initialProgram;
|
||||
|
||||
SettingsState({
|
||||
this.trainingTimeMinutes = 20,
|
||||
this.weightLeft = 16.0,
|
||||
this.weightRight = 16.0,
|
||||
this.repsPerSet = 5,
|
||||
this.goalSets = 5,
|
||||
this.notes = "",
|
||||
this.initialProgram = 'giant_1.0',
|
||||
});
|
||||
|
||||
SettingsState copyWith({
|
||||
int? trainingTimeMinutes,
|
||||
double? weightLeft,
|
||||
double? weightRight,
|
||||
int? repsPerSet,
|
||||
int? goalSets,
|
||||
String? notes,
|
||||
String? initialProgram,
|
||||
}) {
|
||||
return SettingsState(
|
||||
trainingTimeMinutes: trainingTimeMinutes ?? this.trainingTimeMinutes,
|
||||
weightLeft: weightLeft ?? this.weightLeft,
|
||||
weightRight: weightRight ?? this.weightRight,
|
||||
repsPerSet: repsPerSet ?? this.repsPerSet,
|
||||
goalSets: goalSets ?? this.goalSets,
|
||||
notes: notes ?? this.notes,
|
||||
initialProgram: initialProgram ?? this.initialProgram,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -39,9 +36,30 @@ class SettingsState {
|
|||
class SettingsNotifier extends StateNotifier<SettingsState> {
|
||||
SettingsNotifier() : super(SettingsState());
|
||||
|
||||
void updateSettings(SettingsState newSettings) {
|
||||
Future<void> loadSettings() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
state = SettingsState(
|
||||
trainingTimeMinutes: prefs.getInt('trainingTimeMinutes') ?? 20,
|
||||
weightLeft: prefs.getDouble('weightLeft') ?? 16.0,
|
||||
weightRight: prefs.getDouble('weightRight') ?? 16.0,
|
||||
goalSets: prefs.getInt('goalSets') ?? 5,
|
||||
initialProgram: prefs.getString('initialProgram') ?? 'giant_1.0',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> saveSettings(SettingsState newSettings) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt('trainingTimeMinutes', newSettings.trainingTimeMinutes);
|
||||
await prefs.setDouble('weightLeft', newSettings.weightLeft);
|
||||
await prefs.setDouble('weightRight', newSettings.weightRight);
|
||||
await prefs.setInt('goalSets', newSettings.goalSets);
|
||||
await prefs.setString('initialProgram', newSettings.initialProgram);
|
||||
state = newSettings;
|
||||
}
|
||||
|
||||
Future<void> updateSettings(SettingsState newSettings) async {
|
||||
await saveSettings(newSettings);
|
||||
}
|
||||
}
|
||||
|
||||
final settingsProvider = StateNotifierProvider<SettingsNotifier, SettingsState>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue