From 7887ab9999b384e567cb8c19d38c13057d127573 Mon Sep 17 00:00:00 2001 From: uvok Date: Thu, 31 Jul 2025 18:14:54 +0200 Subject: ValueNotifier, remove manual back button --- lib/widgets/device_details.dart | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'lib/widgets/device_details.dart') diff --git a/lib/widgets/device_details.dart b/lib/widgets/device_details.dart index e481303..0081d3c 100644 --- a/lib/widgets/device_details.dart +++ b/lib/widgets/device_details.dart @@ -13,6 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'dart:io'; import 'dart:ui'; import 'package:uvok_epaper_badge/model/device/device.dart'; @@ -39,7 +40,6 @@ class DeviceDetailsScreen extends StatefulWidget { } class DeviceDetailsState extends State { - String connectStatus = ""; late final AppLifecycleListener appLL; /// Whether the back button should be active. @@ -63,15 +63,14 @@ class DeviceDetailsState extends State { title: Text("Device details"), ), body: Center( - child: Column( - spacing: 20, - children: [ - Text(connectStatus), - ElevatedButton( - onPressed: backActive ? backClick : null, - child: Text("Back"), - ), - ], + child: ValueListenableBuilder( + valueListenable: widget.deviceConnection.status, + builder: (connCtx, ConnectionStatus value, child) { + return Column( + spacing: 20, + children: [Text("Connection state: ${value.toString()}")], + ); + }, ), ), ); @@ -83,10 +82,6 @@ class DeviceDetailsState extends State { _doConnect(); } - void backClick() { - Navigator.pop(context); - } - @override void deactivate() { logger.i("(widget deactivate)"); @@ -102,20 +97,14 @@ class DeviceDetailsState extends State { } void _doConnect() async { - final dev = widget.device; - try { logger.i("Try to connect..."); await widget.deviceConnection.connect(); } catch (e) { logger.e(e); await widget.deviceConnection.disconnect(); - connectStatus = e.toString(); } finally { backActive = true; - if (mounted) { - setState(() {}); - } } } } -- cgit v1.2.3