spotube/lib/components/Shared/RecordHotKeyDialog.dart
Kingkor Roy Tirtho e666e25ffd Global custom hotkey support for playback control
UserPreferences provider genius access token not loading on init bug fix
2022-02-06 10:01:29 +06:00

92 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:hotkey_manager/hotkey_manager.dart';
class RecordHotKeyDialog extends StatefulWidget {
final ValueChanged<HotKey> onHotKeyRecorded;
const RecordHotKeyDialog({
Key? key,
required this.onHotKeyRecorded,
}) : super(key: key);
@override
_RecordHotKeyDialogState createState() => _RecordHotKeyDialogState();
}
class _RecordHotKeyDialogState extends State<RecordHotKeyDialog> {
HotKey _hotKey = HotKey(null);
@override
Widget build(BuildContext context) {
return AlertDialog(
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text(
'Press the keys you want to use',
style: Theme.of(context).textTheme.headline5,
),
const SizedBox(height: 10),
const Text(
"DO NOT Use only letters (e.g. k, g etc..)\nUse in combination with these"),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
KeyCode.control,
KeyCode.shift,
KeyCode.alt,
KeyCode.superKey,
KeyCode.meta,
]
.map((key) => HotKeyVirtualView(
hotKey: HotKey(key),
))
.toList(),
),
Container(
width: 100,
height: 60,
margin: const EdgeInsets.only(top: 20),
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).primaryColor,
),
),
child: Stack(
alignment: Alignment.center,
children: [
HotKeyRecorder(
onHotKeyRecorded: (hotKey) {
setState(() {
_hotKey = hotKey;
});
},
),
],
),
),
],
),
),
actions: <Widget>[
TextButton(
child: const Text('Cancel'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: const Text('OK'),
onPressed: !_hotKey.isSetted
? null
: () {
widget.onHotKeyRecorded(_hotKey);
Navigator.of(context).pop();
},
),
],
);
}
}