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