wip
parent
4b2e900bda
commit
8d8a9ccf2c
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"group": "Gruppe 2",
|
||||
"key": "value"
|
||||
}
|
|
@ -10,6 +10,6 @@ class MyApp extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const MaterialApp(title: _title, home: MyHomePage());
|
||||
return MaterialApp(title: _title, home: MyHomePage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
class Settings {
|
||||
final String group;
|
||||
final String key;
|
||||
//final List<String> relapseCategories;
|
||||
|
||||
Settings(this.group, this.key); //, this.relapseCategories);
|
||||
|
||||
Settings.fromJson(Map<String, dynamic> json)
|
||||
: group = json['group'].toString(),
|
||||
key = json['key'].toString()
|
||||
//relapseCategories = json['relapse_categories']
|
||||
;
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:smoke_cess_app/pages/mood_page.dart';
|
||||
import 'package:smoke_cess_app/pages/relapse_page.dart';
|
||||
import 'package:smoke_cess_app/pages/settings_page.dart';
|
||||
import 'package:smoke_cess_app/pages/scanner_page.dart';
|
||||
import 'package:smoke_cess_app/pages/sleep_page.dart';
|
||||
import 'package:smoke_cess_app/pages/timer_page.dart';
|
||||
import 'package:smoke_cess_app/service/settings_service.dart';
|
||||
import 'package:smoke_cess_app/widgets/missing_config_popup.dart';
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key});
|
||||
|
@ -13,24 +15,38 @@ class MyHomePage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class MyHomePageState extends State<MyHomePage> {
|
||||
int _selectedIndex = 2;
|
||||
int _selectedIndex = 4;
|
||||
final SettingsService settingsService = SettingsService();
|
||||
|
||||
final List<String> _titles = [
|
||||
'Stimmung',
|
||||
'Schlaf',
|
||||
'Timer',
|
||||
'Rückfall',
|
||||
'Einstellungen'
|
||||
'Scanner'
|
||||
];
|
||||
static const List<Widget> _widgetOptions = <Widget>[
|
||||
MoodPage(),
|
||||
SleepPage(),
|
||||
StopWatchTimerPage(),
|
||||
RelapsePage(),
|
||||
static final List<Widget> _widgetOptions = <Widget>[
|
||||
const MoodPage(),
|
||||
const SleepPage(),
|
||||
const StopWatchTimerPage(),
|
||||
const RelapsePage(),
|
||||
SettingsPage(),
|
||||
];
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
setState(() => _selectedIndex = index);
|
||||
setState(() async {
|
||||
(await settingsService.getGroup() != null)
|
||||
? _selectedIndex = index
|
||||
: showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
Future.delayed(
|
||||
const Duration(seconds: 3),
|
||||
() => Navigator.of(context)
|
||||
.pop(true)); //Dismiss popup after 3 seconds
|
||||
return const MissingConfigPopup();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -58,7 +74,7 @@ class MyHomePageState extends State<MyHomePage> {
|
|||
icon: Icon(Icons.smoke_free_outlined, color: Colors.black),
|
||||
label: 'Rückfall'),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.settings, color: Colors.black),
|
||||
icon: Icon(Icons.camera_alt_outlined, color: Colors.black),
|
||||
label: 'Settings'),
|
||||
],
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:smoke_cess_app/service/settings_service.dart';
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
SettingsPage({super.key});
|
||||
SettingsService service = SettingsService();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text('Hier taucht die Kamera zum Scannen auf'),
|
||||
const SizedBox(height: 30),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
textStyle: const TextStyle(fontSize: 20)),
|
||||
onPressed: () {
|
||||
service.loadSettings();
|
||||
},
|
||||
child: const Text('Read JSON'),
|
||||
)
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
const SettingsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(child: Text('Hier können Settings eingestellt werden'));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
const String configJSONPath = 'assets/config.json';
|
||||
|
||||
Future<Map<String, dynamic>> loadLocalConfigJSON() async {
|
||||
String content = await rootBundle.loadString(configJSONPath);
|
||||
return jsonDecode(content);
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:smoke_cess_app/models/settings.dart';
|
||||
import 'package:smoke_cess_app/service/json_service.dart';
|
||||
|
||||
class SettingsService {
|
||||
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
|
||||
|
@ -7,6 +9,11 @@ class SettingsService {
|
|||
setIntSetting('workout_duration_minutes', 5);
|
||||
}
|
||||
|
||||
//access group setting which was saved in local storage
|
||||
Future<String?> getGroup() {
|
||||
return getStringSetting('group');
|
||||
}
|
||||
|
||||
void setStringSetting(String settingKey, String settingValue) =>
|
||||
_prefs.then((pref) => pref.setString(settingKey, settingValue));
|
||||
|
||||
|
@ -19,7 +26,24 @@ class SettingsService {
|
|||
Future<int?> getIntSetting(String settingKey) =>
|
||||
_prefs.then((pref) => pref.getInt(settingKey));
|
||||
|
||||
void setStringList(String settingKey, List<String> list) =>
|
||||
_prefs.then((pref) => pref.setStringList(settingKey, list));
|
||||
|
||||
//Add other setters and getters if needed
|
||||
//other possible SharedPreferences Types: Int, Bool, Double, StringList
|
||||
//see https://pub.dev/packages/shared_preferences
|
||||
|
||||
Future<void> loadSettings() async {
|
||||
Map<String, dynamic> configJSON = await loadLocalConfigJSON();
|
||||
Settings settings = Settings.fromJson(configJSON);
|
||||
print(settings.group);
|
||||
saveSettings(settings);
|
||||
String gruppe = (await getGroup())!;
|
||||
print('Gruppe: $gruppe');
|
||||
}
|
||||
|
||||
void saveSettings(Settings settings) {
|
||||
setStringSetting('group', settings.group);
|
||||
setStringSetting('key', settings.key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class MissingConfigPopup extends StatelessWidget {
|
||||
const MissingConfigPopup({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Fehlende Konfiguration'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const <Widget>[
|
||||
Text("Bitte QR Code Scannen"),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -62,6 +62,8 @@ flutter:
|
|||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
assets:
|
||||
- config.json
|
||||
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/assets-and-images/#resolution-aware
|
||||
|
|
Loading…
Reference in New Issue