use provider for scanner
parent
5ab6e598f9
commit
d910e3780f
|
@ -16,7 +16,7 @@ class ScannerPage extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadJSON(BuildContext context) async {
|
void loadJSON(BuildContext context) async {
|
||||||
var settingsModel = context.read<SettingsProvider>();
|
SettingsProvider settingsModel = context.read<SettingsProvider>();
|
||||||
await loadSettingsFromLocalJSON();
|
await loadSettingsFromLocalJSON();
|
||||||
settingsModel.initSettings();
|
settingsModel.initSettings();
|
||||||
NotificationService().setAllNotifications();
|
NotificationService().setAllNotifications();
|
||||||
|
|
|
@ -6,9 +6,16 @@ import '../models/settings.dart';
|
||||||
class SettingsProvider extends ChangeNotifier {
|
class SettingsProvider extends ChangeNotifier {
|
||||||
Settings? _settings;
|
Settings? _settings;
|
||||||
bool _initialized = false;
|
bool _initialized = false;
|
||||||
|
bool _scanning = false;
|
||||||
|
|
||||||
Settings? get settings => _settings;
|
Settings? get settings => _settings;
|
||||||
bool get initialized => _initialized;
|
bool get initialized => _initialized;
|
||||||
|
bool get scanning => _scanning;
|
||||||
|
|
||||||
|
set scanning(bool value) {
|
||||||
|
_scanning = value;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
SettingsProvider() {
|
SettingsProvider() {
|
||||||
initSettings();
|
initSettings();
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class RoundAddButton extends StatelessWidget {
|
class RoundButton extends StatelessWidget {
|
||||||
final VoidCallback onPressed;
|
final VoidCallback onPressed;
|
||||||
final IconData iconData;
|
final IconData iconData;
|
||||||
|
|
||||||
const RoundAddButton(
|
const RoundButton(
|
||||||
{super.key, required this.onPressed, required this.iconData});
|
{super.key, required this.onPressed, required this.iconData});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -7,46 +7,41 @@ import 'package:smoke_cess_app/services/json_service.dart';
|
||||||
import 'package:smoke_cess_app/services/settings_service.dart';
|
import 'package:smoke_cess_app/services/settings_service.dart';
|
||||||
import '../providers/settings_provider.dart';
|
import '../providers/settings_provider.dart';
|
||||||
import '../services/notification_service.dart';
|
import '../services/notification_service.dart';
|
||||||
|
import 'buttons/round_button_widget.dart';
|
||||||
|
|
||||||
class MyScanner extends StatefulWidget {
|
class MyScanner extends StatelessWidget {
|
||||||
const MyScanner({super.key});
|
const MyScanner({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => MyScannerState();
|
Widget build(BuildContext context) {
|
||||||
}
|
SettingsProvider settingsProvider = context.watch<SettingsProvider>();
|
||||||
|
|
||||||
class MyScannerState extends State<MyScanner> {
|
|
||||||
bool scanning = false;
|
|
||||||
|
|
||||||
void handleSucces(String? rawValue) {
|
void handleSucces(String? rawValue) {
|
||||||
String qrText = rawValue!;
|
String qrText = rawValue!;
|
||||||
Map<String, dynamic> json = stringToJSON(qrText);
|
Map<String, dynamic> json = stringToJSON(qrText);
|
||||||
Settings settings = Settings.fromJson(json);
|
Settings settings = Settings.fromJson(json);
|
||||||
saveSettings(settings);
|
saveSettings(settings);
|
||||||
var settingsModel = context.read<SettingsProvider>();
|
settingsProvider.initSettings();
|
||||||
settingsModel.initSettings();
|
|
||||||
NotificationService().setAllNotifications();
|
NotificationService().setAllNotifications();
|
||||||
setState(() {
|
settingsProvider.scanning = false;
|
||||||
scanning = false;
|
|
||||||
AwesomeDialog(
|
AwesomeDialog(
|
||||||
context: context,
|
context: context,
|
||||||
dialogType: DialogType.success,
|
dialogType: DialogType.success,
|
||||||
title: 'Geschafft',
|
title: 'Geschafft',
|
||||||
desc: 'Der Code wurde erfolgreich gescannt!',
|
desc: 'Der Code wurde erfolgreich gescannt!',
|
||||||
).show();
|
).show();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleError() {
|
void handleError() {
|
||||||
setState(() {
|
settingsProvider.scanning = false;
|
||||||
scanning = false;
|
|
||||||
AwesomeDialog(
|
AwesomeDialog(
|
||||||
context: context,
|
context: context,
|
||||||
dialogType: DialogType.error,
|
dialogType: DialogType.error,
|
||||||
title: 'Fehler',
|
title: 'Fehler',
|
||||||
desc: 'Der QR-Code war fehlerhaft!',
|
desc: 'Der QR-Code war fehlerhaft!',
|
||||||
).show();
|
).show();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDetect(capture) {
|
void onDetect(capture) {
|
||||||
|
@ -62,9 +57,7 @@ class MyScannerState extends State<MyScanner> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
return settingsProvider.scanning
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return scanning
|
|
||||||
? Expanded(
|
? Expanded(
|
||||||
child: MobileScanner(
|
child: MobileScanner(
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
|
@ -72,13 +65,9 @@ class MyScannerState extends State<MyScanner> {
|
||||||
detectionTimeoutMs: 2000,
|
detectionTimeoutMs: 2000,
|
||||||
),
|
),
|
||||||
onDetect: onDetect))
|
onDetect: onDetect))
|
||||||
: ElevatedButton(
|
: RoundButton(
|
||||||
style: ElevatedButton.styleFrom(
|
onPressed: () => settingsProvider.scanning = true,
|
||||||
textStyle: const TextStyle(fontSize: 20)),
|
iconData: Icons.qr_code_scanner_outlined,
|
||||||
onPressed: () {
|
|
||||||
setState(() => scanning = true);
|
|
||||||
},
|
|
||||||
child: const Text('Scan QR Code'),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ class ViewFormPage extends StatelessWidget {
|
||||||
if (!pageProvider.showForm)
|
if (!pageProvider.showForm)
|
||||||
Container(
|
Container(
|
||||||
margin: EdgeInsets.symmetric(vertical: height * 0.02),
|
margin: EdgeInsets.symmetric(vertical: height * 0.02),
|
||||||
child: RoundAddButton(
|
child: RoundButton(
|
||||||
iconData: Icons.add_outlined,
|
iconData: Icons.add_outlined,
|
||||||
onPressed: tasksProvider.tasks[page] ?? true
|
onPressed: tasksProvider.tasks[page] ?? true
|
||||||
? () => pageProvider.swap()
|
? () => pageProvider.swap()
|
||||||
|
|
Loading…
Reference in New Issue