From 5e814184f096811e3697c8a7a74bf5573625ec96 Mon Sep 17 00:00:00 2001 From: Vadim Date: Mon, 20 Mar 2023 22:34:59 +0300 Subject: [PATCH] improved equipment profiles screen --- lib/application.dart | 51 ++++---- .../widget_container_readings.dart | 3 +- .../widget_list_tile_equipment.dart | 46 ------- .../widget_list_tiles_equipments.dart | 114 ++++++++++++++++++ .../widget_section_equipment_profile.dart | 73 ++++------- .../screen_equipment_profile.dart | 18 ++- .../dialog_filter/widget_dialog_filter.dart | 0 7 files changed, 176 insertions(+), 129 deletions(-) delete mode 100644 lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/components/equipment_list_tile/widget_list_tile_equipment.dart create mode 100644 lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/components/equipment_list_tiles/widget_list_tiles_equipments.dart rename lib/screens/settings/components/{metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/components => shared}/dialog_filter/widget_dialog_filter.dart (100%) diff --git a/lib/application.dart b/lib/application.dart index 0f0a184..ed596a5 100644 --- a/lib/application.dart +++ b/lib/application.dart @@ -8,7 +8,6 @@ import 'package:lightmeter/data/caffeine_service.dart'; import 'package:lightmeter/data/haptics_service.dart'; import 'package:lightmeter/data/models/supported_locale.dart'; import 'package:lightmeter/providers/supported_locale_provider.dart'; -import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -48,33 +47,31 @@ class Application extends StatelessWidget { Provider(create: (_) => PermissionsService()), Provider(create: (_) => const LightSensorService()), ], - child: IAPProductsProvider( - child: StopTypeProvider( - child: EquipmentProfileProvider( - child: EvSourceTypeProvider( - child: SupportedLocaleProvider( - child: ThemeProvider( - builder: (context, _) => _AnnotatedRegionWrapper( - child: MaterialApp( - theme: context.watch(), - locale: Locale(context.watch().intlName), - localizationsDelegates: const [ - S.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: S.delegate.supportedLocales, - builder: (context, child) => MediaQuery( - data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), - child: child!, - ), - initialRoute: "metering", - routes: { - "metering": (context) => const MeteringFlow(), - "settings": (context) => const SettingsFlow(), - }, + child: StopTypeProvider( + child: EquipmentProfileProvider( + child: EvSourceTypeProvider( + child: SupportedLocaleProvider( + child: ThemeProvider( + builder: (context, _) => _AnnotatedRegionWrapper( + child: MaterialApp( + theme: context.watch(), + locale: Locale(context.watch().intlName), + localizationsDelegates: const [ + S.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: S.delegate.supportedLocales, + builder: (context, child) => MediaQuery( + data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), + child: child!, ), + initialRoute: "metering", + routes: { + "metering": (context) => const MeteringFlow(), + "settings": (context) => const SettingsFlow(), + }, ), ), ), diff --git a/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart b/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart index 15afdb9..0fa7140 100644 --- a/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart +++ b/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart @@ -38,8 +38,7 @@ class ReadingsContainer extends StatelessWidget { return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - if (IAPProducts.of(context, IAPProductType.equipment)?.status == - IAPProductStatus.purchased) ...[ + if (true) ...[ ReadingValueContainer.singleValue( value: ReadingValue( label: S.of(context).equipment, diff --git a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/components/equipment_list_tile/widget_list_tile_equipment.dart b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/components/equipment_list_tile/widget_list_tile_equipment.dart deleted file mode 100644 index 356c4aa..0000000 --- a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/components/equipment_list_tile/widget_list_tile_equipment.dart +++ /dev/null @@ -1,46 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; - -import '../dialog_filter/widget_dialog_filter.dart'; - -class EquipmentListTile extends StatelessWidget { - final IconData icon; - final String title; - final String description; - final List selectedValues; - final List values; - final ValueChanged> onChanged; - final bool rangeSelect; - - const EquipmentListTile({ - required this.icon, - required this.title, - required this.description, - required this.selectedValues, - required this.values, - required this.onChanged, - required this.rangeSelect, - super.key, - }); - - @override - Widget build(BuildContext context) { - return ListTile( - leading: Icon(icon), - title: Text(title), - onTap: () { - showDialog( - context: context, - builder: (_) => DialogFilter( - icon: Icon(icon), - title: title, - description: description, - values: values, - titleAdapter: (_, value) => value.toString(), - rangeSelect: rangeSelect, - ), - ); - }, - ); - } -} diff --git a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/components/equipment_list_tiles/widget_list_tiles_equipments.dart b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/components/equipment_list_tiles/widget_list_tiles_equipments.dart new file mode 100644 index 0000000..53f8559 --- /dev/null +++ b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/components/equipment_list_tiles/widget_list_tiles_equipments.dart @@ -0,0 +1,114 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/generated/l10n.dart'; +import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; +import 'package:lightmeter/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart'; + +class EquipmentListTiles extends StatelessWidget { + final List selectedApertureValues; + final List selectedIsoValues; + final List selectedNdValues; + final List selectedShutterSpeedValues; + final ValueChanged> onApertureValuesSelected; + final ValueChanged> onIsoValuesSelecred; + final ValueChanged> onNdValuesSelected; + final ValueChanged> onShutterSpeedValuesSelected; + + const EquipmentListTiles({ + required this.selectedApertureValues, + required this.selectedIsoValues, + required this.selectedNdValues, + required this.selectedShutterSpeedValues, + required this.onApertureValuesSelected, + required this.onIsoValuesSelecred, + required this.onNdValuesSelected, + required this.onShutterSpeedValuesSelected, + super.key, + }); + + @override + Widget build(BuildContext context) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + _EquipmentListTile( + icon: Icons.iso, + title: S.of(context).isoValues, + description: S.of(context).isoValuesFilterDescription, + values: isoValues, + selectedValues: selectedIsoValues, + rangeSelect: false, + onChanged: onIsoValuesSelecred, + ), + _EquipmentListTile( + icon: Icons.filter_b_and_w, + title: S.of(context).ndFilters, + description: S.of(context).ndFiltersFilterDescription, + values: ndValues, + selectedValues: selectedNdValues, + rangeSelect: false, + onChanged: onNdValuesSelected, + ), + _EquipmentListTile( + icon: Icons.camera, + title: S.of(context).apertureValues, + description: S.of(context).apertureValuesFilterDescription, + values: apertureValues, + selectedValues: selectedApertureValues, + rangeSelect: true, + onChanged: onApertureValuesSelected, + ), + _EquipmentListTile( + icon: Icons.shutter_speed, + title: S.of(context).shutterSpeedValues, + description: S.of(context).shutterSpeedValuesFilterDescription, + values: shutterSpeedValues, + selectedValues: selectedShutterSpeedValues, + rangeSelect: true, + onChanged: onShutterSpeedValuesSelected, + ), + ], + ); + } +} + +class _EquipmentListTile extends StatelessWidget { + final IconData icon; + final String title; + final String description; + final List selectedValues; + final List values; + final ValueChanged> onChanged; + final bool rangeSelect; + + const _EquipmentListTile({ + required this.icon, + required this.title, + required this.description, + required this.selectedValues, + required this.values, + required this.onChanged, + required this.rangeSelect, + super.key, + }); + + @override + Widget build(BuildContext context) { + return ListTile( + leading: Icon(icon), + title: Text(title), + onTap: () { + showDialog( + context: context, + builder: (_) => DialogFilter( + icon: Icon(icon), + title: title, + description: description, + values: values, + titleAdapter: (_, value) => value.toString(), + rangeSelect: rangeSelect, + ), + ); + }, + ); + } +} diff --git a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/widget_section_equipment_profile.dart b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/widget_section_equipment_profile.dart index d553ed7..2f761b4 100644 --- a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/widget_section_equipment_profile.dart +++ b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/widget_section_equipment_profile.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; +import 'package:flutter/scheduler.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; -import 'components/equipment_list_tile/widget_list_tile_equipment.dart'; +import 'components/equipment_list_tiles/widget_list_tiles_equipments.dart'; class EquipmentListTilesSection extends StatefulWidget { final EquipmentProfileData data; @@ -69,7 +70,17 @@ class _EquipmentListTilesSectionState extends State { ), ], ), - if (_expanded) const _DialogsListTiles() + if (_expanded) + EquipmentListTiles( + selectedApertureValues: widget.data.apertureValues, + selectedIsoValues: widget.data.isoValues, + selectedNdValues: widget.data.ndValues, + selectedShutterSpeedValues: widget.data.shutterSpeedValues, + onApertureValuesSelected: (value) {}, + onIsoValuesSelecred: (value) {}, + onNdValuesSelected: (value) {}, + onShutterSpeedValuesSelected: (value) {}, + ), ], ), ), @@ -82,7 +93,14 @@ class _EquipmentListTilesSectionState extends State { setState(() { _expanded = !_expanded; }); - if (!_expanded) { + if (_expanded) { + SchedulerBinding.instance.addPostFrameCallback((_) { + Scrollable.ensureVisible( + context, + alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd, + ); + }); + } else { _fieldFocusNode.unfocus(); } }, @@ -90,52 +108,3 @@ class _EquipmentListTilesSectionState extends State { ); } } - -class _DialogsListTiles extends StatelessWidget { - const _DialogsListTiles(); - - @override - Widget build(BuildContext context) { - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - EquipmentListTile( - icon: Icons.iso, - title: S.of(context).isoValues, - description: S.of(context).isoValuesFilterDescription, - values: isoValues, - selectedValues: const [], - rangeSelect: false, - onChanged: (value) {}, - ), - EquipmentListTile( - icon: Icons.filter_b_and_w, - title: S.of(context).ndFilters, - description: S.of(context).ndFiltersFilterDescription, - values: ndValues, - selectedValues: const [], - rangeSelect: false, - onChanged: (value) {}, - ), - EquipmentListTile( - icon: Icons.camera, - title: S.of(context).apertureValues, - description: S.of(context).apertureValuesFilterDescription, - values: apertureValues, - selectedValues: const [], - rangeSelect: true, - onChanged: (value) {}, - ), - EquipmentListTile( - icon: Icons.shutter_speed, - title: S.of(context).shutterSpeedValues, - description: S.of(context).shutterSpeedValuesFilterDescription, - values: shutterSpeedValues, - selectedValues: const [], - rangeSelect: true, - onChanged: (value) {}, - ), - ], - ); - } -} diff --git a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart index 400d3a9..0e54985 100644 --- a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart +++ b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart @@ -23,14 +23,28 @@ class _EquipmentProfileScreenState extends State { ), body: SafeArea( bottom: false, - child: ListView.builder( - padding: const EdgeInsets.all(Dimens.paddingM), + child: ListView.separated( + padding: EdgeInsets.fromLTRB( + Dimens.paddingM, + Dimens.paddingM, + Dimens.paddingM, + Dimens.paddingM + + MediaQuery.of(context).padding.bottom + + Dimens.grid56 + + kFloatingActionButtonMargin, + ), + separatorBuilder: (context, index) => const SizedBox(height: Dimens.grid16), itemCount: EquipmentProfiles.of(context)?.length ?? 0, itemBuilder: (_, index) => EquipmentListTilesSection( data: EquipmentProfiles.of(context)![index], ), ), ), + floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, + floatingActionButton: FloatingActionButton( + onPressed: EquipmentProfileProvider.of(context).addProfile, + child: const Icon(Icons.add), + ), ); } } diff --git a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/components/dialog_filter/widget_dialog_filter.dart b/lib/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart similarity index 100% rename from lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_section/components/dialog_filter/widget_dialog_filter.dart rename to lib/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart