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",
|
"close": "Close",
|
||||||
|
"addFilmTitle": "Add film",
|
||||||
|
"editFilmTitle": "Edit film",
|
||||||
"filmFormula": "Formula",
|
"filmFormula": "Formula",
|
||||||
"filmFormulaExponential": "T=t^Rf",
|
"filmFormulaExponential": "T=t^Rf",
|
||||||
"filmFormulaExponentialRf": "Rf",
|
"filmFormulaExponentialRf": "Rf",
|
||||||
|
"filmFormulaExponentialRfPlaceholder": "1.3",
|
||||||
"name": "Name"
|
"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';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
|
class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
|
||||||
|
static const _defaultFilm = FilmExponential(name: '', iso: 100, exponent: 1.3);
|
||||||
final FilmExponential _originalFilm;
|
final FilmExponential _originalFilm;
|
||||||
FilmExponential _newFilm;
|
FilmExponential _newFilm;
|
||||||
|
|
||||||
FilmEditBloc(FilmExponential film)
|
factory FilmEditBloc(FilmExponential? film) => film != null ? FilmEditBloc._(film) : FilmEditBloc._(_defaultFilm);
|
||||||
|
|
||||||
|
FilmEditBloc._(FilmExponential film)
|
||||||
: _originalFilm = film,
|
: _originalFilm = film,
|
||||||
_newFilm = film,
|
_newFilm = film,
|
||||||
super(
|
super(
|
||||||
|
@ -16,6 +19,7 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
|
||||||
isoValue: IsoValue.values.firstWhere((element) => element.value == film.iso),
|
isoValue: IsoValue.values.firstWhere((element) => element.value == film.iso),
|
||||||
exponent: film.exponent,
|
exponent: film.exponent,
|
||||||
canSave: false,
|
canSave: false,
|
||||||
|
isEdit: film != _defaultFilm,
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
on<FilmEditEvent>(
|
on<FilmEditEvent>(
|
||||||
|
@ -42,6 +46,7 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
|
||||||
isoValue: state.isoValue,
|
isoValue: state.isoValue,
|
||||||
exponent: state.exponent,
|
exponent: state.exponent,
|
||||||
canSave: _canSave(event.name, state.exponent),
|
canSave: _canSave(event.name, state.exponent),
|
||||||
|
isEdit: state.isEdit,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -54,6 +59,7 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
|
||||||
isoValue: event.iso,
|
isoValue: event.iso,
|
||||||
exponent: state.exponent,
|
exponent: state.exponent,
|
||||||
canSave: _canSave(state.name, state.exponent),
|
canSave: _canSave(state.name, state.exponent),
|
||||||
|
isEdit: state.isEdit,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -68,6 +74,7 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
|
||||||
isoValue: state.isoValue,
|
isoValue: state.isoValue,
|
||||||
exponent: event.exponent,
|
exponent: event.exponent,
|
||||||
canSave: _canSave(state.name, 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';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class FilmEditFlow extends StatelessWidget {
|
class FilmEditFlow extends StatelessWidget {
|
||||||
final FilmExponential film;
|
final FilmExponential? film;
|
||||||
|
|
||||||
const FilmEditFlow(this.film, {super.key});
|
const FilmEditFlow({this.film, super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
|
@ -24,8 +23,8 @@ class _FilmEditScreenState extends State<FilmEditScreen> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SliverScreen(
|
return SliverScreen(
|
||||||
title: BlocBuilder<FilmEditBloc, FilmEditState>(
|
title: BlocBuilder<FilmEditBloc, FilmEditState>(
|
||||||
buildWhen: (previous, current) => previous.name != current.name,
|
buildWhen: (previous, current) => false,
|
||||||
builder: (_, state) => Text(state.name),
|
builder: (context, state) => Text(state.isEdit ? S.of(context).editFilmTitle : S.of(context).addFilmTitle),
|
||||||
),
|
),
|
||||||
appBarActions: [
|
appBarActions: [
|
||||||
BlocBuilder<FilmEditBloc, FilmEditState>(
|
BlocBuilder<FilmEditBloc, FilmEditState>(
|
||||||
|
@ -97,6 +96,8 @@ class _NameFieldBuilder extends StatelessWidget {
|
||||||
buildWhen: (previous, current) => previous.name != current.name,
|
buildWhen: (previous, current) => previous.name != current.name,
|
||||||
builder: (context, state) => LightmeterTextField(
|
builder: (context, state) => LightmeterTextField(
|
||||||
initialValue: state.name,
|
initialValue: state.name,
|
||||||
|
maxLength: 48,
|
||||||
|
hintText: S.of(context).name,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
context.read<FilmEditBloc>().add(FilmEditNameChangedEvent(value));
|
context.read<FilmEditBloc>().add(FilmEditNameChangedEvent(value));
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,11 +5,13 @@ class FilmEditState {
|
||||||
final IsoValue isoValue;
|
final IsoValue isoValue;
|
||||||
final double? exponent;
|
final double? exponent;
|
||||||
final bool canSave;
|
final bool canSave;
|
||||||
|
final bool isEdit;
|
||||||
|
|
||||||
const FilmEditState({
|
const FilmEditState({
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.isoValue,
|
required this.isoValue,
|
||||||
required this.exponent,
|
required this.exponent,
|
||||||
required this.canSave,
|
required this.canSave,
|
||||||
|
required this.isEdit,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,21 @@ class LightmeterTextField extends TextFormField {
|
||||||
super.focusNode,
|
super.focusNode,
|
||||||
super.initialValue,
|
super.initialValue,
|
||||||
super.inputFormatters,
|
super.inputFormatters,
|
||||||
|
super.maxLength,
|
||||||
super.onChanged,
|
super.onChanged,
|
||||||
super.style,
|
super.style,
|
||||||
super.textAlign,
|
super.textAlign,
|
||||||
Widget? leading,
|
Widget? leading,
|
||||||
|
String? hintText,
|
||||||
}) : super(
|
}) : super(
|
||||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
|
counter: const SizedBox(),
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
errorStyle: const TextStyle(fontSize: 0),
|
errorStyle: const TextStyle(fontSize: 0),
|
||||||
icon: leading,
|
icon: leading,
|
||||||
|
hintText: hintText,
|
||||||
),
|
),
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
|
|
Loading…
Reference in a new issue