- settings_provider: AppSettings (ecuType, pollingInterval) StateNotifier - bt_provider: BtNotifier (disconnected/connecting/connected/error states), btServiceProvider singleton, pairedDevicesProvider FutureProvider, internal frameStream piped through StreamController - sensor_provider: sensorStateProvider StreamProvider (auto S300/KPro), latestSensorProvider convenience Provider - theme_provider: AppThemeVariant (red/green × dark/light) StateNotifier - main.dart: fully Riverpod — ProviderScope, ConsumerWidget throughout, no setState for BT state, providers own all lifecycle
32 lines
909 B
Dart
32 lines
909 B
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../bluetooth/bt_poller.dart';
|
|
|
|
class AppSettings {
|
|
final EcuType ecuType;
|
|
final Duration pollingInterval;
|
|
|
|
const AppSettings({
|
|
this.ecuType = EcuType.s300,
|
|
this.pollingInterval = const Duration(milliseconds: 100),
|
|
});
|
|
|
|
AppSettings copyWith({EcuType? ecuType, Duration? pollingInterval}) =>
|
|
AppSettings(
|
|
ecuType: ecuType ?? this.ecuType,
|
|
pollingInterval: pollingInterval ?? this.pollingInterval,
|
|
);
|
|
}
|
|
|
|
class SettingsNotifier extends StateNotifier<AppSettings> {
|
|
SettingsNotifier() : super(const AppSettings());
|
|
|
|
void setEcuType(EcuType type) => state = state.copyWith(ecuType: type);
|
|
void setPollingInterval(Duration d) =>
|
|
state = state.copyWith(pollingInterval: d);
|
|
}
|
|
|
|
final settingsProvider =
|
|
StateNotifierProvider<SettingsNotifier, AppSettings>(
|
|
(ref) => SettingsNotifier(),
|
|
);
|