mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-02-18 00:17:40 +01:00
114 lines
3.6 KiB
Dart
114 lines
3.6 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:swift_control/main.dart';
|
|
import 'package:swift_control/pages/markdown.dart';
|
|
|
|
class ScanWidget extends StatefulWidget {
|
|
const ScanWidget({super.key});
|
|
|
|
@override
|
|
State<ScanWidget> createState() => _ScanWidgetState();
|
|
}
|
|
|
|
class _ScanWidgetState extends State<ScanWidget> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
connection.initialize();
|
|
|
|
/*_isScanningSubscription = FlutterBluePlus.isScanning.listen((state) {
|
|
_isScanning = state;
|
|
if (mounted) {
|
|
setState(() {});
|
|
}
|
|
});*/
|
|
|
|
// after the first frame
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
// must be called from a button
|
|
if (!kIsWeb) {
|
|
Future.delayed(Duration(seconds: 1))
|
|
.then((_) {
|
|
return connection.performScanning();
|
|
})
|
|
.catchError((e) {
|
|
print(e);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ValueListenableBuilder(
|
|
valueListenable: connection.isScanning,
|
|
builder: (context, isScanning, widget) {
|
|
if (isScanning) {
|
|
return Column(
|
|
spacing: 12,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'Scanning for devices... Make sure they are powered on and in range and not connected to another device.',
|
|
),
|
|
if (!kIsWeb && (Platform.isMacOS || Platform.isIOS || Platform.isWindows))
|
|
ValueListenableBuilder(
|
|
valueListenable: connection.isMediaKeyDetectionEnabled,
|
|
builder: (context, value, child) {
|
|
return SwitchListTile.adaptive(
|
|
value: value,
|
|
contentPadding: EdgeInsets.zero,
|
|
dense: true,
|
|
subtitle: Text(
|
|
'Enable this option to allow BikeControl to detect bluetooth remotes. In order to do so BikeControl needs to act as a media player.',
|
|
),
|
|
title: Row(
|
|
children: [
|
|
const Text("Enable Media Key Detection"),
|
|
],
|
|
),
|
|
onChanged: (change) {
|
|
connection.isMediaKeyDetectionEnabled.value = change;
|
|
},
|
|
);
|
|
},
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (c) => MarkdownPage(assetPath: 'TROUBLESHOOTING.md')),
|
|
);
|
|
},
|
|
child: const Text("Show Troubleshooting Guide"),
|
|
),
|
|
SizedBox(),
|
|
],
|
|
);
|
|
} else {
|
|
return Row(
|
|
children: [
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
connection.performScanning();
|
|
},
|
|
child: const Text("SCAN"),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|