From b7f03050558485ecde2c86fecfc75448a99a80c1 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:22:25 +0200 Subject: [PATCH] [`FilmEditScreen`] wip --- lib/screens/film_edit/bloc_film_edit.dart | 44 +++++++++ lib/screens/film_edit/event_film_edit.dart | 27 +++++ lib/screens/film_edit/flow_film_edit.dart | 19 ++++ lib/screens/film_edit/screen_film_edit.dart | 104 ++++++++++++++++++++ lib/screens/film_edit/state_film_edit.dart | 8 ++ 5 files changed, 202 insertions(+) create mode 100644 lib/screens/film_edit/bloc_film_edit.dart create mode 100644 lib/screens/film_edit/event_film_edit.dart create mode 100644 lib/screens/film_edit/flow_film_edit.dart create mode 100644 lib/screens/film_edit/screen_film_edit.dart create mode 100644 lib/screens/film_edit/state_film_edit.dart diff --git a/lib/screens/film_edit/bloc_film_edit.dart b/lib/screens/film_edit/bloc_film_edit.dart new file mode 100644 index 0000000..16fd2e5 --- /dev/null +++ b/lib/screens/film_edit/bloc_film_edit.dart @@ -0,0 +1,44 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:lightmeter/screens/film_edit/event_film_edit.dart'; +import 'package:lightmeter/screens/film_edit/state_film_edit.dart'; +import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; + +class FilmEditBloc extends Bloc { + FilmEditBloc(FilmExponential film) + : super( + FilmEditState( + film, + IsoValue.values.firstWhere((element) => element.value == film.iso), + ), + ) { + on( + (event, emit) { + switch (event) { + case final FilmEditNameChangedEvent e: + _onNameChanged(e, emit); + case final FilmEditIsoChangedEvent e: + _onIsoChanged(e, emit); + case final FilmEditExpChangedEvent e: + _onExpChanged(e, emit); + case FilmEditSaveEvent(): + _onSave(event, emit); + } + }, + ); + } + + Future _onNameChanged(FilmEditNameChangedEvent event, Emitter emit) async {} + + Future _onIsoChanged(FilmEditIsoChangedEvent event, Emitter emit) async { + emit( + FilmEditState( + state.film.copyWith(iso: event.iso.value), + event.iso, + ), + ); + } + + Future _onExpChanged(FilmEditExpChangedEvent event, Emitter emit) async {} + + Future _onSave(FilmEditSaveEvent _, Emitter emit) async {} +} diff --git a/lib/screens/film_edit/event_film_edit.dart b/lib/screens/film_edit/event_film_edit.dart new file mode 100644 index 0000000..c469451 --- /dev/null +++ b/lib/screens/film_edit/event_film_edit.dart @@ -0,0 +1,27 @@ +import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; + +sealed class FilmEditEvent { + const FilmEditEvent(); +} + +class FilmEditNameChangedEvent extends FilmEditEvent { + final String name; + + const FilmEditNameChangedEvent(this.name); +} + +class FilmEditIsoChangedEvent extends FilmEditEvent { + final IsoValue iso; + + const FilmEditIsoChangedEvent(this.iso); +} + +class FilmEditExpChangedEvent extends FilmEditEvent { + final double exp; + + const FilmEditExpChangedEvent(this.exp); +} + +class FilmEditSaveEvent extends FilmEditEvent { + const FilmEditSaveEvent(); +} diff --git a/lib/screens/film_edit/flow_film_edit.dart b/lib/screens/film_edit/flow_film_edit.dart new file mode 100644 index 0000000..38d09ed --- /dev/null +++ b/lib/screens/film_edit/flow_film_edit.dart @@ -0,0 +1,19 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:lightmeter/screens/film_edit/bloc_film_edit.dart'; +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; + + const FilmEditFlow(this.film, {super.key}); + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (_) => FilmEditBloc(film), + child: const FilmEditScreen(), + ); + } +} diff --git a/lib/screens/film_edit/screen_film_edit.dart b/lib/screens/film_edit/screen_film_edit.dart new file mode 100644 index 0000000..9ce089f --- /dev/null +++ b/lib/screens/film_edit/screen_film_edit.dart @@ -0,0 +1,104 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/screens/film_edit/bloc_film_edit.dart'; +import 'package:lightmeter/screens/film_edit/event_film_edit.dart'; +import 'package:lightmeter/screens/film_edit/state_film_edit.dart'; +import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart'; +import 'package:lightmeter/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart'; +import 'package:lightmeter/screens/settings/components/shared/expandable_section_list/widget_expandable_section_list.dart'; +import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart'; +import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; + +class FilmEditScreen extends StatefulWidget { + const FilmEditScreen({super.key}); + + @override + State createState() => _FilmEditScreenState(); +} + +class _FilmEditScreenState extends State { + @override + Widget build(BuildContext context) { + return SliverScreen( + title: BlocBuilder( + buildWhen: (previous, current) => previous.film.name != current.film.name, + builder: (context, state) => TextFormField( + initialValue: state.film.name, + onChanged: (value) {}, + ), + ), + appBarActions: [ + IconButton( + onPressed: () {}, + icon: const Icon(Icons.save), + ), + ], + slivers: [ + SliverToBoxAdapter( + child: BlocBuilder( + buildWhen: (previous, current) => previous.isoValue != current.isoValue, + builder: (context, state) => _IsoPickerListTile( + selected: state.isoValue, + onChanged: (value) { + context.read().add(FilmEditIsoChangedEvent(value)); + }, + ), + ), + ), + SliverToBoxAdapter( + child: BlocBuilder( + buildWhen: (previous, current) => previous.film.exponent != current.film.exponent, + builder: (context, state) => ListTile( + leading: const Icon(Icons.equalizer), + title: Text('Formula'), + trailing: Text(state.film.exponent.toString()), + ), + ), + ), + SliverToBoxAdapter(child: SizedBox(height: MediaQuery.paddingOf(context).bottom)), + ], + ); + } +} + +class _IsoPickerListTile extends StatelessWidget { + final IsoValue selected; + final ValueChanged onChanged; + + const _IsoPickerListTile({ + required this.selected, + required this.onChanged, + }); + + @override + Widget build(BuildContext context) { + return ListTile( + leading: const Icon(Icons.iso), + title: Text(S.of(context).iso), + trailing: Text(selected.value.toString()), + onTap: () { + showDialog( + context: context, + builder: (_) => Dialog( + child: DialogPicker( + icon: Icons.iso, + title: S.of(context).iso, + subtitle: S.of(context).filmSpeed, + values: IsoValue.values, + initialValue: selected, + itemTitleBuilder: (_, value) => Text(value.value.toString()), + onSelect: (value) { + onChanged(value); + Navigator.of(context).pop(); + }, + onCancel: () { + Navigator.of(context).pop(); + }, + ), + ), + ); + }, + ); + } +} diff --git a/lib/screens/film_edit/state_film_edit.dart b/lib/screens/film_edit/state_film_edit.dart new file mode 100644 index 0000000..0fac707 --- /dev/null +++ b/lib/screens/film_edit/state_film_edit.dart @@ -0,0 +1,8 @@ +import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; + +class FilmEditState { + final FilmExponential film; + final IsoValue isoValue; + + const FilmEditState(this.film, this.isoValue); +}