feat: add ConnectionStatusButton to show status on LevelSelection

This commit is contained in:
Orangerot 2025-01-13 16:57:55 +01:00
parent fc951a4df5
commit d9403d9e98
2 changed files with 47 additions and 12 deletions

View file

@ -3,6 +3,7 @@ import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.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:sense_the_rhythm/utils/esense_input.dart';
import 'package:sense_the_rhythm/utils/simfile.dart';
@ -94,18 +95,16 @@ class _LevelSelectionState extends State<LevelSelection> {
appBar: AppBar(
title: const Text('Sense the Rhythm'),
actions: [
IconButton(
onPressed: () => showDialog(
context: context,
builder: (BuildContext context) {
return ESenseConnectDialog(
deviceStatus: ESenseInput.instance.deviceStatus,
connect: (String name) {
ESenseInput.instance.connectToESense(name);
});
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: ValueListenableBuilder(
valueListenable: ESenseInput.instance.deviceStatus,
builder:
(BuildContext context, String deviceStatus, Widget? child) {
return ConnectionStatusButton(deviceStatus);
},
),
icon: const Icon(Icons.bluetooth))
)
],
),
body: Builder(builder: (context) {

View 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));
}
}