mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-24 08:20:40 +00:00
[FilmEditScreen
] separated add and edit blocs
This commit is contained in:
parent
e781bb38ac
commit
a6f319bf99
6 changed files with 23 additions and 6 deletions
|
@ -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"
|
||||
}
|
|
@ -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<FilmEditEvent, FilmEditState> {
|
||||
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<FilmEditEvent, FilmEditState> {
|
|||
isoValue: IsoValue.values.firstWhere((element) => element.value == film.iso),
|
||||
exponent: film.exponent,
|
||||
canSave: false,
|
||||
isEdit: film != _defaultFilm,
|
||||
),
|
||||
) {
|
||||
on<FilmEditEvent>(
|
||||
|
@ -42,6 +46,7 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
|
|||
isoValue: state.isoValue,
|
||||
exponent: state.exponent,
|
||||
canSave: _canSave(event.name, state.exponent),
|
||||
isEdit: state.isEdit,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -54,6 +59,7 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
|
|||
isoValue: event.iso,
|
||||
exponent: state.exponent,
|
||||
canSave: _canSave(state.name, state.exponent),
|
||||
isEdit: state.isEdit,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -68,6 +74,7 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
|
|||
isoValue: state.isoValue,
|
||||
exponent: event.exponent,
|
||||
canSave: _canSave(state.name, event.exponent),
|
||||
isEdit: state.isEdit,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<FilmEditScreen> {
|
|||
Widget build(BuildContext context) {
|
||||
return SliverScreen(
|
||||
title: BlocBuilder<FilmEditBloc, FilmEditState>(
|
||||
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<FilmEditBloc, FilmEditState>(
|
||||
|
@ -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<FilmEditBloc>().add(FilmEditNameChangedEvent(value));
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue