cpd_2022_zi/lib/providers/settings_provider.dart

39 lines
1.2 KiB
Dart
Raw Normal View History

2023-02-27 02:27:42 +01:00
import 'package:flutter/material.dart';
import 'package:smoke_cess_app/services/settings_service.dart';
import '../models/settings.dart';
class SettingsProvider extends ChangeNotifier {
Settings? _settings;
bool _initialized = false;
2023-02-27 02:27:42 +01:00
Settings? get settings => _settings;
bool get initialized => _initialized;
2023-02-27 02:27:42 +01:00
SettingsProvider() {
initSettings();
}
void initSettings() async {
int? group = await getGroup();
List<String>? relapseCategories = await getRelapseCategories();
int? moodHours = await getMoodQueryHours();
int? moodMinutes = await getMoodQueryMinutes();
List<String>? moodDays = await getMoodQueryDaysCategories();
int? sleepHours = await getSleepQueryHours();
int? sleepMinutes = await getSleepQueryMinutes();
List<String>? sleepDays = await getSleepQueryDaysCategories();
int? chessHours = await getChessHours();
int? chessMinutes = await getChessMinutes();
_settings = Settings(
group ?? 0,
relapseCategories,
QueryConfig(moodHours ?? 0, moodMinutes ?? 0, moodDays),
QueryConfig(sleepHours ?? 0, sleepMinutes ?? 0, sleepDays),
TimeConfig(chessHours ?? 0, chessMinutes ?? 0));
_initialized = group != 0 ? true : false;
2023-02-27 02:27:42 +01:00
notifyListeners();
}
}