From e82083b9e2166b4e427ae23630871914dc72f276 Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 2 Aug 2025 10:26:31 +0200 Subject: DD: Pull up button, error text, ViewModel ListView should really only be a list. Makes more sense to add error after rfresh button. --- lib/widgets/device_details.dart | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'lib/widgets/device_details.dart') diff --git a/lib/widgets/device_details.dart b/lib/widgets/device_details.dart index 17319f4..0463522 100644 --- a/lib/widgets/device_details.dart +++ b/lib/widgets/device_details.dart @@ -30,14 +30,19 @@ class DeviceDetailsScreen extends StatefulWidget { final Device device; final DeviceConnection deviceConnection; - final BadgeMotiveSelection _motiveSelection; + late final BadgeMotiveSelection _motiveSelection; + late final BadgeMotiveViewModel _motiveVM; DeviceDetailsScreen({ super.key, required this.device, required this.deviceConnection, - }) : _motiveSelection = - BadgeMotiveSelectionFactory.createBadgeMotiveSelection(device); + }) { + _motiveSelection = BadgeMotiveSelectionFactory.createBadgeMotiveSelection( + device, + ); + _motiveVM = BadgeMotiveViewModel(motivSelect: _motiveSelection); + } @override State createState() { @@ -77,11 +82,30 @@ class DeviceDetailsState extends State { children: [ SizedBox(height: 20), Text("Connection state: ${value.toString()}"), - BadgeMotiveList( - motiveVM: BadgeMotiveViewModel( - motivSelect: widget._motiveSelection, - ), + 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(); + }, ), + BadgeMotiveList(motiveVM: widget._motiveVM), ], ); }, -- cgit v1.2.3