use texticonbutton for scan and export, use global bool to enable local json config
parent
a99fed7fa2
commit
6d53158b64
|
@ -5,3 +5,6 @@ import 'package:smoke_cess_app/services/database_service.dart';
|
|||
|
||||
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;
|
||||
|
|
|
@ -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<SettingsProvider>();
|
||||
|
||||
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'),
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue