Complete refactor to clean up project
This commit is contained in:
40
lib/shared/input/pedal_shortcuts.dart
Normal file
40
lib/shared/input/pedal_shortcuts.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// Widget that handles Bluetooth pedal and keyboard shortcuts for page turning.
|
||||
///
|
||||
/// Listens for arrow key presses and invokes the appropriate callback:
|
||||
/// - Arrow Down/Right: Turn page forward
|
||||
/// - Arrow Up/Left: Turn page backward
|
||||
class PedalShortcuts extends StatelessWidget {
|
||||
final Widget child;
|
||||
final VoidCallback onPageForward;
|
||||
final VoidCallback onPageBackward;
|
||||
|
||||
const PedalShortcuts({
|
||||
super.key,
|
||||
required this.child,
|
||||
required this.onPageForward,
|
||||
required this.onPageBackward,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CallbackShortcuts(
|
||||
bindings: _buildBindings(),
|
||||
child: Focus(autofocus: true, child: child),
|
||||
);
|
||||
}
|
||||
|
||||
Map<ShortcutActivator, VoidCallback> _buildBindings() {
|
||||
return {
|
||||
// Forward navigation
|
||||
const SingleActivator(LogicalKeyboardKey.arrowDown): onPageForward,
|
||||
const SingleActivator(LogicalKeyboardKey.arrowRight): onPageForward,
|
||||
|
||||
// Backward navigation
|
||||
const SingleActivator(LogicalKeyboardKey.arrowUp): onPageBackward,
|
||||
const SingleActivator(LogicalKeyboardKey.arrowLeft): onPageBackward,
|
||||
};
|
||||
}
|
||||
}
|
||||
106
lib/shared/widgets/edit_sheet_bottom_sheet.dart
Normal file
106
lib/shared/widgets/edit_sheet_bottom_sheet.dart
Normal file
@@ -0,0 +1,106 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../core/models/sheet.dart';
|
||||
|
||||
/// Callback when sheet metadata is saved.
|
||||
typedef SheetEditCallback = void Function(String newName, String newComposer);
|
||||
|
||||
/// Bottom sheet for editing sheet metadata (name and composer).
|
||||
class EditSheetBottomSheet extends StatefulWidget {
|
||||
final Sheet sheet;
|
||||
final SheetEditCallback onSave;
|
||||
|
||||
const EditSheetBottomSheet({
|
||||
super.key,
|
||||
required this.sheet,
|
||||
required this.onSave,
|
||||
});
|
||||
|
||||
@override
|
||||
State<EditSheetBottomSheet> createState() => _EditSheetBottomSheetState();
|
||||
}
|
||||
|
||||
class _EditSheetBottomSheetState extends State<EditSheetBottomSheet> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _composerController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_nameController = TextEditingController(text: widget.sheet.name);
|
||||
_composerController = TextEditingController(
|
||||
text: widget.sheet.composerName,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_composerController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _handleSave() {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
|
||||
widget.onSave(_nameController.text.trim(), _composerController.text.trim());
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
String? _validateNotEmpty(String? value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return 'This field cannot be empty';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
16,
|
||||
16,
|
||||
16,
|
||||
MediaQuery.of(context).viewInsets.bottom + 16,
|
||||
),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
'Edit Sheet',
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
validator: _validateNotEmpty,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Sheet Name',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextFormField(
|
||||
controller: _composerController,
|
||||
validator: _validateNotEmpty,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Composer',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (_) => _handleSave(),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(onPressed: _handleSave, child: const Text('Save')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user