m3_lightmeter/lib/screens/film_edit/screen_film_edit.dart

104 lines
4 KiB
Dart
Raw Normal View History

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