diff options
| author | uvok | 2025-08-03 16:34:00 +0200 | 
|---|---|---|
| committer | uvok | 2025-08-03 16:34:00 +0200 | 
| commit | 671c6aa65937c914413ce53bbb855ee780b7df21 (patch) | |
| tree | 5cddfb22881de24d7569cc92c5bd77f392a18232 | |
| parent | 9d18247793203275f0118b13f8e10d12acfdaf67 (diff) | |
Avoid late final by using factory ctor/getters
| -rw-r--r-- | lib/model/motive_selection/flutter_blue_plus_motive_selection.dart | 6 | ||||
| -rw-r--r-- | lib/widgets/device_details.dart | 38 | 
2 files changed, 27 insertions, 17 deletions
| diff --git a/lib/model/motive_selection/flutter_blue_plus_motive_selection.dart b/lib/model/motive_selection/flutter_blue_plus_motive_selection.dart index 4046d83..561388a 100644 --- a/lib/model/motive_selection/flutter_blue_plus_motive_selection.dart +++ b/lib/model/motive_selection/flutter_blue_plus_motive_selection.dart @@ -35,12 +35,10 @@ class FlutterBluePlusMotiveSelection    List<BadgeMotive> _cachedMotives = []; -  late final BluetoothDevice _fbpDevice; +  BluetoothDevice get _fbpDevice => _device.scanResult.device;    FlutterBluePlusMotiveSelection({required FlutterBluePlusDevice device}) -    : _device = device { -    _fbpDevice = _device.scanResult.device; -  } +    : _device = device;    @override    Future<BadgeMotive> getCurrentMotive() async { diff --git a/lib/widgets/device_details.dart b/lib/widgets/device_details.dart index 0463522..dc8ca97 100644 --- a/lib/widgets/device_details.dart +++ b/lib/widgets/device_details.dart @@ -29,19 +29,31 @@ var logger = Logger();  class DeviceDetailsScreen extends StatefulWidget {    final Device device;    final DeviceConnection deviceConnection; +  final BadgeMotiveSelection motiveSelection; +  final BadgeMotiveViewModel motiveVM; -  late final BadgeMotiveSelection _motiveSelection; -  late final BadgeMotiveViewModel _motiveVM; - -  DeviceDetailsScreen({ +  const DeviceDetailsScreen._({      super.key,      required this.device,      required this.deviceConnection, +    required this.motiveSelection, +    required this.motiveVM, +  }); + +  factory DeviceDetailsScreen({ +    Key? key, +    required Device device, +    required DeviceConnection deviceConnection,    }) { -    _motiveSelection = BadgeMotiveSelectionFactory.createBadgeMotiveSelection( -      device, +    var ms = BadgeMotiveSelectionFactory.createBadgeMotiveSelection(device); +    var mvm = BadgeMotiveViewModel(motivSelect: ms); +    return DeviceDetailsScreen._( +      key: key, +      device: device, +      deviceConnection: deviceConnection, +      motiveSelection: ms, +      motiveVM: mvm,      ); -    _motiveVM = BadgeMotiveViewModel(motivSelect: _motiveSelection);    }    @override @@ -85,17 +97,17 @@ class DeviceDetailsState extends State<DeviceDetailsScreen> {                  ElevatedButton(                    child: Text("Refresh"),                    onPressed: () async { -                    await widget._motiveVM.updateMotives(); -                    await widget._motiveVM.getCurrentMotive(); +                    await widget.motiveVM.updateMotives(); +                    await widget.motiveVM.getCurrentMotive();                    },                  ),                  ListenableBuilder( -                  listenable: widget._motiveVM, +                  listenable: widget.motiveVM,                    builder: (errorCtx, child) { -                    if (widget._motiveVM.errorMessage != null) { +                    if (widget.motiveVM.errorMessage != null) {                        var theme = Theme.of(errorCtx);                        return Text( -                        widget._motiveVM.errorMessage!, +                        widget.motiveVM.errorMessage!,                          style: TextStyle(                            color: theme.colorScheme.error,                            fontWeight: FontWeight.bold, @@ -105,7 +117,7 @@ class DeviceDetailsState extends State<DeviceDetailsScreen> {                      return Container();                    },                  ), -                BadgeMotiveList(motiveVM: widget._motiveVM), +                BadgeMotiveList(motiveVM: widget.motiveVM),                ],              );            }, | 
