From 4d02e71736ec0240553010b385a39e4404c72c58 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:23:46 +0100 Subject: [PATCH] added equipment profiles screens to navigation --- lib/application.dart | 6 +- lib/navigation/routes.dart | 3 +- .../screen_equipment_profiles.dart | 101 ++++++++++++++++++ lib/screens/films/screen_films.dart | 2 +- 4 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 lib/screens/equipment_profiles/screen_equipment_profiles.dart diff --git a/lib/application.dart b/lib/application.dart index 87cdfe3..7f90b35 100644 --- a/lib/application.dart +++ b/lib/application.dart @@ -7,10 +7,12 @@ import 'package:lightmeter/navigation/modal_route_args_parser.dart'; import 'package:lightmeter/navigation/routes.dart'; import 'package:lightmeter/platform_config.dart'; import 'package:lightmeter/providers/user_preferences_provider.dart'; +import 'package:lightmeter/screens/equipment_profile_edit/flow_equipment_profile_edit.dart'; import 'package:lightmeter/screens/film_edit/flow_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/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.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'; @@ -49,8 +51,10 @@ class Application extends StatelessWidget { routes: { NavigationRoutes.meteringScreen.name: (_) => const ReleaseNotesFlow(child: MeteringFlow()), NavigationRoutes.settingsScreen.name: (_) => const SettingsFlow(), + NavigationRoutes.equipmentProfilesListScreen.name: (_) => const EquipmentProfilesScreen(), + NavigationRoutes.equipmentProfileEditScreen.name: (context) => + EquipmentProfileEditFlow(args: context.routeArgs()), NavigationRoutes.filmsListScreen.name: (_) => const FilmsScreen(), - NavigationRoutes.filmAddScreen.name: (_) => const FilmEditFlow(args: FilmEditArgs()), NavigationRoutes.filmEditScreen.name: (context) => FilmEditFlow(args: context.routeArgs()), NavigationRoutes.proFeaturesScreen.name: (_) => LightmeterProScreen(), NavigationRoutes.timerScreen.name: (context) => TimerFlow(args: context.routeArgs()), diff --git a/lib/navigation/routes.dart b/lib/navigation/routes.dart index 4b496f0..f449be3 100644 --- a/lib/navigation/routes.dart +++ b/lib/navigation/routes.dart @@ -2,8 +2,9 @@ enum NavigationRoutes { meteringScreen, settingsScreen, filmsListScreen, - filmAddScreen, filmEditScreen, + equipmentProfilesListScreen, + equipmentProfileEditScreen, proFeaturesScreen, timerScreen, } diff --git a/lib/screens/equipment_profiles/screen_equipment_profiles.dart b/lib/screens/equipment_profiles/screen_equipment_profiles.dart new file mode 100644 index 0000000..d05e8be --- /dev/null +++ b/lib/screens/equipment_profiles/screen_equipment_profiles.dart @@ -0,0 +1,101 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/navigation/routes.dart'; +import 'package:lightmeter/providers/equipment_profile_provider.dart'; +import 'package:lightmeter/res/dimens.dart'; +import 'package:lightmeter/screens/equipment_profile_edit/flow_equipment_profile_edit.dart'; +import 'package:lightmeter/screens/shared/sliver_placeholder/widget_sliver_placeholder.dart'; +import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart'; +import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; + +class EquipmentProfilesScreen extends StatefulWidget { + const EquipmentProfilesScreen({super.key}); + + @override + State createState() => _EquipmentProfilesScreenState(); +} + +class _EquipmentProfilesScreenState extends State with SingleTickerProviderStateMixin { + @override + Widget build(BuildContext context) { + return SliverScreen( + title: Text(S.of(context).films), + appBarActions: [ + IconButton( + onPressed: _addProfile, + icon: const Icon(Icons.add_outlined), + tooltip: S.of(context).tooltipAdd, + ), + ], + slivers: [ + if (EquipmentProfiles.of(context).isNotEmpty) + _EquipmentProfilesListBuilder( + values: EquipmentProfiles.of(context).toList(), + onEdit: _editProfile, + ) + else + SliverPlaceholder(onTap: _addProfile), + ], + ); + } + + void _addProfile() { + Navigator.of(context).pushNamed( + NavigationRoutes.equipmentProfileEditScreen.name, + arguments: const EquipmentProfileEditArgs(), + ); + } + + void _editProfile(EquipmentProfile profile) { + Navigator.of(context).pushNamed( + NavigationRoutes.equipmentProfileEditScreen.name, + arguments: EquipmentProfileEditArgs(profile: profile), + ); + } +} + +class _EquipmentProfilesListBuilder extends StatelessWidget { + final List values; + final void Function(EquipmentProfile film) onEdit; + + const _EquipmentProfilesListBuilder({ + required this.values, + required this.onEdit, + }); + + @override + Widget build(BuildContext context) { + return SliverList.builder( + itemCount: values.length, + itemBuilder: (_, index) => Padding( + padding: EdgeInsets.fromLTRB( + Dimens.paddingM, + index == 0 ? Dimens.paddingM : 0, + Dimens.paddingM, + index == values.length - 1 ? Dimens.paddingM + MediaQuery.paddingOf(context).bottom : 0.0, + ), + child: Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.vertical( + top: index == 0 ? const Radius.circular(Dimens.borderRadiusL) : Radius.zero, + bottom: index == values.length - 1 ? const Radius.circular(Dimens.borderRadiusL) : Radius.zero, + ), + ), + child: Padding( + padding: EdgeInsets.only( + top: index == 0 ? Dimens.paddingM : 0.0, + bottom: index == values.length - 1 ? Dimens.paddingM : 0.0, + ), + child: ListTile( + title: Text(values[index].name), + trailing: IconButton( + onPressed: () => onEdit(values[index]), + icon: const Icon(Icons.edit), + ), + ), + ), + ), + ), + ); + } +} diff --git a/lib/screens/films/screen_films.dart b/lib/screens/films/screen_films.dart index 5a11c2f..06eaf8e 100644 --- a/lib/screens/films/screen_films.dart +++ b/lib/screens/films/screen_films.dart @@ -78,7 +78,7 @@ class _FilmsScreenState extends State with SingleTickerProviderStat void _addFilm() { Navigator.of(context).pushNamed( - NavigationRoutes.filmAddScreen.name, + NavigationRoutes.filmEditScreen.name, arguments: const FilmEditArgs(), ); }