import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/screens/film_edit/bloc_film_edit.dart'; import 'package:lightmeter/screens/film_edit/components/exponential_formula_input/widget_input_exponential_formula_film_edit.dart'; import 'package:lightmeter/screens/film_edit/components/iso_picker/widget_picker_iso_film_edit.dart'; import 'package:lightmeter/screens/film_edit/components/name_field/widget_field_name_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/shared/sliver_screen/screen_sliver.dart'; class FilmEditScreen extends StatefulWidget { final bool isEdit; const FilmEditScreen({ required this.isEdit, super.key, }); @override State createState() => _FilmEditScreenState(); } class _FilmEditScreenState extends State { @override Widget build(BuildContext context) { return SliverScreen( title: Text(widget.isEdit ? S.of(context).editFilmTitle : S.of(context).addFilmTitle), appBarActions: [ BlocBuilder( buildWhen: (previous, current) => previous.canSave != current.canSave, builder: (context, state) => IconButton( onPressed: state.canSave ? () { context.read().add(const FilmEditSaveEvent()); Navigator.of(context).pop(); } : null, icon: const Icon(Icons.save), ), ), if (widget.isEdit) IconButton( onPressed: () { context.read().add(const FilmEditDeleteEvent()); Navigator.of(context).pop(); }, icon: const Icon(Icons.delete), ), ], slivers: [ SliverToBoxAdapter( child: Padding( padding: const EdgeInsets.fromLTRB( Dimens.paddingM, 0, Dimens.paddingM, Dimens.paddingM, ), child: Card( child: Padding( padding: const EdgeInsets.symmetric(vertical: Dimens.paddingM), child: Column( children: [ BlocBuilder( buildWhen: (previous, current) => previous.name != current.name, builder: (context, state) => FilmEditNameField( name: state.name, onChanged: (value) { context.read().add(FilmEditNameChangedEvent(value)); }, ), ), BlocBuilder( buildWhen: (previous, current) => previous.isoValue != current.isoValue, builder: (context, state) => FilmEditIsoPicker( selected: state.isoValue, onChanged: (value) { context.read().add(FilmEditIsoChangedEvent(value)); }, ), ), BlocBuilder( buildWhen: (previous, current) => previous.exponent != current.exponent, builder: (context, state) => FilmEditExponentialFormulaInput( value: state.exponent, onChanged: (value) { context.read().add(FilmEditExpChangedEvent(value)); }, ), ), ], ), ), ), ), ), SliverToBoxAdapter(child: SizedBox(height: MediaQuery.paddingOf(context).bottom)), ], ); } }