diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index c279a18..2e214c0 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -35,6 +35,8 @@ "camera": "Camera", "lightSensor": "Light sensor", "equipment": "Equipment", + "equipmentProfileName": "Equipment profile name", + "equipmentProfileNameHint": "Praktica MTL5B", "apertureValues": "Aperture values", "apertureValuesFilterDescription": "Select the range of aperture values to display. This is usually determined by the lens you are using.", "ndFilters": "ND filters", diff --git a/lib/providers/equipment_profile_provider.dart b/lib/providers/equipment_profile_provider.dart index a11c63b..5335dde 100644 --- a/lib/providers/equipment_profile_provider.dart +++ b/lib/providers/equipment_profile_provider.dart @@ -46,10 +46,10 @@ class EquipmentProfileProviderState extends State { } /// Creates a default equipment profile - void addProfile() { - _profiles.add(const EquipmentProfileData( + void addProfile(String name) { + _profiles.add(EquipmentProfileData( id: 'default', - name: '', + name: name, apertureValues: apertureValues, ndValues: ndValues, shutterSpeedValues: shutterSpeedValues, diff --git a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_name_dialog/widget_dialog_equipment_profile_name.dart b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_name_dialog/widget_dialog_equipment_profile_name.dart new file mode 100644 index 0000000..caf62bb --- /dev/null +++ b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_name_dialog/widget_dialog_equipment_profile_name.dart @@ -0,0 +1,45 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/generated/l10n.dart'; + +class EquipmentProfileNameDialog extends StatefulWidget { + const EquipmentProfileNameDialog({super.key}); + + @override + State createState() => _EquipmentProfileNameDialogState(); +} + +class _EquipmentProfileNameDialogState extends State { + final TextEditingController _nameController = TextEditingController(); + + @override + void dispose() { + _nameController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return AlertDialog( + title: Text(S.of(context).equipmentProfileName), + content: TextField( + controller: _nameController, + decoration: InputDecoration(hintText: S.of(context).equipmentProfileNameHint), + ), + actions: [ + TextButton( + onPressed: Navigator.of(context).pop, + child: Text(S.of(context).cancel), + ), + ValueListenableBuilder( + valueListenable: _nameController, + builder: (_, value, __) => TextButton( + onPressed: value.text.isNotEmpty + ? () => Navigator.of(context).pop(value.text.isNotEmpty) + : null, + child: Text(S.of(context).save), + ), + ), + ], + ); + } +} diff --git a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart index cedc5f6..be88b63 100644 --- a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart +++ b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart @@ -4,6 +4,7 @@ import 'package:lightmeter/providers/equipment_profile_provider.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'components/equipment_profile_container/widget_container_equipment_profile.dart'; +import 'components/equipment_profile_name_dialog/widget_dialog_equipment_profile_name.dart'; class EquipmentProfileScreen extends StatefulWidget { const EquipmentProfileScreen({super.key}); @@ -67,8 +68,13 @@ class _EquipmentProfileScreenState extends State { floatingActionButton: profilesCount < maxProfiles ? FloatingActionButton( onPressed: () { - EquipmentProfileProvider.of(context).addProfile(); - profileContainersKeys.add(GlobalKey()); + showDialog(context: context, builder: (_) => const EquipmentProfileNameDialog()) + .then((value) { + if (value != null) { + EquipmentProfileProvider.of(context).addProfile(value); + profileContainersKeys.add(GlobalKey()); + } + }); }, child: const Icon(Icons.add), )