From 3bb2b7845bebf60431bee16f58f8889c4a3b8e13 Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 18 May 2023 19:56:13 +0200 Subject: [PATCH] removed `Provider` from providers folder --- lib/application.dart | 43 ++++++++------- lib/providers/equipment_profile_provider.dart | 52 +++---------------- lib/providers/ev_source_type_provider.dart | 7 +-- lib/providers/supported_locale_provider.dart | 7 +-- lib/providers/theme_provider.dart | 25 ++++----- .../widget_bottom_controls.dart | 4 +- .../widget_container_readings.dart | 13 ++--- lib/screens/metering/flow_metering.dart | 2 +- lib/screens/metering/screen_metering.dart | 47 +++++++---------- .../language/widget_list_tile_language.dart | 6 +-- .../screen_equipment_profile.dart | 10 ++-- .../widget_list_tile_dynamic_color.dart | 4 +- .../widget_list_tile_primary_color.dart | 5 +- .../widget_list_tile_theme_type.dart | 6 +-- .../theme/widget_settings_section_theme.dart | 5 +- 15 files changed, 99 insertions(+), 137 deletions(-) diff --git a/lib/application.dart b/lib/application.dart index 39b2de2..82f4a8f 100644 --- a/lib/application.dart +++ b/lib/application.dart @@ -19,6 +19,7 @@ import 'package:lightmeter/providers/supported_locale_provider.dart'; import 'package:lightmeter/providers/theme_provider.dart'; import 'package:lightmeter/screens/metering/flow_metering.dart'; import 'package:lightmeter/screens/settings/flow_settings.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -53,26 +54,28 @@ class Application extends StatelessWidget { 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!, + child: Builder( + builder: (context) => _AnnotatedRegionWrapper( + child: MaterialApp( + theme: context.listen(), + locale: Locale(context.listen().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(), + }, ), - initialRoute: "metering", - routes: { - "metering": (context) => const MeteringFlow(), - "settings": (context) => const SettingsFlow(), - }, ), ), ), @@ -100,7 +103,7 @@ class _AnnotatedRegionWrapper extends StatelessWidget { @override Widget build(BuildContext context) { final systemIconsBrightness = ThemeData.estimateBrightnessForColor( - context.watch().colorScheme.onSurface, + context.listen().colorScheme.onSurface, ); return AnnotatedRegion( value: SystemUiOverlayStyle( diff --git a/lib/providers/equipment_profile_provider.dart b/lib/providers/equipment_profile_provider.dart index fea496e..1c986fa 100644 --- a/lib/providers/equipment_profile_provider.dart +++ b/lib/providers/equipment_profile_provider.dart @@ -1,9 +1,13 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/data/shared_prefs_service.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:provider/provider.dart'; import 'package:uuid/uuid.dart'; +typedef EquipmentProfiles = List; +typedef EquipmentProfile = EquipmentProfileData; + class EquipmentProfileProvider extends StatefulWidget { final Widget child; @@ -47,9 +51,9 @@ class EquipmentProfileProviderState extends State { @override Widget build(BuildContext context) { - return EquipmentProfiles( - profiles: [_defaultProfile] + _customProfiles, - child: EquipmentProfile( + return InheritedWidgetBase>( + data: [_defaultProfile] + _customProfiles, + child: InheritedWidgetBase( data: _selectedProfile, child: widget.child, ), @@ -96,45 +100,3 @@ class EquipmentProfileProviderState extends State { setState(() {}); } } - -class EquipmentProfiles extends InheritedWidget { - final List profiles; - - const EquipmentProfiles({ - required this.profiles, - required super.child, - super.key, - }); - - static List of(BuildContext context, {bool listen = true}) { - if (listen) { - return context.dependOnInheritedWidgetOfExactType()!.profiles; - } else { - return context.findAncestorWidgetOfExactType()!.profiles; - } - } - - @override - bool updateShouldNotify(EquipmentProfiles oldWidget) => true; -} - -class EquipmentProfile extends InheritedWidget { - final EquipmentProfileData data; - - const EquipmentProfile({ - required this.data, - required super.child, - super.key, - }); - - static EquipmentProfileData of(BuildContext context, {bool listen = true}) { - if (listen) { - return context.dependOnInheritedWidgetOfExactType()!.data; - } else { - return context.findAncestorWidgetOfExactType()!.data; - } - } - - @override - bool updateShouldNotify(EquipmentProfile oldWidget) => true; -} diff --git a/lib/providers/ev_source_type_provider.dart b/lib/providers/ev_source_type_provider.dart index 83657e2..afbc759 100644 --- a/lib/providers/ev_source_type_provider.dart +++ b/lib/providers/ev_source_type_provider.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/data/models/ev_source_type.dart'; import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/environment.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; import 'package:provider/provider.dart'; class EvSourceTypeProvider extends StatefulWidget { @@ -41,9 +42,9 @@ class EvSourceTypeProviderState extends State { Widget build(BuildContext context) { return ValueListenableBuilder( valueListenable: valueListenable, - builder: (_, value, child) => Provider.value( - value: value, - child: child, + builder: (_, value, child) => InheritedWidgetBase( + data: value, + child: child!, ), child: widget.child, ); diff --git a/lib/providers/supported_locale_provider.dart b/lib/providers/supported_locale_provider.dart index 32ee912..3a6aca9 100644 --- a/lib/providers/supported_locale_provider.dart +++ b/lib/providers/supported_locale_provider.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/data/models/supported_locale.dart'; import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; import 'package:provider/provider.dart'; class SupportedLocaleProvider extends StatefulWidget { @@ -36,9 +37,9 @@ class SupportedLocaleProviderState extends State { Widget build(BuildContext context) { return ValueListenableBuilder( valueListenable: valueListenable, - builder: (_, value, child) => Provider.value( - value: value, - child: child, + builder: (_, value, child) => InheritedWidgetBase( + data: value, + child: child!, ), child: widget.child, ); diff --git a/lib/providers/theme_provider.dart b/lib/providers/theme_provider.dart index d2f1f37..f4a8829 100644 --- a/lib/providers/theme_provider.dart +++ b/lib/providers/theme_provider.dart @@ -5,15 +5,16 @@ import 'package:lightmeter/data/models/dynamic_colors_state.dart'; import 'package:lightmeter/data/models/theme_type.dart'; import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/res/dimens.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; import 'package:material_color_utilities/material_color_utilities.dart'; import 'package:provider/provider.dart'; class ThemeProvider extends StatefulWidget { - final TransitionBuilder? builder; + final Widget child; const ThemeProvider({ - this.builder, + required this.child, super.key, }); @@ -76,8 +77,8 @@ class ThemeProviderState extends State with WidgetsBindingObserve Widget build(BuildContext context) { return ValueListenableBuilder( valueListenable: _themeTypeNotifier, - builder: (_, themeType, __) => Provider.value( - value: themeType, + builder: (_, themeType, __) => InheritedWidgetBase( + data: themeType, child: ValueListenableBuilder( valueListenable: _dynamicColorNotifier, builder: (_, useDynamicColor, __) => _DynamicColorProvider( @@ -88,7 +89,7 @@ class ThemeProviderState extends State with WidgetsBindingObserve builder: (_, primaryColor, __) => _ThemeDataProvider( primaryColor: dynamicPrimaryColor ?? primaryColor, brightness: _themeBrightness, - builder: widget.builder, + child: widget.child, ), ), ), @@ -154,8 +155,8 @@ class _DynamicColorProvider extends StatelessWidget { dynamicPrimaryColor = null; state = DynamicColorState.unavailable; } - return Provider.value( - value: state, + return InheritedWidgetBase( + data: state, child: builder(context, dynamicPrimaryColor), ); }, @@ -166,19 +167,19 @@ class _DynamicColorProvider extends StatelessWidget { class _ThemeDataProvider extends StatelessWidget { final Color primaryColor; final Brightness brightness; - final TransitionBuilder? builder; + final Widget child; const _ThemeDataProvider({ required this.primaryColor, required this.brightness, - required this.builder, + required this.child, }); @override Widget build(BuildContext context) { - return Provider.value( - value: _themeFromColorScheme(_colorSchemeFromColor()), - builder: builder, + return InheritedWidgetBase( + data: _themeFromColorScheme(_colorSchemeFromColor()), + child: child, ); } diff --git a/lib/screens/metering/components/bottom_controls/widget_bottom_controls.dart b/lib/screens/metering/components/bottom_controls/widget_bottom_controls.dart index 13a3892..96cd7b6 100644 --- a/lib/screens/metering/components/bottom_controls/widget_bottom_controls.dart +++ b/lib/screens/metering/components/bottom_controls/widget_bottom_controls.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/data/models/ev_source_type.dart'; import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart'; -import 'package:provider/provider.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; class MeteringBottomControls extends StatelessWidget { final double? ev; @@ -44,7 +44,7 @@ class MeteringBottomControls extends StatelessWidget { child: IconButton( onPressed: onSwitchEvSourceType, icon: Icon( - context.watch() != EvSourceType.camera + context.listen() != EvSourceType.camera ? Icons.camera_rear : Icons.wb_incandescent, ), 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 688d932..09f8bce 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 @@ -9,6 +9,7 @@ import 'package:lightmeter/providers/metering_screen_layout_provider.dart'; import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/animated_dialog_picker/widget_picker_dialog_animated.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/reading_value_container/widget_container_reading_value.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; class ReadingsContainer extends StatelessWidget { @@ -76,7 +77,7 @@ class ReadingsContainer extends StatelessWidget { Expanded( child: _IsoValuePicker( selectedValue: iso, - values: EquipmentProfile.of(context).isoValues, + values: context.listen().isoValues, onChanged: onIsoChanged, ), ), @@ -84,7 +85,7 @@ class ReadingsContainer extends StatelessWidget { Expanded( child: _NdValuePicker( selectedValue: nd, - values: EquipmentProfile.of(context).ndValues, + values: context.listen().ndValues, onChanged: onNdChanged, ), ), @@ -107,16 +108,16 @@ class _EquipmentProfilePicker extends StatelessWidget { return AnimatedDialogPicker( icon: Icons.camera, title: S.of(context).equipmentProfile, - selectedValue: EquipmentProfile.of(context), - values: EquipmentProfiles.of(context), + selectedValue: context.listen(), + values: context.listen(), itemTitleBuilder: (_, value) => Text(value.id.isEmpty ? S.of(context).none : value.name), onChanged: EquipmentProfileProvider.of(context).setProfile, closedChild: ReadingValueContainer.singleValue( value: ReadingValue( label: S.of(context).equipmentProfile, - value: EquipmentProfile.of(context).id.isEmpty + value: context.listen().id.isEmpty ? S.of(context).none - : EquipmentProfile.of(context).name, + : context.listen().name, ), ), ); diff --git a/lib/screens/metering/flow_metering.dart b/lib/screens/metering/flow_metering.dart index ff34afa..b6364c1 100644 --- a/lib/screens/metering/flow_metering.dart +++ b/lib/screens/metering/flow_metering.dart @@ -39,7 +39,7 @@ class _MeteringFlowState extends State { create: (context) => MeteringBloc( context.read(), context.read(), - EquipmentProfile.of(context, listen: false), + context.get(), context.get(), ), ), diff --git a/lib/screens/metering/screen_metering.dart b/lib/screens/metering/screen_metering.dart index 51d33b9..5058897 100644 --- a/lib/screens/metering/screen_metering.dart +++ b/lib/screens/metering/screen_metering.dart @@ -16,22 +16,9 @@ import 'package:lightmeter/screens/metering/state_metering.dart'; import 'package:lightmeter/utils/inherited_generics.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; -class MeteringScreen extends StatefulWidget { +class MeteringScreen extends StatelessWidget { const MeteringScreen({super.key}); - @override - State createState() => _MeteringScreenState(); -} - -class _MeteringScreenState extends State { - MeteringBloc get _bloc => context.read(); - - @override - void didChangeDependencies() { - super.didChangeDependencies(); - _bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context))); - } - @override Widget build(BuildContext context) { return _InheritedListeners( @@ -48,22 +35,23 @@ class _MeteringScreenState extends State { film: state.film, iso: state.iso, nd: state.nd, - onFilmChanged: (value) => _bloc.add(FilmChangedEvent(value)), - onIsoChanged: (value) => _bloc.add(IsoChangedEvent(value)), - onNdChanged: (value) => _bloc.add(NdChangedEvent(value)), + onFilmChanged: (value) => + context.read().add(FilmChangedEvent(value)), + onIsoChanged: (value) => context.read().add(IsoChangedEvent(value)), + onNdChanged: (value) => context.read().add(NdChangedEvent(value)), ), ), ), BlocBuilder( builder: (context, state) => MeteringBottomControlsProvider( ev: state is MeteringDataState ? state.ev : null, - isMetering: state is LoadingState || - state is MeteringDataState && state.continuousMetering, + isMetering: + state is LoadingState || state is MeteringDataState && state.continuousMetering, hasError: state is MeteringDataState && state.hasError, onSwitchEvSourceType: context.read().hasLightSensor ? EvSourceTypeProvider.of(context).toggleType : null, - onMeasure: () => _bloc.add(const MeasureEvent()), + onMeasure: () => context.read().add(const MeasureEvent()), onSettings: () => Navigator.pushNamed(context, 'settings'), ), ), @@ -81,16 +69,21 @@ class _InheritedListeners extends StatelessWidget { @override Widget build(BuildContext context) { - return InheritedWidgetListener( + return InheritedWidgetListener( onDidChangeDependencies: (value) { - context.read().add(StopTypeChangedEvent(value)); + context.read().add(EquipmentProfileChangedEvent(value)); }, - child: InheritedModelAspectListener( - aspect: MeteringScreenLayoutFeature.filmPicker, + child: InheritedWidgetListener( onDidChangeDependencies: (value) { - if (!value) context.read().add(const FilmChangedEvent(Film.other())); + context.read().add(StopTypeChangedEvent(value)); }, - child: child, + child: InheritedModelAspectListener( + aspect: MeteringScreenLayoutFeature.filmPicker, + onDidChangeDependencies: (value) { + if (!value) context.read().add(const FilmChangedEvent(Film.other())); + }, + child: child, + ), ), ); } @@ -121,7 +114,7 @@ class _MeteringContainerBuidler extends StatelessWidget { @override Widget build(BuildContext context) { - return context.watch() == EvSourceType.camera + return context.listen() == EvSourceType.camera ? CameraContainerProvider( fastest: fastest, slowest: slowest, diff --git a/lib/screens/settings/components/general/components/language/widget_list_tile_language.dart b/lib/screens/settings/components/general/components/language/widget_list_tile_language.dart index 4bea398..381f286 100644 --- a/lib/screens/settings/components/general/components/language/widget_list_tile_language.dart +++ b/lib/screens/settings/components/general/components/language/widget_list_tile_language.dart @@ -3,7 +3,7 @@ import 'package:lightmeter/data/models/supported_locale.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/providers/supported_locale_provider.dart'; import 'package:lightmeter/screens/settings/components/shared/dialog_picker.dart/widget_dialog_picker.dart'; -import 'package:provider/provider.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; class LanguageListTile extends StatelessWidget { const LanguageListTile({super.key}); @@ -13,14 +13,14 @@ class LanguageListTile extends StatelessWidget { return ListTile( leading: const Icon(Icons.language), title: Text(S.of(context).language), - trailing: Text(context.watch().localizedName), + trailing: Text(context.listen().localizedName), onTap: () { showDialog( context: context, builder: (_) => DialogPicker( icon: Icons.language, title: S.of(context).chooseLanguage, - selectedValue: context.read(), + selectedValue: context.get(), values: SupportedLocale.values, titleAdapter: (context, value) => value.localizedName, ), 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 04a9be1..25ca59a 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 @@ -5,6 +5,7 @@ import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/widget_container_equipment_profile.dart'; import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_name_dialog/widget_dialog_equipment_profile_name.dart'; import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; class EquipmentProfilesScreen extends StatefulWidget { @@ -18,12 +19,13 @@ class _EquipmentProfilesScreenState extends State { static const maxProfiles = 5 + 1; // replace with a constant from iap late List> profileContainersKeys = []; - int get profilesCount => EquipmentProfiles.of(context).length; + int get profilesCount => context.listen().length; @override void initState() { super.initState(); - profileContainersKeys = EquipmentProfiles.of(context, listen: false) + profileContainersKeys = context + .get() .map((e) => GlobalKey(debugLabel: e.id)) .toList(); } @@ -56,7 +58,7 @@ class _EquipmentProfilesScreenState extends State { ), child: EquipmentProfileContainer( key: profileContainersKeys[index], - data: EquipmentProfiles.of(context)[index], + data: context.listen()[index], onExpand: () => _keepExpandedAt(index), onUpdate: (profileData) => _updateProfileAt(profileData, index), onDelete: () => _removeProfileAt(index), @@ -87,7 +89,7 @@ class _EquipmentProfilesScreenState extends State { } void _removeProfileAt(int index) { - EquipmentProfileProvider.of(context).deleteProfile(EquipmentProfiles.of(context)[index]); + EquipmentProfileProvider.of(context).deleteProfile(context.listen()[index]); profileContainersKeys.removeAt(index); } diff --git a/lib/screens/settings/components/theme/components/dynamic_color/widget_list_tile_dynamic_color.dart b/lib/screens/settings/components/theme/components/dynamic_color/widget_list_tile_dynamic_color.dart index db8e7f0..f15186e 100644 --- a/lib/screens/settings/components/theme/components/dynamic_color/widget_list_tile_dynamic_color.dart +++ b/lib/screens/settings/components/theme/components/dynamic_color/widget_list_tile_dynamic_color.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/data/models/dynamic_colors_state.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/providers/theme_provider.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; class DynamicColorListTile extends StatelessWidget { const DynamicColorListTile({super.key}); @@ -12,7 +12,7 @@ class DynamicColorListTile extends StatelessWidget { return SwitchListTile( secondary: const Icon(Icons.colorize), title: Text(S.of(context).dynamicColor), - value: context.watch() == DynamicColorState.enabled, + value: context.listen() == DynamicColorState.enabled, onChanged: ThemeProvider.of(context).enableDynamicColor, ); } diff --git a/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart b/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart index 6b6c0d0..afc1a7b 100644 --- a/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart +++ b/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart @@ -1,18 +1,17 @@ import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/data/models/dynamic_colors_state.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/providers/theme_provider.dart'; import 'package:lightmeter/res/dimens.dart'; - import 'package:lightmeter/screens/settings/components/theme/components/primary_color/components/primary_color_picker_dialog/widget_dialog_picker_primary_color.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; class PrimaryColorListTile extends StatelessWidget { const PrimaryColorListTile({super.key}); @override Widget build(BuildContext context) { - if (context.watch() == DynamicColorState.enabled) { + if (context.listen() == DynamicColorState.enabled) { return Opacity( opacity: Dimens.disabledOpacity, child: IgnorePointer( diff --git a/lib/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart b/lib/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart index 3c43224..46e1b86 100644 --- a/lib/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart +++ b/lib/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart @@ -3,7 +3,7 @@ import 'package:lightmeter/data/models/theme_type.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/providers/theme_provider.dart'; import 'package:lightmeter/screens/settings/components/shared/dialog_picker.dart/widget_dialog_picker.dart'; -import 'package:provider/provider.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; class ThemeTypeListTile extends StatelessWidget { const ThemeTypeListTile({super.key}); @@ -13,14 +13,14 @@ class ThemeTypeListTile extends StatelessWidget { return ListTile( leading: const Icon(Icons.brightness_6), title: Text(S.of(context).theme), - trailing: Text(_typeToString(context, context.watch())), + trailing: Text(_typeToString(context, context.listen())), onTap: () { showDialog( context: context, builder: (_) => DialogPicker( icon: Icons.brightness_6, title: S.of(context).chooseTheme, - selectedValue: context.read(), + selectedValue: context.get(), values: ThemeType.values, titleAdapter: _typeToString, ), diff --git a/lib/screens/settings/components/theme/widget_settings_section_theme.dart b/lib/screens/settings/components/theme/widget_settings_section_theme.dart index 8a9bbfa..d137469 100644 --- a/lib/screens/settings/components/theme/widget_settings_section_theme.dart +++ b/lib/screens/settings/components/theme/widget_settings_section_theme.dart @@ -1,12 +1,11 @@ import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/data/models/dynamic_colors_state.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/screens/settings/components/shared/settings_section/widget_settings_section.dart'; - import 'package:lightmeter/screens/settings/components/theme/components/dynamic_color/widget_list_tile_dynamic_color.dart'; import 'package:lightmeter/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart'; import 'package:lightmeter/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart'; +import 'package:lightmeter/utils/inherited_generics.dart'; class ThemeSettingsSection extends StatelessWidget { const ThemeSettingsSection({super.key}); @@ -18,7 +17,7 @@ class ThemeSettingsSection extends StatelessWidget { children: [ const ThemeTypeListTile(), const PrimaryColorListTile(), - if (context.read() != DynamicColorState.unavailable) + if (context.get() != DynamicColorState.unavailable) const DynamicColorListTile(), ], );