change group to int, show group in appbar if configured

main
Julian Gegner 2023-02-20 19:50:09 +01:00
parent 5393590687
commit 6d4a958d8c
6 changed files with 13 additions and 9 deletions

View File

@ -1,5 +1,5 @@
{
"group": "Gruppe 1",
"group": 1,
"HITT_time": 35,
"relapse_categories": ["App stresst mich", "langeweile", "lunge braucht es"],
"mood_query": {

View File

@ -1,5 +1,5 @@
{
"group": "Gruppe 3",
"group": 3,
"HITT_time": 35,
"chess_time": {
"hours": 8,

View File

@ -1,7 +1,7 @@
import 'package:smoke_cess_app/service/json_service.dart';
class Settings {
final String group;
final int group;
final List<String>? relapseCategories;
final QueryConfig moodQuery;
final QueryConfig sleepQuery;
@ -11,7 +11,7 @@ class Settings {
this.chessTime);
Settings.fromJson(Map<String, dynamic> json)
: group = json['group'] as String,
: group = json['group'] as int,
relapseCategories = jsonPropertyAsList(json['relapse_categories']),
moodQuery = QueryConfig.fromJson(json['mood_query']),
sleepQuery = QueryConfig.fromJson(json['sleep_query']),

View File

@ -16,6 +16,7 @@ class MyHomePage extends StatefulWidget {
class MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 4;
int? _gruppe;
final List<String> _titles = [
'Stimmung',
@ -33,8 +34,8 @@ class MyHomePageState extends State<MyHomePage> {
];
Future<void> _onItemTapped(int index) async {
bool isConfigured = (await getGroup()) != null;
print('Gruppe: ${await getGroup()}, isConfigured: $isConfigured');
_gruppe = await getGroup();
bool isConfigured = _gruppe != null;
setState(() {
isConfigured
? _selectedIndex = index
@ -52,7 +53,9 @@ class MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(_titles[_selectedIndex])),
appBar: AppBar(
title: Text(
'${_titles[_selectedIndex]} ${_gruppe != null ? "Gruppe $_gruppe" : ""}')),
body: _widgetOptions.elementAt(_selectedIndex),
bottomNavigationBar: NavigationBar(
onDestinationSelected: _onItemTapped,

View File

@ -30,6 +30,7 @@ class ScannerPageState extends State<ScannerPage> {
detectionTimeoutMs: 2000,
),
onDetect: (capture) {
//TODO Errorhandling!!
final List<Barcode> barcodes = capture.barcodes;
for (final barcode in barcodes) {
if (barcode.rawValue != null) {

View File

@ -3,7 +3,7 @@ import 'package:smoke_cess_app/models/settings.dart';
import 'package:smoke_cess_app/service/json_service.dart';
//access group setting which was saved in local storage
Future<String?> getGroup() => _getStringSetting('group');
Future<int?> getGroup() => _getIntSetting('group');
Future<List<String>?> getRelapseCategories() =>
_getStringListSetting('relapse_categories');
@ -52,7 +52,7 @@ Future<void> loadSettingsFromLocalJSON() async {
}
void saveSettings(Settings settings) {
_setStringSetting('group', settings.group);
_setIntSetting('group', settings.group);
_setStringListSetting('relapse_categories', settings.relapseCategories!);
_setStringListSetting('mood_query_days', settings.moodQuery.days!);
_setIntSetting('mood_query_hours', settings.moodQuery.hours);