65 lines
2.1 KiB
Dart
65 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:sense_the_rhythm/utils/esense_input.dart';
|
|
|
|
class ESenseConnectDialog extends StatefulWidget {
|
|
final void Function(String) connect;
|
|
final VoidCallback disconnect;
|
|
final ValueNotifier<String> deviceStatus;
|
|
|
|
const ESenseConnectDialog(
|
|
{super.key,
|
|
required this.deviceStatus,
|
|
required this.connect,
|
|
required this.disconnect});
|
|
|
|
@override
|
|
State<ESenseConnectDialog> createState() => _ESenseConnectDialogState();
|
|
}
|
|
|
|
class _ESenseConnectDialogState extends State<ESenseConnectDialog> {
|
|
String _eSenseDeviceName = '';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// rerender whenever the deviceStatus changes
|
|
return ValueListenableBuilder(
|
|
valueListenable: widget.deviceStatus,
|
|
builder: (BuildContext context, String deviceStatus, Widget? child) {
|
|
return AlertDialog(
|
|
title: const Text('Connect to ESense'),
|
|
content: Column(mainAxisSize: MainAxisSize.min, children: [
|
|
TextField(
|
|
onChanged: (input) {
|
|
setState(() {
|
|
_eSenseDeviceName = input;
|
|
});
|
|
},
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
hintText: 'eSense-xxxx',
|
|
labelText: 'Device name',
|
|
),
|
|
),
|
|
// Text(eSenseDeviceName),
|
|
Text(deviceStatus)
|
|
]),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, 'Cancel'),
|
|
child: const Text('Close'),
|
|
),
|
|
ESenseInput.instance.connected
|
|
? TextButton(
|
|
onPressed: () => widget.disconnect(),
|
|
child: const Text('Disconnect'),
|
|
)
|
|
: TextButton(
|
|
onPressed: () => widget.connect(_eSenseDeviceName),
|
|
child: const Text('Connect'),
|
|
),
|
|
],
|
|
);
|
|
});
|
|
}
|
|
}
|