cpd_2022_zi/lib/pages/scanner_page.dart

62 lines
2.0 KiB
Dart

import 'package:awesome_dialog/awesome_dialog.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:smoke_cess_app/services/export_service.dart';
import 'package:smoke_cess_app/services/settings_service.dart';
import 'package:smoke_cess_app/services/notification_service.dart';
import 'package:smoke_cess_app/widgets/buttons/round_button_widget.dart';
import 'package:smoke_cess_app/widgets/buttons/text_icon_button.dart';
import 'package:smoke_cess_app/widgets/scanner.dart';
import '../providers/settings_provider.dart';
import '../globals.dart' as globals;
class ScannerPage extends StatelessWidget {
const ScannerPage({super.key});
void export() async {
ExportService exportService = ExportService();
exportService.exportData();
}
void loadJSON(BuildContext context) async {
SettingsProvider settingsModel = context.read<SettingsProvider>();
await loadSettingsFromLocalJSON();
settingsModel.initSettings();
NotificationService().setAllNotifications();
if (context.mounted) {
AwesomeDialog(
context: context,
dialogType: DialogType.success,
title: 'Geschafft',
desc: 'Die Einstellung wurden erfolgreich gespeichert',
).show();
}
}
@override
Widget build(BuildContext context) {
SettingsProvider settingsProvider = context.watch<SettingsProvider>();
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const MyScanner(),
const SizedBox(height: 30),
if (!settingsProvider.scanning)
TextIconButton(
text: 'Export',
onPressed: ExportService().exportData,
iconData: Icons.upload),
if (globals.useLocalConfig && !settingsProvider.scanning)
ElevatedButton(
style: ElevatedButton.styleFrom(
textStyle: const TextStyle(fontSize: 20)),
onPressed: () => loadJSON(context),
child: const Text('Read JSON'),
),
],
));
}
}