diff options
author | uvok | 2025-07-31 18:14:54 +0200 |
---|---|---|
committer | uvok | 2025-07-31 18:14:54 +0200 |
commit | 7887ab9999b384e567cb8c19d38c13057d127573 (patch) | |
tree | 9a7b6bf04d2f9b5cc2d26e496ff6af659fb87db3 /lib/widgets/device_details.dart | |
parent | 32f6e089c79ba1c3a9d5ee438999dc4b8f784871 (diff) |
ValueNotifier, remove manual back button
Diffstat (limited to 'lib/widgets/device_details.dart')
-rw-r--r-- | lib/widgets/device_details.dart | 29 |
1 files changed, 9 insertions, 20 deletions
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 <https://www.gnu.org/licenses/>. +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<DeviceDetailsScreen> { - String connectStatus = "<Status>"; late final AppLifecycleListener appLL; /// Whether the back button should be active. @@ -63,15 +63,14 @@ class DeviceDetailsState extends State<DeviceDetailsScreen> { 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<DeviceDetailsScreen> { _doConnect(); } - void backClick() { - Navigator.pop(context); - } - @override void deactivate() { logger.i("(widget deactivate)"); @@ -102,20 +97,14 @@ class DeviceDetailsState extends State<DeviceDetailsScreen> { } 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(() {}); - } } } } |