mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 15:30:59 +00:00
change equipment profile name via dialog
This commit is contained in:
parent
b6a7f68b5c
commit
1b52b1abf5
2 changed files with 47 additions and 68 deletions
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
|
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_name_dialog/widget_dialog_equipment_profile_name.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
import 'components/equipment_list_tiles/widget_list_tiles_equipments.dart';
|
import 'components/equipment_list_tiles/widget_list_tiles_equipments.dart';
|
||||||
|
@ -25,7 +25,7 @@ class EquipmentProfileContainer extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class EquipmentProfileContainerState extends State<EquipmentProfileContainer> {
|
class EquipmentProfileContainerState extends State<EquipmentProfileContainer> {
|
||||||
late EquipmentProfileData _equipmentProfileData = EquipmentProfileData(
|
late EquipmentProfileData _equipmentData = EquipmentProfileData(
|
||||||
id: widget.data.id,
|
id: widget.data.id,
|
||||||
name: widget.data.name,
|
name: widget.data.name,
|
||||||
apertureValues: widget.data.apertureValues,
|
apertureValues: widget.data.apertureValues,
|
||||||
|
@ -33,14 +33,12 @@ class EquipmentProfileContainerState extends State<EquipmentProfileContainer> {
|
||||||
shutterSpeedValues: widget.data.shutterSpeedValues,
|
shutterSpeedValues: widget.data.shutterSpeedValues,
|
||||||
isoValues: widget.data.isoValues,
|
isoValues: widget.data.isoValues,
|
||||||
);
|
);
|
||||||
late final _nameController = TextEditingController(text: _equipmentProfileData.name);
|
|
||||||
final _fieldFocusNode = FocusNode();
|
|
||||||
bool _expanded = false;
|
bool _expanded = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didUpdateWidget(EquipmentProfileContainer oldWidget) {
|
void didUpdateWidget(EquipmentProfileContainer oldWidget) {
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
_equipmentProfileData = EquipmentProfileData(
|
_equipmentData = EquipmentProfileData(
|
||||||
id: widget.data.id,
|
id: widget.data.id,
|
||||||
name: widget.data.name,
|
name: widget.data.name,
|
||||||
apertureValues: widget.data.apertureValues,
|
apertureValues: widget.data.apertureValues,
|
||||||
|
@ -50,13 +48,6 @@ class EquipmentProfileContainerState extends State<EquipmentProfileContainer> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_nameController.dispose();
|
|
||||||
_fieldFocusNode.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Card(
|
return Card(
|
||||||
|
@ -66,70 +57,59 @@ class EquipmentProfileContainerState extends State<EquipmentProfileContainer> {
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
ListTile(
|
||||||
children: [
|
title: Text(
|
||||||
Expanded(
|
_equipmentData.name,
|
||||||
child: Padding(
|
maxLines: 1,
|
||||||
padding: const EdgeInsets.fromLTRB(
|
overflow: TextOverflow.ellipsis,
|
||||||
Dimens.paddingM,
|
),
|
||||||
0,
|
trailing: Row(
|
||||||
Dimens.paddingM,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
0,
|
mainAxisSize: MainAxisSize.min,
|
||||||
),
|
children: [
|
||||||
child: IgnorePointer(
|
_collapseButton(),
|
||||||
ignoring: !_expanded,
|
IconButton(
|
||||||
child: TextFormField(
|
onPressed: widget.onDelete,
|
||||||
focusNode: _fieldFocusNode,
|
icon: const Icon(Icons.delete),
|
||||||
controller: _nameController,
|
|
||||||
onFieldSubmitted: (value) {
|
|
||||||
_equipmentProfileData = _equipmentProfileData.copyWith(name: value);
|
|
||||||
widget.onUpdate(_equipmentProfileData);
|
|
||||||
},
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: S.of(context).equipmentProfileNameHint,
|
|
||||||
border: InputBorder.none,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
Row(
|
),
|
||||||
children: [
|
onTap: () {
|
||||||
_collapseButton(),
|
showDialog<String>(
|
||||||
IconButton(
|
context: context,
|
||||||
onPressed: widget.onDelete,
|
builder: (_) => EquipmentProfileNameDialog(initialValue: _equipmentData.name),
|
||||||
icon: const Icon(Icons.delete),
|
).then((value) {
|
||||||
),
|
if (value != null) {
|
||||||
],
|
_equipmentData = _equipmentData.copyWith(name: value);
|
||||||
),
|
widget.onUpdate(_equipmentData);
|
||||||
],
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
AnimatedSize(
|
AnimatedSize(
|
||||||
alignment: Alignment.topCenter,
|
alignment: Alignment.topCenter,
|
||||||
duration: Dimens.durationM,
|
duration: Dimens.durationM,
|
||||||
child: _expanded
|
child: _expanded
|
||||||
? EquipmentListTiles(
|
? EquipmentListTiles(
|
||||||
selectedApertureValues: _equipmentProfileData.apertureValues,
|
selectedApertureValues: _equipmentData.apertureValues,
|
||||||
selectedIsoValues: _equipmentProfileData.isoValues,
|
selectedIsoValues: _equipmentData.isoValues,
|
||||||
selectedNdValues: _equipmentProfileData.ndValues,
|
selectedNdValues: _equipmentData.ndValues,
|
||||||
selectedShutterSpeedValues: _equipmentProfileData.shutterSpeedValues,
|
selectedShutterSpeedValues: _equipmentData.shutterSpeedValues,
|
||||||
onApertureValuesSelected: (value) {
|
onApertureValuesSelected: (value) {
|
||||||
_equipmentProfileData =
|
_equipmentData = _equipmentData.copyWith(apertureValues: value);
|
||||||
_equipmentProfileData.copyWith(apertureValues: value);
|
widget.onUpdate(_equipmentData);
|
||||||
widget.onUpdate(_equipmentProfileData);
|
|
||||||
},
|
},
|
||||||
onIsoValuesSelecred: (value) {
|
onIsoValuesSelecred: (value) {
|
||||||
_equipmentProfileData = _equipmentProfileData.copyWith(isoValues: value);
|
_equipmentData = _equipmentData.copyWith(isoValues: value);
|
||||||
widget.onUpdate(_equipmentProfileData);
|
widget.onUpdate(_equipmentData);
|
||||||
},
|
},
|
||||||
onNdValuesSelected: (value) {
|
onNdValuesSelected: (value) {
|
||||||
_equipmentProfileData = _equipmentProfileData.copyWith(ndValues: value);
|
_equipmentData = _equipmentData.copyWith(ndValues: value);
|
||||||
widget.onUpdate(_equipmentProfileData);
|
widget.onUpdate(_equipmentData);
|
||||||
},
|
},
|
||||||
onShutterSpeedValuesSelected: (value) {
|
onShutterSpeedValuesSelected: (value) {
|
||||||
_equipmentProfileData =
|
_equipmentData = _equipmentData.copyWith(shutterSpeedValues: value);
|
||||||
_equipmentProfileData.copyWith(shutterSpeedValues: value);
|
widget.onUpdate(_equipmentData);
|
||||||
widget.onUpdate(_equipmentProfileData);
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
: Row(mainAxisSize: MainAxisSize.max),
|
: Row(mainAxisSize: MainAxisSize.max),
|
||||||
|
@ -164,6 +144,5 @@ class EquipmentProfileContainerState extends State<EquipmentProfileContainer> {
|
||||||
setState(() {
|
setState(() {
|
||||||
_expanded = false;
|
_expanded = false;
|
||||||
});
|
});
|
||||||
_fieldFocusNode.unfocus();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,16 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
|
|
||||||
class EquipmentProfileNameDialog extends StatefulWidget {
|
class EquipmentProfileNameDialog extends StatefulWidget {
|
||||||
const EquipmentProfileNameDialog({super.key});
|
final String initialValue;
|
||||||
|
|
||||||
|
const EquipmentProfileNameDialog({this.initialValue = '', super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<EquipmentProfileNameDialog> createState() => _EquipmentProfileNameDialogState();
|
State<EquipmentProfileNameDialog> createState() => _EquipmentProfileNameDialogState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _EquipmentProfileNameDialogState extends State<EquipmentProfileNameDialog> {
|
class _EquipmentProfileNameDialogState extends State<EquipmentProfileNameDialog> {
|
||||||
final TextEditingController _nameController = TextEditingController();
|
late final _nameController = TextEditingController(text: widget.initialValue);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
@ -33,9 +35,7 @@ class _EquipmentProfileNameDialogState extends State<EquipmentProfileNameDialog>
|
||||||
ValueListenableBuilder(
|
ValueListenableBuilder(
|
||||||
valueListenable: _nameController,
|
valueListenable: _nameController,
|
||||||
builder: (_, value, __) => TextButton(
|
builder: (_, value, __) => TextButton(
|
||||||
onPressed: value.text.isNotEmpty
|
onPressed: value.text.isNotEmpty ? () => Navigator.of(context).pop(value.text) : null,
|
||||||
? () => Navigator.of(context).pop(value.text)
|
|
||||||
: null,
|
|
||||||
child: Text(S.of(context).save),
|
child: Text(S.of(context).save),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue