Skip to content

Commit 7a85586

Browse files
committed
Force update when bike page is opened, and slow down delay on initial connection
1 parent c341c10 commit 7a85586

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/bike.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,21 @@ class ForegroundNotificationWrapper extends StatelessWidget {
197197
}
198198

199199
class BikePageState extends ConsumerState<BikePage> {
200+
@override
201+
void initState() {
202+
super.initState();
203+
// Schedule a post-frame callback to ensure providers are initialized
204+
WidgetsBinding.instance.addPostFrameCallback((_) {
205+
final bikeControl = ref.read(bikeProvider(widget.bikeID).notifier);
206+
final connectionState =
207+
ref.read(connectionHandlerProvider(widget.bikeID));
208+
209+
if (connectionState == SDBluetoothConnectionState.connected) {
210+
bikeControl.updateStateDataNow(force: true);
211+
}
212+
});
213+
}
214+
200215
@override
201216
Widget build(BuildContext context) {
202217
var bike = ref.watch(bikeProvider(widget.bikeID));
@@ -205,7 +220,7 @@ class BikePageState extends ConsumerState<BikePage> {
205220
if (previous != SDBluetoothConnectionState.connected &&
206221
next == SDBluetoothConnectionState.connected) {
207222
// add a delay
208-
Future.delayed(const Duration(milliseconds: 200), () {
223+
Future.delayed(const Duration(milliseconds: 1000), () {
209224
bikeControl.updateStateDataNow(force: true);
210225
});
211226
}

0 commit comments

Comments
 (0)