feat: add ConnectionStatusButton to show status on LevelSelection
This commit is contained in:
parent
fc951a4df5
commit
d9403d9e98
|
@ -3,6 +3,7 @@ import 'dart:io';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
import 'package:sense_the_rhythm/widgets/connection_status_button.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:sense_the_rhythm/utils/esense_input.dart';
|
import 'package:sense_the_rhythm/utils/esense_input.dart';
|
||||||
import 'package:sense_the_rhythm/utils/simfile.dart';
|
import 'package:sense_the_rhythm/utils/simfile.dart';
|
||||||
|
@ -94,18 +95,16 @@ class _LevelSelectionState extends State<LevelSelection> {
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Sense the Rhythm'),
|
title: const Text('Sense the Rhythm'),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
Padding(
|
||||||
onPressed: () => showDialog(
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
context: context,
|
child: ValueListenableBuilder(
|
||||||
builder: (BuildContext context) {
|
valueListenable: ESenseInput.instance.deviceStatus,
|
||||||
return ESenseConnectDialog(
|
builder:
|
||||||
deviceStatus: ESenseInput.instance.deviceStatus,
|
(BuildContext context, String deviceStatus, Widget? child) {
|
||||||
connect: (String name) {
|
return ConnectionStatusButton(deviceStatus);
|
||||||
ESenseInput.instance.connectToESense(name);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
icon: const Icon(Icons.bluetooth))
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Builder(builder: (context) {
|
body: Builder(builder: (context) {
|
||||||
|
|
36
lib/widgets/connection_status_button.dart
Normal file
36
lib/widgets/connection_status_button.dart
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:sense_the_rhythm/utils/esense_input.dart';
|
||||||
|
import 'package:sense_the_rhythm/widgets/esense_connect_dialog.dart';
|
||||||
|
|
||||||
|
class ConnectionStatusButton extends StatelessWidget {
|
||||||
|
final String deviceStatus;
|
||||||
|
const ConnectionStatusButton(
|
||||||
|
this.deviceStatus, {
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return FilledButton.icon(
|
||||||
|
style: ButtonStyle(
|
||||||
|
backgroundColor: WidgetStateProperty.all(
|
||||||
|
ESenseInput.instance.connected ? Colors.green : Colors.grey),
|
||||||
|
padding:
|
||||||
|
WidgetStateProperty.all(EdgeInsets.symmetric(horizontal: 8.0))),
|
||||||
|
onPressed: () => showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return ESenseConnectDialog(
|
||||||
|
deviceStatus: ESenseInput.instance.deviceStatus,
|
||||||
|
connect: (String name) {
|
||||||
|
ESenseInput.instance.connectToESense(name);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
label: Text(deviceStatus),
|
||||||
|
iconAlignment: IconAlignment.end,
|
||||||
|
icon: Icon(ESenseInput.instance.connected
|
||||||
|
? Icons.bluetooth_connected
|
||||||
|
: Icons.bluetooth));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue