added popup on successfull scan
parent
74946d005c
commit
5393590687
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
"group": "Gruppe 2",
|
|
||||||
"key": "value"
|
|
||||||
}
|
|
|
@ -41,7 +41,10 @@ class MyHomePageState extends State<MyHomePage> {
|
||||||
: showDialog(
|
: showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return const MissingConfigPopup();
|
return const MissingConfigPopup(
|
||||||
|
title: 'Fehlende Konfiguration',
|
||||||
|
text: 'Bitte QR Code Scannen!',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,71 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mobile_scanner/mobile_scanner.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 'package:smoke_cess_app/service/settings_service.dart';
|
||||||
|
|
||||||
class ScannerPage extends StatelessWidget {
|
import '../widgets/missing_config_popup.dart';
|
||||||
|
|
||||||
|
class ScannerPage extends StatefulWidget {
|
||||||
const ScannerPage({super.key});
|
const ScannerPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<StatefulWidget> createState() => ScannerPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class ScannerPageState extends State<ScannerPage> {
|
||||||
|
bool scanning = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Center(
|
return Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Expanded(child: MobileScanner(fit: BoxFit.contain,onDetect: (capture) {
|
scanning
|
||||||
final List<Barcode> barcodes = capture.barcodes;
|
? Expanded(
|
||||||
for (final barcode in barcodes) {
|
child: MobileScanner(
|
||||||
debugPrint('Barcode found! ${barcode.rawValue}');
|
fit: BoxFit.contain,
|
||||||
} },
|
controller: MobileScannerController(
|
||||||
|
detectionTimeoutMs: 2000,
|
||||||
))
|
),
|
||||||
,
|
onDetect: (capture) {
|
||||||
|
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),
|
const SizedBox(height: 30),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
textStyle: const TextStyle(fontSize: 20)),
|
textStyle: const TextStyle(fontSize: 20)),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
loadSettings();
|
loadSettingsFromLocalJSON();
|
||||||
},
|
},
|
||||||
child: const Text('Read JSON'),
|
child: const Text('Read JSON'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,3 +10,5 @@ Future<Map<String, dynamic>> loadLocalConfigJSON() async {
|
||||||
|
|
||||||
List<String>? jsonPropertyAsList(dynamic property) =>
|
List<String>? jsonPropertyAsList(dynamic property) =>
|
||||||
property != null ? List.from(property) : null;
|
property != null ? List.from(property) : null;
|
||||||
|
|
||||||
|
Map<String, dynamic> stringToJSON(String jsonString) => jsonDecode(jsonString);
|
||||||
|
|
|
@ -45,7 +45,7 @@ Future<List<String>?> _getStringListSetting(String settingKey) =>
|
||||||
SharedPreferences.getInstance()
|
SharedPreferences.getInstance()
|
||||||
.then((pref) => pref.getStringList(settingKey));
|
.then((pref) => pref.getStringList(settingKey));
|
||||||
|
|
||||||
Future<void> loadSettings() async {
|
Future<void> loadSettingsFromLocalJSON() async {
|
||||||
Map<String, dynamic> configJSON = await loadLocalConfigJSON();
|
Map<String, dynamic> configJSON = await loadLocalConfigJSON();
|
||||||
Settings settings = Settings.fromJson(configJSON);
|
Settings settings = Settings.fromJson(configJSON);
|
||||||
saveSettings(settings);
|
saveSettings(settings);
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class MissingConfigPopup extends StatelessWidget {
|
class MissingConfigPopup extends StatelessWidget {
|
||||||
const MissingConfigPopup({super.key});
|
final String title;
|
||||||
|
final String text;
|
||||||
|
const MissingConfigPopup(
|
||||||
|
{super.key, required this.title, required this.text});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: const Text('Fehlende Konfiguration'),
|
title: Text(title),
|
||||||
content: Column(
|
content: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: const <Widget>[
|
children: <Widget>[
|
||||||
Text("Bitte QR Code Scannen"),
|
Text(text),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -64,7 +64,6 @@ flutter:
|
||||||
# - images/a_dot_burr.jpeg
|
# - images/a_dot_burr.jpeg
|
||||||
# - images/a_dot_ham.jpeg
|
# - images/a_dot_ham.jpeg
|
||||||
assets:
|
assets:
|
||||||
- config.json
|
|
||||||
- group1.json
|
- group1.json
|
||||||
- group3.json
|
- group3.json
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue