Merge branch 'scanner-page' into 'main'
Get Settings input from Scanner Page See merge request Crondung/hsma_cpd!4main
commit
7a80851e05
|
@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
|
|||
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
|
||||
|
||||
android {
|
||||
compileSdkVersion flutter.compileSdkVersion
|
||||
compileSdkVersion 33
|
||||
ndkVersion flutter.ndkVersion
|
||||
|
||||
compileOptions {
|
||||
|
@ -47,7 +47,7 @@ android {
|
|||
applicationId "com.example.smoke_cess_app"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
|
||||
minSdkVersion flutter.minSdkVersion
|
||||
minSdkVersion 21
|
||||
targetSdkVersion flutter.targetSdkVersion
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"group": 1,
|
||||
"HITT_time": 35,
|
||||
"relapse_categories": ["App stresst mich", "langeweile", "lunge braucht es"],
|
||||
"mood_query": {
|
||||
"days": ["Montag", "Freitag"],
|
||||
"hours": 8,
|
||||
"minutes": 30
|
||||
},
|
||||
"sleep_query": {
|
||||
"days": ["Dienstag", "Samstag"],
|
||||
"hours": 9,
|
||||
"minutes": 30
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"group": 3,
|
||||
"HITT_time": 35,
|
||||
"chess_time": {
|
||||
"hours": 8,
|
||||
"minutes": 30
|
||||
},
|
||||
"relapse_categories": ["App stresst mich", "langeweile", "lunge braucht es"],
|
||||
"mood_query": {
|
||||
"days": ["Montag", "Freitag"],
|
||||
"hours": 10,
|
||||
"minutes": 30
|
||||
},
|
||||
"sleep_query": {
|
||||
"days": ["Dienstag", "Samstag"],
|
||||
"hours": 11,
|
||||
"minutes": 30
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>This app needs camera access to scan QR codes</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
|
|
|
@ -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,45 @@
|
|||
import 'package:smoke_cess_app/service/json_service.dart';
|
||||
|
||||
class Settings {
|
||||
final int group;
|
||||
final List<String>? relapseCategories;
|
||||
final QueryConfig moodQuery;
|
||||
final QueryConfig sleepQuery;
|
||||
final TimeConfig? chessTime;
|
||||
|
||||
Settings(this.group, this.relapseCategories, this.moodQuery, this.sleepQuery,
|
||||
this.chessTime);
|
||||
|
||||
Settings.fromJson(Map<String, dynamic> json)
|
||||
: group = json['group'] as int,
|
||||
relapseCategories = jsonPropertyAsList(json['relapse_categories']),
|
||||
moodQuery = QueryConfig.fromJson(json['mood_query']),
|
||||
sleepQuery = QueryConfig.fromJson(json['sleep_query']),
|
||||
chessTime = json['chess_time'] != null
|
||||
? TimeConfig.fromJson(json['chess_time'])
|
||||
: null;
|
||||
}
|
||||
|
||||
class QueryConfig {
|
||||
final int hours;
|
||||
final int minutes;
|
||||
final List<String>? days;
|
||||
|
||||
QueryConfig(this.hours, this.minutes, this.days);
|
||||
|
||||
QueryConfig.fromJson(Map<String, dynamic> json)
|
||||
: hours = json['hours'] as int,
|
||||
minutes = json['minutes'] as int,
|
||||
days = jsonPropertyAsList(json['days']);
|
||||
}
|
||||
|
||||
class TimeConfig {
|
||||
final int hours;
|
||||
final int minutes;
|
||||
|
||||
TimeConfig(this.hours, this.minutes);
|
||||
|
||||
TimeConfig.fromJson(Map<String, dynamic> json)
|
||||
: hours = json['hours'] as int,
|
||||
minutes = json['minutes'] as int;
|
||||
}
|
|
@ -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,30 +15,47 @@ class MyHomePage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class MyHomePageState extends State<MyHomePage> {
|
||||
int _selectedIndex = 2;
|
||||
int _selectedIndex = 4;
|
||||
int? _gruppe;
|
||||
|
||||
final List<String> _titles = [
|
||||
'Stimmung',
|
||||
'Schlaf',
|
||||
'Timer',
|
||||
'Rückfall',
|
||||
'Einstellungen'
|
||||
'Scanner'
|
||||
];
|
||||
static const List<Widget> _widgetOptions = <Widget>[
|
||||
MoodPage(),
|
||||
SleepPage(),
|
||||
StopWatchTimerPage(),
|
||||
RelapsePage(),
|
||||
SettingsPage(),
|
||||
ScannerPage(),
|
||||
];
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
setState(() => _selectedIndex = index);
|
||||
Future<void> _onItemTapped(int index) async {
|
||||
_gruppe = await getGroup();
|
||||
bool isConfigured = _gruppe != null;
|
||||
setState(() {
|
||||
isConfigured
|
||||
? _selectedIndex = index
|
||||
: showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return const MissingConfigPopup(
|
||||
title: 'Fehlende Konfiguration',
|
||||
text: 'Bitte QR Code Scannen!',
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@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,
|
||||
|
@ -58,7 +77,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,76 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:smoke_cess_app/models/settings.dart';
|
||||
import 'package:smoke_cess_app/service/json_service.dart';
|
||||
import 'package:smoke_cess_app/service/settings_service.dart';
|
||||
|
||||
import '../widgets/missing_config_popup.dart';
|
||||
|
||||
class ScannerPage extends StatefulWidget {
|
||||
const ScannerPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => ScannerPageState();
|
||||
}
|
||||
|
||||
class ScannerPageState extends State<ScannerPage> {
|
||||
bool scanning = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
scanning
|
||||
? Expanded(
|
||||
child: MobileScanner(
|
||||
fit: BoxFit.contain,
|
||||
controller: MobileScannerController(
|
||||
detectionTimeoutMs: 2000,
|
||||
),
|
||||
onDetect: (capture) {
|
||||
//TODO Errorhandling!!
|
||||
final List<Barcode> barcodes = capture.barcodes;
|
||||
for (final barcode in barcodes) {
|
||||
if (barcode.rawValue != null) {
|
||||
String qrText = barcode.rawValue!;
|
||||
Map<String, dynamic> json = stringToJSON(qrText);
|
||||
Settings settings = Settings.fromJson(json);
|
||||
saveSettings(settings);
|
||||
setState(() {
|
||||
scanning = false;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return MissingConfigPopup(
|
||||
title: 'Konfiguration erfolgreich',
|
||||
text: 'Du gehörst zu Gruppe ${settings.group}',
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
))
|
||||
: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
textStyle: const TextStyle(fontSize: 20)),
|
||||
onPressed: () {
|
||||
setState(() => scanning = true);
|
||||
},
|
||||
child: const Text('Scan QR Code'),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
textStyle: const TextStyle(fontSize: 20)),
|
||||
onPressed: () {
|
||||
loadSettingsFromLocalJSON();
|
||||
},
|
||||
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'));
|
||||
}
|
||||
}
|
|
@ -11,7 +11,6 @@ class StopWatchTimerPage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class StopWatchTimerPageState extends State<StopWatchTimerPage> {
|
||||
SettingsService settings = SettingsService();
|
||||
Duration duration = const Duration(minutes: 1);
|
||||
Timer? timer;
|
||||
|
||||
|
@ -19,21 +18,11 @@ class StopWatchTimerPageState extends State<StopWatchTimerPage> {
|
|||
|
||||
@override
|
||||
void initState() {
|
||||
setDurationWithSetting();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
void setDurationWithSetting() {
|
||||
settings.getIntSetting('workout_duration_minutes').then((workoutMinutes) =>
|
||||
{setState(() => duration = Duration(minutes: workoutMinutes ?? 10))});
|
||||
}
|
||||
|
||||
void reset() {
|
||||
if (countDown) {
|
||||
setDurationWithSetting();
|
||||
} else {
|
||||
setState(() => duration = const Duration());
|
||||
}
|
||||
setState(() => duration = const Duration());
|
||||
}
|
||||
|
||||
void startTimer() {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
const String configJSONPath = 'assets/group3.json';
|
||||
|
||||
Future<Map<String, dynamic>> loadLocalConfigJSON() async {
|
||||
String content = await rootBundle.loadString(configJSONPath);
|
||||
return jsonDecode(content);
|
||||
}
|
||||
|
||||
List<String>? jsonPropertyAsList(dynamic property) =>
|
||||
property != null ? List.from(property) : null;
|
||||
|
||||
Map<String, dynamic> stringToJSON(String jsonString) => jsonDecode(jsonString);
|
|
@ -1,25 +1,67 @@
|
|||
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();
|
||||
//access group setting which was saved in local storage
|
||||
Future<int?> getGroup() => _getIntSetting('group');
|
||||
|
||||
SettingsService() {
|
||||
setIntSetting('workout_duration_minutes', 5);
|
||||
}
|
||||
Future<List<String>?> getRelapseCategories() =>
|
||||
_getStringListSetting('relapse_categories');
|
||||
|
||||
void setStringSetting(String settingKey, String settingValue) =>
|
||||
_prefs.then((pref) => pref.setString(settingKey, settingValue));
|
||||
Future<List<String>?> getSleepQueryDaysCategories() =>
|
||||
_getStringListSetting('sleep_query_days');
|
||||
|
||||
Future<String?> getStringSetting(String settingKey) =>
|
||||
_prefs.then((pref) => pref.getString(settingKey));
|
||||
Future<int?> getSleepQueryHours() => _getIntSetting('sleep_query_hours');
|
||||
Future<int?> getSleepQueryMinutes() => _getIntSetting('sleep_query_minutes');
|
||||
|
||||
void setIntSetting(String settingKey, int settingValue) =>
|
||||
_prefs.then((pref) => pref.setInt(settingKey, settingValue));
|
||||
Future<List<String>?> getMoodQueryDaysCategories() =>
|
||||
_getStringListSetting('mood_query_days');
|
||||
|
||||
Future<int?> getIntSetting(String settingKey) =>
|
||||
_prefs.then((pref) => pref.getInt(settingKey));
|
||||
Future<int?> getMoodQueryHours() => _getIntSetting('mood_query_hours');
|
||||
Future<int?> getMoodQueryMinutes() => _getIntSetting('mood_query_minutes');
|
||||
|
||||
//Add other setters and getters if needed
|
||||
//other possible SharedPreferences Types: Int, Bool, Double, StringList
|
||||
//see https://pub.dev/packages/shared_preferences
|
||||
Future<int?> getChessHours() => _getIntSetting('chess_hours');
|
||||
Future<int?> getChessMinutes() => _getIntSetting('chess_minutes');
|
||||
|
||||
void _setStringSetting(String settingKey, String settingValue) =>
|
||||
SharedPreferences.getInstance()
|
||||
.then((pref) => pref.setString(settingKey, settingValue));
|
||||
|
||||
Future<String?> _getStringSetting(String settingKey) =>
|
||||
SharedPreferences.getInstance().then((pref) => pref.getString(settingKey));
|
||||
|
||||
void _setIntSetting(String settingKey, int settingValue) =>
|
||||
SharedPreferences.getInstance()
|
||||
.then((pref) => pref.setInt(settingKey, settingValue));
|
||||
|
||||
Future<int?> _getIntSetting(String settingKey) =>
|
||||
SharedPreferences.getInstance().then((pref) => pref.getInt(settingKey));
|
||||
|
||||
void _setStringListSetting(String settingKey, List<String> list) =>
|
||||
SharedPreferences.getInstance()
|
||||
.then((pref) => pref.setStringList(settingKey, list));
|
||||
|
||||
Future<List<String>?> _getStringListSetting(String settingKey) =>
|
||||
SharedPreferences.getInstance()
|
||||
.then((pref) => pref.getStringList(settingKey));
|
||||
|
||||
Future<void> loadSettingsFromLocalJSON() async {
|
||||
Map<String, dynamic> configJSON = await loadLocalConfigJSON();
|
||||
Settings settings = Settings.fromJson(configJSON);
|
||||
saveSettings(settings);
|
||||
}
|
||||
|
||||
void saveSettings(Settings settings) {
|
||||
_setIntSetting('group', settings.group);
|
||||
_setStringListSetting('relapse_categories', settings.relapseCategories!);
|
||||
_setStringListSetting('mood_query_days', settings.moodQuery.days!);
|
||||
_setIntSetting('mood_query_hours', settings.moodQuery.hours);
|
||||
_setIntSetting('mood_query_minutes', settings.moodQuery.minutes);
|
||||
_setStringListSetting('sleep_query_days', settings.sleepQuery.days!);
|
||||
_setIntSetting('sleep_query_hours', settings.sleepQuery.hours);
|
||||
_setIntSetting('sleep_query_minutes', settings.sleepQuery.minutes);
|
||||
if (settings.chessTime != null) {
|
||||
_setIntSetting('chess_hours', settings.chessTime!.hours);
|
||||
_setIntSetting('chess_minutes', settings.chessTime!.minutes);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class MissingConfigPopup extends StatelessWidget {
|
||||
final String title;
|
||||
final String text;
|
||||
const MissingConfigPopup(
|
||||
{super.key, required this.title, required this.text});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(text),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -121,6 +121,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0"
|
||||
mobile_scanner:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: mobile_scanner
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -36,6 +36,7 @@ dependencies:
|
|||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.2
|
||||
shared_preferences: ^2.0.17
|
||||
mobile_scanner: ^3.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
@ -62,6 +63,9 @@ flutter:
|
|||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
assets:
|
||||
- group1.json
|
||||
- group3.json
|
||||
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/assets-and-images/#resolution-aware
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
<head>
|
||||
<!--
|
||||
If you are serving your web app in a path other than the root, change the
|
||||
href value below to reflect the base path you are serving from.
|
||||
|
||||
|
@ -14,45 +14,49 @@
|
|||
This is a placeholder for base href that will be replaced by the value of
|
||||
the `--base-href` argument provided to `flutter build`.
|
||||
-->
|
||||
<base href="$FLUTTER_BASE_HREF">
|
||||
<base href="$FLUTTER_BASE_HREF" />
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
|
||||
<meta name="description" content="A new Flutter project.">
|
||||
<meta charset="UTF-8" />
|
||||
<meta content="IE=Edge" http-equiv="X-UA-Compatible" />
|
||||
<meta name="description" content="A new Flutter project." />
|
||||
|
||||
<!-- iOS meta tags & icons -->
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="apple-mobile-web-app-title" content="smoke_cess_app">
|
||||
<link rel="apple-touch-icon" href="icons/Icon-192.png">
|
||||
<!-- iOS meta tags & icons -->
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||||
<meta name="apple-mobile-web-app-title" content="smoke_cess_app" />
|
||||
<link rel="apple-touch-icon" href="icons/Icon-192.png" />
|
||||
|
||||
<!-- Favicon -->
|
||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||
<!-- Favicon -->
|
||||
<link rel="icon" type="image/png" href="favicon.png" />
|
||||
|
||||
<title>smoke_cess_app</title>
|
||||
<link rel="manifest" href="manifest.json">
|
||||
<title>smoke_cess_app</title>
|
||||
<link rel="manifest" href="manifest.json" />
|
||||
|
||||
<script>
|
||||
// The value below is injected by flutter build, do not touch.
|
||||
var serviceWorkerVersion = null;
|
||||
</script>
|
||||
<!-- This script adds the flutter initialization JS code -->
|
||||
<script src="flutter.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
window.addEventListener('load', function(ev) {
|
||||
// Download main.dart.js
|
||||
_flutter.loader.loadEntrypoint({
|
||||
serviceWorker: {
|
||||
serviceWorkerVersion: serviceWorkerVersion,
|
||||
}
|
||||
}).then(function(engineInitializer) {
|
||||
return engineInitializer.initializeEngine();
|
||||
}).then(function(appRunner) {
|
||||
return appRunner.runApp();
|
||||
<script>
|
||||
// The value below is injected by flutter build, do not touch.
|
||||
var serviceWorkerVersion = null;
|
||||
</script>
|
||||
<!-- This script adds the flutter initialization JS code -->
|
||||
<script src="flutter.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
window.addEventListener('load', function (ev) {
|
||||
// Download main.dart.js
|
||||
_flutter.loader
|
||||
.loadEntrypoint({
|
||||
serviceWorker: {
|
||||
serviceWorkerVersion: serviceWorkerVersion,
|
||||
},
|
||||
})
|
||||
.then(function (engineInitializer) {
|
||||
return engineInitializer.initializeEngine();
|
||||
})
|
||||
.then(function (appRunner) {
|
||||
return appRunner.runApp();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/jsqr@1.4.0/dist/jsQR.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue