From a6f319bf996531a5edb91b67526477884549c9a6 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:20:42 +0200 Subject: [PATCH] [`FilmEditScreen`] separated add and edit blocs --- lib/l10n/intl_en.arb | 3 +++ lib/screens/film_edit/bloc_film_edit.dart | 9 ++++++++- lib/screens/film_edit/flow_film_edit.dart | 4 ++-- lib/screens/film_edit/screen_film_edit.dart | 7 ++++--- lib/screens/film_edit/state_film_edit.dart | 2 ++ lib/screens/shared/text_field/widget_text_field.dart | 4 ++++ 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 2079426..6469a14 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -151,8 +151,11 @@ } }, "close": "Close", + "addFilmTitle": "Add film", + "editFilmTitle": "Edit film", "filmFormula": "Formula", "filmFormulaExponential": "T=t^Rf", "filmFormulaExponentialRf": "Rf", + "filmFormulaExponentialRfPlaceholder": "1.3", "name": "Name" } \ No newline at end of file diff --git a/lib/screens/film_edit/bloc_film_edit.dart b/lib/screens/film_edit/bloc_film_edit.dart index 1b72289..6fea9d0 100644 --- a/lib/screens/film_edit/bloc_film_edit.dart +++ b/lib/screens/film_edit/bloc_film_edit.dart @@ -4,10 +4,13 @@ import 'package:lightmeter/screens/film_edit/state_film_edit.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; class FilmEditBloc extends Bloc { + static const _defaultFilm = FilmExponential(name: '', iso: 100, exponent: 1.3); final FilmExponential _originalFilm; FilmExponential _newFilm; - FilmEditBloc(FilmExponential film) + factory FilmEditBloc(FilmExponential? film) => film != null ? FilmEditBloc._(film) : FilmEditBloc._(_defaultFilm); + + FilmEditBloc._(FilmExponential film) : _originalFilm = film, _newFilm = film, super( @@ -16,6 +19,7 @@ class FilmEditBloc extends Bloc { isoValue: IsoValue.values.firstWhere((element) => element.value == film.iso), exponent: film.exponent, canSave: false, + isEdit: film != _defaultFilm, ), ) { on( @@ -42,6 +46,7 @@ class FilmEditBloc extends Bloc { isoValue: state.isoValue, exponent: state.exponent, canSave: _canSave(event.name, state.exponent), + isEdit: state.isEdit, ), ); } @@ -54,6 +59,7 @@ class FilmEditBloc extends Bloc { isoValue: event.iso, exponent: state.exponent, canSave: _canSave(state.name, state.exponent), + isEdit: state.isEdit, ), ); } @@ -68,6 +74,7 @@ class FilmEditBloc extends Bloc { isoValue: state.isoValue, exponent: event.exponent, canSave: _canSave(state.name, event.exponent), + isEdit: state.isEdit, ), ); } diff --git a/lib/screens/film_edit/flow_film_edit.dart b/lib/screens/film_edit/flow_film_edit.dart index 38d09ed..60876a2 100644 --- a/lib/screens/film_edit/flow_film_edit.dart +++ b/lib/screens/film_edit/flow_film_edit.dart @@ -5,9 +5,9 @@ import 'package:lightmeter/screens/film_edit/screen_film_edit.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; class FilmEditFlow extends StatelessWidget { - final FilmExponential film; + final FilmExponential? film; - const FilmEditFlow(this.film, {super.key}); + const FilmEditFlow({this.film, super.key}); @override Widget build(BuildContext context) { diff --git a/lib/screens/film_edit/screen_film_edit.dart b/lib/screens/film_edit/screen_film_edit.dart index 6c881d9..8666297 100644 --- a/lib/screens/film_edit/screen_film_edit.dart +++ b/lib/screens/film_edit/screen_film_edit.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/res/dimens.dart'; @@ -24,8 +23,8 @@ class _FilmEditScreenState extends State { Widget build(BuildContext context) { return SliverScreen( title: BlocBuilder( - buildWhen: (previous, current) => previous.name != current.name, - builder: (_, state) => Text(state.name), + buildWhen: (previous, current) => false, + builder: (context, state) => Text(state.isEdit ? S.of(context).editFilmTitle : S.of(context).addFilmTitle), ), appBarActions: [ BlocBuilder( @@ -97,6 +96,8 @@ class _NameFieldBuilder extends StatelessWidget { buildWhen: (previous, current) => previous.name != current.name, builder: (context, state) => LightmeterTextField( initialValue: state.name, + maxLength: 48, + hintText: S.of(context).name, onChanged: (value) { context.read().add(FilmEditNameChangedEvent(value)); }, diff --git a/lib/screens/film_edit/state_film_edit.dart b/lib/screens/film_edit/state_film_edit.dart index b811160..2db7b79 100644 --- a/lib/screens/film_edit/state_film_edit.dart +++ b/lib/screens/film_edit/state_film_edit.dart @@ -5,11 +5,13 @@ class FilmEditState { final IsoValue isoValue; final double? exponent; final bool canSave; + final bool isEdit; const FilmEditState({ required this.name, required this.isoValue, required this.exponent, required this.canSave, + required this.isEdit, }); } diff --git a/lib/screens/shared/text_field/widget_text_field.dart b/lib/screens/shared/text_field/widget_text_field.dart index d9523d8..ead1f14 100644 --- a/lib/screens/shared/text_field/widget_text_field.dart +++ b/lib/screens/shared/text_field/widget_text_field.dart @@ -6,17 +6,21 @@ class LightmeterTextField extends TextFormField { super.focusNode, super.initialValue, super.inputFormatters, + super.maxLength, super.onChanged, super.style, super.textAlign, Widget? leading, + String? hintText, }) : super( autovalidateMode: AutovalidateMode.onUserInteraction, maxLines: 1, decoration: InputDecoration( + counter: const SizedBox(), contentPadding: EdgeInsets.zero, errorStyle: const TextStyle(fontSize: 0), icon: leading, + hintText: hintText, ), validator: (value) { if (value == null || value.isEmpty) {