From 6d53158b64e2a1aebf7c8c66c0719a4c38bad5e5 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Mon, 6 Mar 2023 15:54:13 +0100 Subject: [PATCH] use texticonbutton for scan and export, use global bool to enable local json config --- lib/globals.dart | 5 +++- lib/pages/scanner_page.dart | 30 +++++++++++++---------- lib/widgets/buttons/text_icon_button.dart | 29 ++++++++++++++++++++++ lib/widgets/scanner.dart | 7 +++--- 4 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 lib/widgets/buttons/text_icon_button.dart diff --git a/lib/globals.dart b/lib/globals.dart index 58229d9..3cdf823 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -3,5 +3,8 @@ library app.globals; import 'package:smoke_cess_app/mock/db_mock.dart'; import 'package:smoke_cess_app/services/database_service.dart'; -DatabaseService databaseService = DatabaseMock(); +DatabaseService databaseService = DatabaseMock(); // DatabaseService databaseService = DatabaseService.instance; + +// set this to read settings from local json file instead of scanning a qr code +bool useLocalConfig = false; diff --git a/lib/pages/scanner_page.dart b/lib/pages/scanner_page.dart index 14b944c..7ba67d4 100644 --- a/lib/pages/scanner_page.dart +++ b/lib/pages/scanner_page.dart @@ -4,8 +4,11 @@ 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}); @@ -32,25 +35,26 @@ class ScannerPage extends StatelessWidget { @override Widget build(BuildContext context) { + SettingsProvider settingsProvider = context.watch(); + return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const MyScanner(), const SizedBox(height: 30), - ElevatedButton( - style: ElevatedButton.styleFrom( - textStyle: const TextStyle(fontSize: 20)), - onPressed: () => loadJSON(context), - child: const Text('Read JSON'), - ), - const SizedBox(height: 30), - ElevatedButton( - style: ElevatedButton.styleFrom( - textStyle: const TextStyle(fontSize: 20)), - onPressed: export, - child: const Text('Export'), - ) + 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'), + ), ], )); } diff --git a/lib/widgets/buttons/text_icon_button.dart b/lib/widgets/buttons/text_icon_button.dart new file mode 100644 index 0000000..85534e2 --- /dev/null +++ b/lib/widgets/buttons/text_icon_button.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; + +class TextIconButton extends StatelessWidget { + final String text; + final VoidCallback onPressed; + final IconData iconData; + + const TextIconButton( + {super.key, + required this.text, + required this.onPressed, + required this.iconData}); + + @override + Widget build(BuildContext context) { + return SizedBox( + width: MediaQuery.of(context).size.width * 0.4, + child: FloatingActionButton.extended( + label: Text(text), + backgroundColor: Theme.of(context).colorScheme.primary, + icon: Icon( + iconData, + size: 24.0, + ), + onPressed: onPressed, + ), + ); + } +} diff --git a/lib/widgets/scanner.dart b/lib/widgets/scanner.dart index a30f1e1..5d45bbe 100644 --- a/lib/widgets/scanner.dart +++ b/lib/widgets/scanner.dart @@ -5,6 +5,7 @@ import 'package:provider/provider.dart'; import 'package:smoke_cess_app/models/settings.dart'; import 'package:smoke_cess_app/services/json_service.dart'; import 'package:smoke_cess_app/services/settings_service.dart'; +import 'package:smoke_cess_app/widgets/buttons/text_icon_button.dart'; import '../providers/settings_provider.dart'; import '../services/notification_service.dart'; import 'buttons/round_button_widget.dart'; @@ -77,9 +78,9 @@ class MyScanner extends StatelessWidget { color: Colors.white.withOpacity(0.4))), ], )) - : RoundButton( + : TextIconButton( + text: "Scan", onPressed: () => settingsProvider.scanning = true, - iconData: Icons.qr_code_scanner_outlined, - ); + iconData: Icons.qr_code_scanner_outlined); } }