|
|
@@ -17,10 +17,12 @@ class CarDataSection extends StatefulWidget {
|
|
|
State<CarDataSection> createState() => _CarDataSectionState();
|
|
|
}
|
|
|
|
|
|
-class _CarDataSectionState extends State<CarDataSection> {
|
|
|
+class _CarDataSectionState extends State<CarDataSection>
|
|
|
+ with WidgetsBindingObserver {
|
|
|
@override
|
|
|
void initState() {
|
|
|
super.initState();
|
|
|
+ WidgetsBinding.instance.addObserver(this);
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
if (!mounted) return;
|
|
|
unawaited(
|
|
|
@@ -29,6 +31,21 @@ class _CarDataSectionState extends State<CarDataSection> {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ @override
|
|
|
+ void dispose() {
|
|
|
+ WidgetsBinding.instance.removeObserver(this);
|
|
|
+ super.dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
+ if (state == AppLifecycleState.resumed) {
|
|
|
+ unawaited(
|
|
|
+ context.read<ObdController>().refreshDevices(requestPermission: false),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
final colors = context.colors;
|
|
|
@@ -167,6 +184,28 @@ class _CarDataSectionState extends State<CarDataSection> {
|
|
|
style: theme.textTheme.bodySmall?.copyWith(color: colors.danger),
|
|
|
),
|
|
|
],
|
|
|
+ if (obd.bluetoothEnabled == false) ...[
|
|
|
+ const SizedBox(height: 2),
|
|
|
+ TextButton.icon(
|
|
|
+ onPressed: () async {
|
|
|
+ final opened = await obd.openBluetoothSettings();
|
|
|
+ if (!opened && context.mounted) {
|
|
|
+ _message(context, 'Could not open Bluetooth settings.');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ icon: AppIcon(
|
|
|
+ 'assets/icons/settings.svg',
|
|
|
+ size: 16,
|
|
|
+ color: colors.accent,
|
|
|
+ ),
|
|
|
+ label: const Text('Open Bluetooth settings'),
|
|
|
+ style: TextButton.styleFrom(
|
|
|
+ foregroundColor: colors.accent,
|
|
|
+ padding: EdgeInsets.zero,
|
|
|
+ alignment: Alignment.centerLeft,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
const SizedBox(height: 8),
|
|
|
Text(
|
|
|
'Pair the ELM327 in Android Bluetooth settings first. CarDash only '
|