Compare commits

...

4 commits

Author SHA1 Message Date
Vadim
dff3eefc4b migrated to iap 1.1.0 2024-10-31 17:17:31 +01:00
Vadim
02d81caa7d wait for the film to edited 2024-10-31 16:59:45 +01:00
Vadim
ca03de9abf autofocus film name field 2024-10-31 15:13:06 +01:00
Vadim
beeb67846a migrated to iap 1.0.1 2024-10-31 14:14:37 +01:00
7 changed files with 118 additions and 86 deletions

View file

@ -70,8 +70,9 @@ class FilmsProviderState extends State<FilmsProvider> {
/* Custom films **/ /* Custom films **/
Future<void> addCustomFilm(FilmExponential film) async { Future<void> addCustomFilm(FilmExponential film) async {
await widget.filmsStorageService.addFilm(film); // ignore: avoid_redundant_argument_values
customFilms[film.id] = (film: film, isUsed: false); await widget.filmsStorageService.addFilm(film, isUsed: true);
customFilms[film.id] = (film: film, isUsed: true);
setState(() {}); setState(() {});
} }

View file

@ -45,18 +45,18 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
), ),
) { ) {
on<FilmEditEvent>( on<FilmEditEvent>(
(event, emit) { (event, emit) async {
switch (event) { switch (event) {
case final FilmEditNameChangedEvent e: case final FilmEditNameChangedEvent e:
_onNameChanged(e, emit); await _onNameChanged(e, emit);
case final FilmEditIsoChangedEvent e: case final FilmEditIsoChangedEvent e:
_onIsoChanged(e, emit); await _onIsoChanged(e, emit);
case final FilmEditExpChangedEvent e: case final FilmEditExpChangedEvent e:
_onExpChanged(e, emit); await _onExpChanged(e, emit);
case FilmEditSaveEvent(): case FilmEditSaveEvent():
_onSave(event, emit); await _onSave(event, emit);
case FilmEditDeleteEvent(): case FilmEditDeleteEvent():
_onDelete(event, emit); await _onDelete(event, emit);
} }
}, },
); );
@ -65,10 +65,8 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
Future<void> _onNameChanged(FilmEditNameChangedEvent event, Emitter emit) async { Future<void> _onNameChanged(FilmEditNameChangedEvent event, Emitter emit) async {
_newFilm = _newFilm.copyWith(name: event.name); _newFilm = _newFilm.copyWith(name: event.name);
emit( emit(
FilmEditState( state.copyWith(
name: event.name, name: event.name,
isoValue: state.isoValue,
exponent: state.exponent,
canSave: _canSave(event.name, state.exponent), canSave: _canSave(event.name, state.exponent),
), ),
); );
@ -77,10 +75,8 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
Future<void> _onIsoChanged(FilmEditIsoChangedEvent event, Emitter emit) async { Future<void> _onIsoChanged(FilmEditIsoChangedEvent event, Emitter emit) async {
_newFilm = _newFilm.copyWith(iso: event.iso.value); _newFilm = _newFilm.copyWith(iso: event.iso.value);
emit( emit(
FilmEditState( state.copyWith(
name: state.name,
isoValue: event.iso, isoValue: event.iso,
exponent: state.exponent,
canSave: _canSave(state.name, state.exponent), canSave: _canSave(state.name, state.exponent),
), ),
); );
@ -101,8 +97,9 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
} }
Future<void> _onSave(FilmEditSaveEvent _, Emitter emit) async { Future<void> _onSave(FilmEditSaveEvent _, Emitter emit) async {
emit(state.copyWith(isLoading: true));
if (_isEdit) { if (_isEdit) {
filmsProvider.updateCustomFilm( await filmsProvider.updateCustomFilm(
FilmExponential( FilmExponential(
id: _originalFilm.id, id: _originalFilm.id,
name: state.name, name: state.name,
@ -111,7 +108,7 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
), ),
); );
} else { } else {
filmsProvider.addCustomFilm( await filmsProvider.addCustomFilm(
FilmExponential( FilmExponential(
id: const Uuid().v1(), id: const Uuid().v1(),
name: state.name, name: state.name,
@ -120,10 +117,13 @@ class FilmEditBloc extends Bloc<FilmEditEvent, FilmEditState> {
), ),
); );
} }
emit(state.copyWith(isLoading: false));
} }
Future<void> _onDelete(FilmEditDeleteEvent _, Emitter emit) async { Future<void> _onDelete(FilmEditDeleteEvent _, Emitter emit) async {
filmsProvider.deleteCustomFilm(_originalFilm); emit(state.copyWith(isLoading: true));
await filmsProvider.deleteCustomFilm(_originalFilm);
emit(state.copyWith(isLoading: false));
} }
bool _canSave(String name, double? exponent) { bool _canSave(String name, double? exponent) {

View file

@ -24,6 +24,7 @@ class FilmEditNameField extends StatelessWidget {
), ),
child: LightmeterTextField( child: LightmeterTextField(
initialValue: name, initialValue: name,
autofocus: true,
maxLength: 48, maxLength: 48,
hintText: S.of(context).name, hintText: S.of(context).name,
onChanged: onChanged, onChanged: onChanged,

View file

@ -25,7 +25,19 @@ class FilmEditScreen extends StatefulWidget {
class _FilmEditScreenState extends State<FilmEditScreen> { class _FilmEditScreenState extends State<FilmEditScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SliverScreen( return BlocConsumer<FilmEditBloc, FilmEditState>(
listenWhen: (previous, current) => previous.isLoading != current.isLoading,
listener: (context, state) {
if (state.isLoading) {
FocusScope.of(context).unfocus();
} else {
Navigator.of(context).pop();
}
},
buildWhen: (previous, current) => previous.isLoading != current.isLoading,
builder: (context, state) => IgnorePointer(
ignoring: state.isLoading,
child: SliverScreen(
title: Text(widget.isEdit ? S.of(context).editFilmTitle : S.of(context).addFilmTitle), title: Text(widget.isEdit ? S.of(context).editFilmTitle : S.of(context).addFilmTitle),
appBarActions: [ appBarActions: [
BlocBuilder<FilmEditBloc, FilmEditState>( BlocBuilder<FilmEditBloc, FilmEditState>(
@ -34,7 +46,6 @@ class _FilmEditScreenState extends State<FilmEditScreen> {
onPressed: state.canSave onPressed: state.canSave
? () { ? () {
context.read<FilmEditBloc>().add(const FilmEditSaveEvent()); context.read<FilmEditBloc>().add(const FilmEditSaveEvent());
Navigator.of(context).pop();
} }
: null, : null,
icon: const Icon(Icons.save), icon: const Icon(Icons.save),
@ -44,7 +55,6 @@ class _FilmEditScreenState extends State<FilmEditScreen> {
IconButton( IconButton(
onPressed: () { onPressed: () {
context.read<FilmEditBloc>().add(const FilmEditDeleteEvent()); context.read<FilmEditBloc>().add(const FilmEditDeleteEvent());
Navigator.of(context).pop();
}, },
icon: const Icon(Icons.delete), icon: const Icon(Icons.delete),
), ),
@ -61,6 +71,8 @@ class _FilmEditScreenState extends State<FilmEditScreen> {
child: Card( child: Card(
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(vertical: Dimens.paddingM), padding: const EdgeInsets.symmetric(vertical: Dimens.paddingM),
child: Opacity(
opacity: state.isLoading ? Dimens.disabledOpacity : Dimens.enabledOpacity,
child: Column( child: Column(
children: [ children: [
BlocBuilder<FilmEditBloc, FilmEditState>( BlocBuilder<FilmEditBloc, FilmEditState>(
@ -96,8 +108,11 @@ class _FilmEditScreenState extends State<FilmEditScreen> {
), ),
), ),
), ),
),
SliverToBoxAdapter(child: SizedBox(height: MediaQuery.paddingOf(context).bottom)), SliverToBoxAdapter(child: SizedBox(height: MediaQuery.paddingOf(context).bottom)),
], ],
),
),
); );
} }
} }

View file

@ -5,13 +5,28 @@ class FilmEditState {
final IsoValue isoValue; final IsoValue isoValue;
final double? exponent; final double? exponent;
final bool canSave; final bool canSave;
final FilmExponential? filmToSave; final bool isLoading;
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,
this.filmToSave, this.isLoading = false,
}); });
FilmEditState copyWith({
String? name,
IsoValue? isoValue,
double? exponent,
bool? canSave,
bool? isLoading,
}) =>
FilmEditState(
name: name ?? this.name,
isoValue: isoValue ?? this.isoValue,
exponent: exponent ?? this.exponent,
canSave: canSave ?? this.canSave,
isLoading: isLoading ?? this.isLoading,
);
} }

View file

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
class LightmeterTextField extends TextFormField { class LightmeterTextField extends TextFormField {
LightmeterTextField({ LightmeterTextField({
super.controller, super.controller,
super.focusNode, super.autofocus,
super.initialValue, super.initialValue,
super.inputFormatters, super.inputFormatters,
super.maxLength, super.maxLength,

View file

@ -30,7 +30,7 @@ dependencies:
m3_lightmeter_iap: m3_lightmeter_iap:
git: git:
url: "https://github.com/vodemn/m3_lightmeter_iap" url: "https://github.com/vodemn/m3_lightmeter_iap"
ref: v1.0.0 ref: v1.1.0
m3_lightmeter_resources: m3_lightmeter_resources:
git: git:
url: "https://github.com/vodemn/m3_lightmeter_resources" url: "https://github.com/vodemn/m3_lightmeter_resources"