diff --git a/lib/domain/entities/settings.dart b/lib/domain/entities/settings.dart index 5e8f466..7e83ebd 100644 --- a/lib/domain/entities/settings.dart +++ b/lib/domain/entities/settings.dart @@ -12,6 +12,7 @@ class Settings { /// Band pass low cut final double bandPassLowCutOff; + /// Copy with method Settings copyWith({ double? bandPassHighCutOff, double? bandPassLowCutOff, diff --git a/lib/presentation/widgets/settings_dialog.dart b/lib/presentation/widgets/settings_dialog.dart index 66b273d..6ddfbf6 100644 --- a/lib/presentation/widgets/settings_dialog.dart +++ b/lib/presentation/widgets/settings_dialog.dart @@ -14,73 +14,77 @@ class SettingsDialog extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final settings = ref.watch(settingsNotifierProvider); final settingsNotifier = ref.read(settingsNotifierProvider.notifier); - return settings.when(data: (data) { - _bandPassHighCutOffController.text = data.bandPassHighCutOff.toString(); - _bandPassLowCutOffController.text = data.bandPassLowCutOff.toString(); - return AlertDialog( - title: const Text('Settings'), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - TextField( - controller: _bandPassHighCutOffController, - decoration: const InputDecoration( - labelText: 'Band Pass High Cut Off', + return settings.when( + data: (data) { + _bandPassHighCutOffController.text = data.bandPassHighCutOff.toString(); + _bandPassLowCutOffController.text = data.bandPassLowCutOff.toString(); + return AlertDialog( + title: const Text('Settings'), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextField( + controller: _bandPassHighCutOffController, + decoration: const InputDecoration( + labelText: 'Band Pass High Cut Off', + ), + keyboardType: TextInputType.number, ), - keyboardType: TextInputType.number, - ), - TextField( - controller: _bandPassLowCutOffController, - decoration: const InputDecoration( - labelText: 'Band Pass Low Cut Off', + TextField( + controller: _bandPassLowCutOffController, + decoration: const InputDecoration( + labelText: 'Band Pass Low Cut Off', + ), + keyboardType: TextInputType.number, ), - keyboardType: TextInputType.number, + ], + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('Cancel'), + ), + TextButton( + onPressed: () async { + final newSettings = data.copyWith( + bandPassHighCutOff: + double.tryParse(_bandPassHighCutOffController.text), + bandPassLowCutOff: + double.tryParse(_bandPassLowCutOffController.text), + ); + final result = await settingsNotifier.saveSettings(newSettings); + result.fold( + (failure) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(failure.message), + ), + ); + }, + (_) { + Navigator.of(context).pop(); + }, + ); + }, + child: const Text('Confirm'), ), ], - ), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: const Text('Cancel'), - ), - TextButton( - onPressed: () async { - final newSettings = data.copyWith( - bandPassHighCutOff: - double.tryParse(_bandPassHighCutOffController.text), - bandPassLowCutOff: - double.tryParse(_bandPassLowCutOffController.text), - ); - final result = await settingsNotifier.saveSettings(newSettings); - result.fold( - (failure) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(failure.message), - ), - ); - }, - (_) { - Navigator.of(context).pop(); - }, - ); - }, - child: const Text('Confirm'), - ), - ], - ); - }, error: (e, s) { - return AlertDialog( - title: const Text('Error'), - content: Text(e.toString()), - ); - }, loading: () { - return const AlertDialog( - title: Text('Loading'), - content: Center(child: CircularProgressIndicator()), - ); - }); + ); + }, + error: (e, s) { + return AlertDialog( + title: const Text('Error'), + content: Text(e.toString()), + ); + }, + loading: () { + return const AlertDialog( + title: Text('Loading'), + content: Center(child: CircularProgressIndicator()), + ); + }, + ); } }