From 311a2688cbbda6744c2d8a2afd076e1e3743301d Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 1 Mar 2025 15:43:36 -0600 Subject: [PATCH] gui changes --- web/repertory/lib/helpers.dart | 11 +++++ web/repertory/lib/types/mount_config.dart | 9 +---- web/repertory/lib/widgets/mount_widget.dart | 45 +++++++++++++++++---- 3 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 web/repertory/lib/helpers.dart diff --git a/web/repertory/lib/helpers.dart b/web/repertory/lib/helpers.dart new file mode 100644 index 00000000..4c7ed50a --- /dev/null +++ b/web/repertory/lib/helpers.dart @@ -0,0 +1,11 @@ +String initialCaps(String txt) { + if (txt.isEmpty) { + return txt; + } + + if (txt.length == 1) { + return txt[0].toUpperCase(); + } + + return txt[0].toUpperCase() + txt.substring(1).toLowerCase(); +} diff --git a/web/repertory/lib/types/mount_config.dart b/web/repertory/lib/types/mount_config.dart index 4ee2e312..25ffc7b5 100644 --- a/web/repertory/lib/types/mount_config.dart +++ b/web/repertory/lib/types/mount_config.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; @@ -8,12 +6,10 @@ class MountConfig { String _path = ""; Map _settings = {}; IconData _state = Icons.toggle_off; - Map _status = {}; final String _type; MountConfig({required name, required type}) : _name = name, _type = type; UnmodifiableMapView get settings => UnmodifiableMapView(_settings); - UnmodifiableMapView get status => UnmodifiableMapView(_status); String get name => _name; String get path => _path; @@ -29,8 +25,7 @@ class MountConfig { } void updateStatus(Map status) { - _status = status; - _state = _status["Active"] as bool ? Icons.toggle_on : Icons.toggle_off; - _path = _status["Location"] as String; + _path = status["Location"] as String; + _state = status["Active"] as bool ? Icons.toggle_on : Icons.toggle_off; } } diff --git a/web/repertory/lib/widgets/mount_widget.dart b/web/repertory/lib/widgets/mount_widget.dart index e2054b92..867b342d 100644 --- a/web/repertory/lib/widgets/mount_widget.dart +++ b/web/repertory/lib/widgets/mount_widget.dart @@ -1,27 +1,58 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:repertory/helpers.dart'; import 'package:repertory/models/mount.dart'; -class MountWidget extends StatelessWidget { +class MountWidget extends StatefulWidget { const MountWidget({super.key}); + @override + State createState() => _MountWidgetState(); +} + +class _MountWidgetState extends State { + Timer? _timer; + @override Widget build(BuildContext context) { return Card( child: Consumer( builder: (context, mount, widget) { + final isThreeLine = mount.state == Icons.toggle_on; + return ListTile( - isThreeLine: true, + isThreeLine: isThreeLine, leading: const Icon(Icons.settings), - subtitle: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [Text(mount.name), Text(mount.path)], - ), - title: Text(mount.type), + subtitle: + isThreeLine + ? Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [Text(mount.name), Text(mount.path)], + ) + : Text(mount.name), + title: Text(initialCaps(mount.type)), trailing: Icon(mount.state), ); }, ), ); } + + @override + void dispose() { + _timer?.cancel(); + _timer = null; + super.dispose(); + } + + @override + void initState() { + super.initState(); + _timer = Timer.periodic(const Duration(seconds: 5), (_) { + var provider = Provider.of(context, listen: false); + provider.refresh(); + }); + } }