From 0243598553307eef4d7b0618503e8b1f82be93a3 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:33:37 +0200 Subject: [PATCH] added films screen to navigation --- lib/application.dart | 7 + lib/l10n/intl_en.arb | 6 +- lib/screens/film_edit/flow_film_edit.dart | 14 +- lib/screens/films/screen_films.dart | 55 ++++-- .../components/widget_formula_input.dart | 166 ------------------ .../films/widget_list_tile_films.dart | 23 +-- 6 files changed, 63 insertions(+), 208 deletions(-) delete mode 100644 lib/screens/settings/components/metering/components/films/components/widget_formula_input.dart diff --git a/lib/application.dart b/lib/application.dart index b8939e4..94f4750 100644 --- a/lib/application.dart +++ b/lib/application.dart @@ -5,11 +5,16 @@ import 'package:lightmeter/data/models/supported_locale.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/platform_config.dart'; import 'package:lightmeter/providers/user_preferences_provider.dart'; +import 'package:lightmeter/screens/film_edit/flow_film_edit.dart'; +import 'package:lightmeter/screens/film_edit/screen_film_edit.dart'; +import 'package:lightmeter/screens/films/screen_films.dart'; import 'package:lightmeter/screens/lightmeter_pro/screen_lightmeter_pro.dart'; import 'package:lightmeter/screens/metering/flow_metering.dart'; import 'package:lightmeter/screens/settings/flow_settings.dart'; import 'package:lightmeter/screens/shared/release_notes_dialog/flow_dialog_release_notes.dart'; import 'package:lightmeter/screens/timer/flow_timer.dart'; +import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; +import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; class Application extends StatelessWidget { const Application({super.key}); @@ -45,6 +50,8 @@ class Application extends StatelessWidget { routes: { "metering": (_) => const ReleaseNotesFlow(child: MeteringFlow()), "settings": (_) => const SettingsFlow(), + "films": (_) => const FilmsScreen(), + "filmEdit": (context) => FilmEditFlow(args: ModalRoute.of(context)!.settings.arguments! as FilmEditArgs), "lightmeterPro": (_) => LightmeterProScreen(), "timer": (context) => TimerFlow(args: ModalRoute.of(context)!.settings.arguments! as TimerFlowArgs), }, diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 6469a14..236e9c7 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -67,8 +67,6 @@ "equipmentProfile": "Equipment profile", "equipmentProfiles": "Equipment profiles", "tapToAdd": "Tap to add", - "filmsInUse": "Films in use", - "filmsInUseDescription": "Select films which you use.", "general": "General", "keepScreenOn": "Keep screen on", "haptics": "Haptics", @@ -151,6 +149,10 @@ } }, "close": "Close", + "films": "Films", + "filmsInUse": "Films in use", + "filmsInUseDescription": "Select films which you use.", + "filmsCustom": "Custom films", "addFilmTitle": "Add film", "editFilmTitle": "Edit film", "filmFormula": "Formula", diff --git a/lib/screens/film_edit/flow_film_edit.dart b/lib/screens/film_edit/flow_film_edit.dart index 60876a2..45dc616 100644 --- a/lib/screens/film_edit/flow_film_edit.dart +++ b/lib/screens/film_edit/flow_film_edit.dart @@ -4,15 +4,21 @@ 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; +class FilmEditArgs { + final FilmExponential film; - const FilmEditFlow({this.film, super.key}); + const FilmEditArgs({required this.film}); +} + +class FilmEditFlow extends StatelessWidget { + final FilmEditArgs args; + + const FilmEditFlow({required this.args, super.key}); @override Widget build(BuildContext context) { return BlocProvider( - create: (_) => FilmEditBloc(film), + create: (_) => FilmEditBloc(args.film), child: const FilmEditScreen(), ); } diff --git a/lib/screens/films/screen_films.dart b/lib/screens/films/screen_films.dart index 0a69d2f..b8547dc 100644 --- a/lib/screens/films/screen_films.dart +++ b/lib/screens/films/screen_films.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/providers/films_provider.dart'; import 'package:lightmeter/res/dimens.dart'; -import 'package:lightmeter/screens/settings/components/shared/expandable_section_list/widget_expandable_section_list.dart'; +import 'package:lightmeter/screens/film_edit/flow_film_edit.dart'; import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; @@ -16,6 +16,12 @@ class FilmsScreen extends StatefulWidget { class _FilmsScreenState extends State with SingleTickerProviderStateMixin { late final tabController = TabController(length: 2, vsync: this); + @override + void dispose() { + tabController.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return SliverScreen( @@ -28,16 +34,22 @@ class _FilmsScreenState extends State with SingleTickerProviderStat ], ), appBarActions: [ - IconButton( - onPressed: _addFilm, - icon: const Icon(Icons.add_outlined), - tooltip: S.of(context).tooltipAdd, + AnimatedBuilder( + animation: tabController, + builder: (context, _) => AnimatedSwitcher( + duration: Dimens.switchDuration, + child: tabController.index == 0 + ? const SizedBox.shrink() + : IconButton( + onPressed: _addFilm, + icon: const Icon(Icons.add_outlined), + tooltip: S.of(context).tooltipAdd, + ), + ), ), ], slivers: [ SliverFillRemaining( - // The inner (body) scroll view must use this scroll controller so that - // the independent scroll positions can be kept in sync. child: TabBarView( controller: tabController, children: [ @@ -45,9 +57,10 @@ class _FilmsScreenState extends State with SingleTickerProviderStat films: Films.of(context).skip(1).toList(), onFilmSelected: (film, value) {}, ), - _FilmsListBuilder( - films: Films.of(context).skip(1).toList(), + _FilmsListBuilder( + films: Films.of(context).skip(1).whereType().toList(), onFilmSelected: (film, value) {}, + onFilmEdit: _editFilm, ), ], ), @@ -56,13 +69,25 @@ class _FilmsScreenState extends State with SingleTickerProviderStat ); } - void _addFilm([EquipmentProfile? copyFrom]) {} + void _addFilm() { + Navigator.of(context).pushNamed( + 'filmEdit', + arguments: const FilmEditArgs(film: FilmExponential(name: '', iso: 100, exponent: 1.3)), + ); + } + + void _editFilm(FilmExponential film) { + Navigator.of(context).pushNamed( + 'filmEdit', + arguments: FilmEditArgs(film: film), + ); + } } -class _FilmsListBuilder extends StatelessWidget { - final List films; - final void Function(Film film, bool value) onFilmSelected; - final void Function()? onFilmEdit; +class _FilmsListBuilder extends StatelessWidget { + final List films; + final void Function(T film, bool value) onFilmSelected; + final void Function(T film)? onFilmEdit; const _FilmsListBuilder({ required this.films, @@ -98,7 +123,7 @@ class _FilmsListBuilder extends StatelessWidget { }, secondary: onFilmEdit != null ? IconButton( - onPressed: onFilmEdit, + onPressed: () => onFilmEdit!(films[index]), icon: const Icon(Icons.edit), ) : null, diff --git a/lib/screens/settings/components/metering/components/films/components/widget_formula_input.dart b/lib/screens/settings/components/metering/components/films/components/widget_formula_input.dart deleted file mode 100644 index b122e5a..0000000 --- a/lib/screens/settings/components/metering/components/films/components/widget_formula_input.dart +++ /dev/null @@ -1,166 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:lightmeter/res/dimens.dart'; - -class FormulaInput extends StatefulWidget { - const FormulaInput({super.key}); - - @override - State createState() => _FormulaInputState(); -} - -class _FormulaInputState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - body: SafeArea( - child: Column( - children: [ - TextFormField( - inputFormatters: [ - FilteringTextInputFormatter.allow(RegExp('x')), - ], - ), - const Spacer(), - Row( - children: [ - _Button( - title: '()', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: 'ln', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: 'lg', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: '^', - onTap: () {}, - ), - ], - ), - Row( - children: [ - _Button( - title: '7', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: '8', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: '9', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: '^', - onTap: () {}, - ), - ], - ), - Row( - children: [ - _Button( - title: '4', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: '5', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: '6', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: '^', - onTap: () {}, - ), - ], - ), - Row( - children: [ - _Button( - title: '1', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: '2', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: '3', - onTap: () {}, - ), - _buttonsDivider, - _Button( - title: '^', - onTap: () {}, - ), - ], - ), - Row( - children: [ - _Button( - title: '0', - onTap: () {}, - ), - _Button( - title: '.', - onTap: () {}, - ), - _Button( - title: '<', - onTap: () {}, - ), - _Button( - title: '^', - onTap: () {}, - ), - ], - ) - ], - ), - ), - ); - } -} - -class _Button extends StatelessWidget { - final String title; - final VoidCallback onTap; - - const _Button({super.key, required this.title, required this.onTap}); - - @override - Widget build(BuildContext context) { - return Expanded( - child: Container( - alignment: Alignment.center, - height: Dimens.grid48, - decoration: ShapeDecoration( - color: Theme.of(context).colorScheme.secondaryContainer, - shape: const StadiumBorder(), - ), - child: Text(title), - ), - ); - } -} - -const _buttonsDivider = SizedBox(width: Dimens.grid8, height: Dimens.grid8); diff --git a/lib/screens/settings/components/metering/components/films/widget_list_tile_films.dart b/lib/screens/settings/components/metering/components/films/widget_list_tile_films.dart index 4eaf017..a2a0ab9 100644 --- a/lib/screens/settings/components/metering/components/films/widget_list_tile_films.dart +++ b/lib/screens/settings/components/metering/components/films/widget_list_tile_films.dart @@ -1,9 +1,6 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/generated/l10n.dart'; -import 'package:lightmeter/providers/films_provider.dart'; -import 'package:lightmeter/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart'; import 'package:lightmeter/screens/settings/components/shared/iap_list_tile/widget_list_tile_iap.dart'; -import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; class FilmsListTile extends StatelessWidget { const FilmsListTile({super.key}); @@ -12,24 +9,8 @@ class FilmsListTile extends StatelessWidget { Widget build(BuildContext context) { return IAPListTile( leading: const Icon(Icons.camera_roll_outlined), - title: Text(S.of(context).filmsInUse), - onTap: () { - showDialog>( - context: context, - builder: (_) => DialogFilter( - icon: const Icon(Icons.camera_roll_outlined), - title: S.of(context).filmsInUse, - description: S.of(context).filmsInUseDescription, - values: Films.of(context).sublist(1), - selectedValues: Films.inUseOf(context), - titleAdapter: (_, value) => value.name, - ), - ).then((values) { - if (values != null) { - FilmsProvider.of(context).saveFilms(values); - } - }); - }, + title: Text(S.of(context).films), + onTap: () => Navigator.of(context).pushNamed('films'), ); } }