69 lines
1.6 KiB
Dart
69 lines
1.6 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_blue_plus_windows/flutter_blue_plus_windows.dart';
|
|
|
|
class BluetoothOffScreen extends StatelessWidget {
|
|
const BluetoothOffScreen({
|
|
super.key,
|
|
this.adapterState,
|
|
});
|
|
|
|
final BluetoothAdapterState? adapterState;
|
|
|
|
Widget buildBluetoothOffIcon(BuildContext context) {
|
|
return const Icon(
|
|
Icons.bluetooth_disabled,
|
|
size: 200,
|
|
color: Colors.white54,
|
|
);
|
|
}
|
|
|
|
Widget buildTitle(BuildContext context) {
|
|
String? state = adapterState?.toString().split(".").last;
|
|
return Text(
|
|
'Bluetooth Adapter is ${state != null ? state : 'not available'}',
|
|
style: Theme.of(context)
|
|
.primaryTextTheme
|
|
.titleSmall
|
|
?.copyWith(color: Colors.white),
|
|
);
|
|
}
|
|
|
|
Widget buildTurnOnButton(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(20),
|
|
child: ElevatedButton(
|
|
onPressed: () async {
|
|
try {
|
|
if (Platform.isAndroid) {
|
|
await FlutterBluePlus.turnOn();
|
|
}
|
|
} catch (e) {
|
|
print("Error Turning On: $e");
|
|
}
|
|
},
|
|
child: const Text('TURN ON'),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ScaffoldMessenger(
|
|
child: Scaffold(
|
|
backgroundColor: Colors.lightBlue,
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
buildBluetoothOffIcon(context),
|
|
buildTitle(context),
|
|
if (Platform.isAndroid) buildTurnOnButton(context),
|
|
],
|
|
),
|
|
),
|
|
));
|
|
}
|
|
}
|