summaryrefslogtreecommitdiff
path: root/lib/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'lib/widgets')
-rw-r--r--lib/widgets/connection_status_section.dart41
-rw-r--r--lib/widgets/device_details.dart36
-rw-r--r--lib/widgets/error_section.dart43
-rw-r--r--lib/widgets/qr_code_entry_section.dart42
-rw-r--r--lib/widgets/refresh_section.dart34
5 files changed, 171 insertions, 25 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();
+ },
+ );
+ }
+}