diff options
| -rw-r--r-- | lib/widgets/connection_status_section.dart | 41 | ||||
| -rw-r--r-- | lib/widgets/device_details.dart | 36 | ||||
| -rw-r--r-- | lib/widgets/error_section.dart | 43 | ||||
| -rw-r--r-- | lib/widgets/qr_code_entry_section.dart | 42 | ||||
| -rw-r--r-- | lib/widgets/refresh_section.dart | 34 | ||||
| -rw-r--r-- | test/scanning_widget_test.dart | 1 |
6 files changed, 171 insertions, 26 deletions
diff --git a/lib/widgets/connection_status_section.dart b/lib/widgets/connection_status_section.dart new file mode 100644 index 0000000..a517c62 --- /dev/null +++ b/lib/widgets/connection_status_section.dart @@ -0,0 +1,41 @@ +// Copyright (C) 2025, uvok cheetah +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +import 'package:flutter/widgets.dart'; +import 'package:uvok_epaper_badge/model/connection/device_connection.dart'; + +String connStateToString(ConnectionStatus connectionStatus) { + switch (connectionStatus) { + case ConnectionStatus.connected: + return "connected"; + case ConnectionStatus.disconnected: + return "disconnected"; + case ConnectionStatus.error: + return "An error occurred"; + default: + return "Unknown"; + } +} + +class ConnectionStatusSection extends StatelessWidget { + final ConnectionStatus connectionStatus; + + const ConnectionStatusSection({super.key, required this.connectionStatus}); + + @override + Widget build(BuildContext context) { + return Text("Connection state: ${connStateToString(connectionStatus)}"); + } +} diff --git a/lib/widgets/device_details.dart b/lib/widgets/device_details.dart index a865e45..a030144 100644 --- a/lib/widgets/device_details.dart +++ b/lib/widgets/device_details.dart @@ -23,6 +23,10 @@ import 'package:uvok_epaper_badge/model/connection/device_connection.dart'; import 'package:uvok_epaper_badge/model/motive_selection/badge_motive_selection.dart'; import 'package:uvok_epaper_badge/view_model/badge_motive_view_model.dart'; import 'package:uvok_epaper_badge/widgets/badge_motive_list.dart'; +import 'package:uvok_epaper_badge/widgets/connection_status_section.dart'; +import 'package:uvok_epaper_badge/widgets/error_section.dart'; +import 'package:uvok_epaper_badge/widgets/qr_code_entry_section.dart'; +import 'package:uvok_epaper_badge/widgets/refresh_section.dart'; var logger = fileLogger(); @@ -88,35 +92,17 @@ class DeviceDetailsState extends State<DeviceDetailsScreen> { body: Center( child: ValueListenableBuilder( valueListenable: widget.deviceConnection.status, - builder: (connCtx, ConnectionStatus value, child) { + builder: (connCtx, ConnectionStatus value, _) { + // final isConnected = value == ConnectionStatus.connected; + return Column( spacing: 20, children: [ SizedBox(height: 20), - Text("Connection state: ${value.toString()}"), - ElevatedButton( - child: Text("Refresh"), - onPressed: () async { - await widget.motiveVM.updateMotives(); - await widget.motiveVM.getCurrentMotive(); - }, - ), - ListenableBuilder( - listenable: widget.motiveVM, - builder: (errorCtx, child) { - if (widget.motiveVM.errorMessage != null) { - var theme = Theme.of(errorCtx); - return Text( - widget.motiveVM.errorMessage!, - style: TextStyle( - color: theme.colorScheme.error, - fontWeight: FontWeight.bold, - ), - ); - } - return Container(); - }, - ), + ConnectionStatusSection(connectionStatus: value), + RefreshSection(motiveVM: widget.motiveVM), + ErrorSection(motiveVM: widget.motiveVM), + QRCodeEntrySection(motiveVM: widget.motiveVM), BadgeMotiveList(motiveVM: widget.motiveVM), ], ); diff --git a/lib/widgets/error_section.dart b/lib/widgets/error_section.dart new file mode 100644 index 0000000..19969b2 --- /dev/null +++ b/lib/widgets/error_section.dart @@ -0,0 +1,43 @@ +// Copyright (C) 2025, uvok cheetah +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +import 'package:flutter/material.dart'; +import 'package:uvok_epaper_badge/view_model/badge_motive_view_model.dart'; + +class ErrorSection extends StatelessWidget { + final BadgeMotiveViewModel motiveVM; + + const ErrorSection({super.key, required this.motiveVM}); + + @override + Widget build(BuildContext context) { + return ListenableBuilder( + listenable: motiveVM, + builder: (errorCtx, child) { + if (motiveVM.errorMessage != null) { + var theme = Theme.of(errorCtx); + return Text( + motiveVM.errorMessage!, + style: TextStyle( + color: theme.colorScheme.error, + fontWeight: FontWeight.bold, + ), + ); + } + return Container(); + }, + ); + } +} diff --git a/lib/widgets/qr_code_entry_section.dart b/lib/widgets/qr_code_entry_section.dart new file mode 100644 index 0000000..658a288 --- /dev/null +++ b/lib/widgets/qr_code_entry_section.dart @@ -0,0 +1,42 @@ +// Copyright (C) 2025, uvok cheetah +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +import 'package:flutter/material.dart'; +import 'package:uvok_epaper_badge/view_model/badge_motive_view_model.dart'; + +class QRCodeEntrySection extends StatelessWidget { + final BadgeMotiveViewModel motiveVM; + + const QRCodeEntrySection({super.key, required this.motiveVM}); + + @override + Widget build(BuildContext context) { + return Column( + spacing: 20, + children: [ + TextField( + controller: motiveVM.qrCodeTextController, + decoration: InputDecoration(hintText: "Enter text for QR code"), + ), + ElevatedButton( + onPressed: () async { + await motiveVM.sendText(); + }, + child: Text("Send text"), + ), + ], + ); + } +} diff --git a/lib/widgets/refresh_section.dart b/lib/widgets/refresh_section.dart new file mode 100644 index 0000000..958b1af --- /dev/null +++ b/lib/widgets/refresh_section.dart @@ -0,0 +1,34 @@ +// Copyright (C) 2025, uvok cheetah +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +import 'package:flutter/material.dart'; +import 'package:uvok_epaper_badge/view_model/badge_motive_view_model.dart'; + +class RefreshSection extends StatelessWidget { + final BadgeMotiveViewModel motiveVM; + + const RefreshSection({super.key, required this.motiveVM}); + + @override + Widget build(BuildContext context) { + return ElevatedButton( + child: Text("Refresh"), + onPressed: () async { + await motiveVM.updateMotives(); + await motiveVM.getCurrentMotive(); + }, + ); + } +} diff --git a/test/scanning_widget_test.dart b/test/scanning_widget_test.dart index 987dc59..552b8c5 100644 --- a/test/scanning_widget_test.dart +++ b/test/scanning_widget_test.dart @@ -5,7 +5,6 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. -import 'package:flutter/widgets.dart'; import 'package:uvok_epaper_badge/control/mock_scanner_controller.dart'; import 'package:uvok_epaper_badge/control/scanner_controller.dart'; import 'package:uvok_epaper_badge/widgets/badge_app.dart'; |
