removed Provider from providers folder

This commit is contained in:
Vadim 2023-05-18 19:56:13 +02:00
parent 2c85a3fddc
commit 3bb2b7845b
15 changed files with 99 additions and 137 deletions

View file

@ -19,6 +19,7 @@ import 'package:lightmeter/providers/supported_locale_provider.dart';
import 'package:lightmeter/providers/theme_provider.dart'; import 'package:lightmeter/providers/theme_provider.dart';
import 'package:lightmeter/screens/metering/flow_metering.dart'; import 'package:lightmeter/screens/metering/flow_metering.dart';
import 'package:lightmeter/screens/settings/flow_settings.dart'; import 'package:lightmeter/screens/settings/flow_settings.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -53,10 +54,11 @@ class Application extends StatelessWidget {
child: EvSourceTypeProvider( child: EvSourceTypeProvider(
child: SupportedLocaleProvider( child: SupportedLocaleProvider(
child: ThemeProvider( child: ThemeProvider(
builder: (context, _) => _AnnotatedRegionWrapper( child: Builder(
builder: (context) => _AnnotatedRegionWrapper(
child: MaterialApp( child: MaterialApp(
theme: context.watch<ThemeData>(), theme: context.listen<ThemeData>(),
locale: Locale(context.watch<SupportedLocale>().intlName), locale: Locale(context.listen<SupportedLocale>().intlName),
localizationsDelegates: const [ localizationsDelegates: const [
S.delegate, S.delegate,
GlobalMaterialLocalizations.delegate, GlobalMaterialLocalizations.delegate,
@ -81,6 +83,7 @@ class Application extends StatelessWidget {
), ),
), ),
), ),
),
); );
} else if (snapshot.error != null) { } else if (snapshot.error != null) {
return Center(child: Text(snapshot.error!.toString())); return Center(child: Text(snapshot.error!.toString()));
@ -100,7 +103,7 @@ class _AnnotatedRegionWrapper extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final systemIconsBrightness = ThemeData.estimateBrightnessForColor( final systemIconsBrightness = ThemeData.estimateBrightnessForColor(
context.watch<ThemeData>().colorScheme.onSurface, context.listen<ThemeData>().colorScheme.onSurface,
); );
return AnnotatedRegion( return AnnotatedRegion(
value: SystemUiOverlayStyle( value: SystemUiOverlayStyle(

View file

@ -1,9 +1,13 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lightmeter/data/shared_prefs_service.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:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
typedef EquipmentProfiles = List<EquipmentProfileData>;
typedef EquipmentProfile = EquipmentProfileData;
class EquipmentProfileProvider extends StatefulWidget { class EquipmentProfileProvider extends StatefulWidget {
final Widget child; final Widget child;
@ -47,9 +51,9 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return EquipmentProfiles( return InheritedWidgetBase<List<EquipmentProfileData>>(
profiles: [_defaultProfile] + _customProfiles, data: [_defaultProfile] + _customProfiles,
child: EquipmentProfile( child: InheritedWidgetBase<EquipmentProfileData>(
data: _selectedProfile, data: _selectedProfile,
child: widget.child, child: widget.child,
), ),
@ -96,45 +100,3 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
setState(() {}); setState(() {});
} }
} }
class EquipmentProfiles extends InheritedWidget {
final List<EquipmentProfileData> profiles;
const EquipmentProfiles({
required this.profiles,
required super.child,
super.key,
});
static List<EquipmentProfileData> of(BuildContext context, {bool listen = true}) {
if (listen) {
return context.dependOnInheritedWidgetOfExactType<EquipmentProfiles>()!.profiles;
} else {
return context.findAncestorWidgetOfExactType<EquipmentProfiles>()!.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<EquipmentProfile>()!.data;
} else {
return context.findAncestorWidgetOfExactType<EquipmentProfile>()!.data;
}
}
@override
bool updateShouldNotify(EquipmentProfile oldWidget) => true;
}

View file

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/data/models/ev_source_type.dart'; import 'package:lightmeter/data/models/ev_source_type.dart';
import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/environment.dart'; import 'package:lightmeter/environment.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class EvSourceTypeProvider extends StatefulWidget { class EvSourceTypeProvider extends StatefulWidget {
@ -41,9 +42,9 @@ class EvSourceTypeProviderState extends State<EvSourceTypeProvider> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ValueListenableBuilder( return ValueListenableBuilder(
valueListenable: valueListenable, valueListenable: valueListenable,
builder: (_, value, child) => Provider.value( builder: (_, value, child) => InheritedWidgetBase<EvSourceType>(
value: value, data: value,
child: child, child: child!,
), ),
child: widget.child, child: widget.child,
); );

View file

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/data/models/supported_locale.dart'; import 'package:lightmeter/data/models/supported_locale.dart';
import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class SupportedLocaleProvider extends StatefulWidget { class SupportedLocaleProvider extends StatefulWidget {
@ -36,9 +37,9 @@ class SupportedLocaleProviderState extends State<SupportedLocaleProvider> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ValueListenableBuilder( return ValueListenableBuilder(
valueListenable: valueListenable, valueListenable: valueListenable,
builder: (_, value, child) => Provider.value( builder: (_, value, child) => InheritedWidgetBase<SupportedLocale>(
value: value, data: value,
child: child, child: child!,
), ),
child: widget.child, child: widget.child,
); );

View file

@ -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/models/theme_type.dart';
import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/res/dimens.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:material_color_utilities/material_color_utilities.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class ThemeProvider extends StatefulWidget { class ThemeProvider extends StatefulWidget {
final TransitionBuilder? builder; final Widget child;
const ThemeProvider({ const ThemeProvider({
this.builder, required this.child,
super.key, super.key,
}); });
@ -76,8 +77,8 @@ class ThemeProviderState extends State<ThemeProvider> with WidgetsBindingObserve
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ValueListenableBuilder( return ValueListenableBuilder(
valueListenable: _themeTypeNotifier, valueListenable: _themeTypeNotifier,
builder: (_, themeType, __) => Provider.value( builder: (_, themeType, __) => InheritedWidgetBase<ThemeType>(
value: themeType, data: themeType,
child: ValueListenableBuilder( child: ValueListenableBuilder(
valueListenable: _dynamicColorNotifier, valueListenable: _dynamicColorNotifier,
builder: (_, useDynamicColor, __) => _DynamicColorProvider( builder: (_, useDynamicColor, __) => _DynamicColorProvider(
@ -88,7 +89,7 @@ class ThemeProviderState extends State<ThemeProvider> with WidgetsBindingObserve
builder: (_, primaryColor, __) => _ThemeDataProvider( builder: (_, primaryColor, __) => _ThemeDataProvider(
primaryColor: dynamicPrimaryColor ?? primaryColor, primaryColor: dynamicPrimaryColor ?? primaryColor,
brightness: _themeBrightness, brightness: _themeBrightness,
builder: widget.builder, child: widget.child,
), ),
), ),
), ),
@ -154,8 +155,8 @@ class _DynamicColorProvider extends StatelessWidget {
dynamicPrimaryColor = null; dynamicPrimaryColor = null;
state = DynamicColorState.unavailable; state = DynamicColorState.unavailable;
} }
return Provider.value( return InheritedWidgetBase<DynamicColorState>(
value: state, data: state,
child: builder(context, dynamicPrimaryColor), child: builder(context, dynamicPrimaryColor),
); );
}, },
@ -166,19 +167,19 @@ class _DynamicColorProvider extends StatelessWidget {
class _ThemeDataProvider extends StatelessWidget { class _ThemeDataProvider extends StatelessWidget {
final Color primaryColor; final Color primaryColor;
final Brightness brightness; final Brightness brightness;
final TransitionBuilder? builder; final Widget child;
const _ThemeDataProvider({ const _ThemeDataProvider({
required this.primaryColor, required this.primaryColor,
required this.brightness, required this.brightness,
required this.builder, required this.child,
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Provider.value( return InheritedWidgetBase<ThemeData>(
value: _themeFromColorScheme(_colorSchemeFromColor()), data: _themeFromColorScheme(_colorSchemeFromColor()),
builder: builder, child: child,
); );
} }

View file

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/data/models/ev_source_type.dart'; import 'package:lightmeter/data/models/ev_source_type.dart';
import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.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 { class MeteringBottomControls extends StatelessWidget {
final double? ev; final double? ev;
@ -44,7 +44,7 @@ class MeteringBottomControls extends StatelessWidget {
child: IconButton( child: IconButton(
onPressed: onSwitchEvSourceType, onPressed: onSwitchEvSourceType,
icon: Icon( icon: Icon(
context.watch<EvSourceType>() != EvSourceType.camera context.listen<EvSourceType>() != EvSourceType.camera
? Icons.camera_rear ? Icons.camera_rear
: Icons.wb_incandescent, : Icons.wb_incandescent,
), ),

View file

@ -9,6 +9,7 @@ import 'package:lightmeter/providers/metering_screen_layout_provider.dart';
import 'package:lightmeter/res/dimens.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/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/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'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class ReadingsContainer extends StatelessWidget { class ReadingsContainer extends StatelessWidget {
@ -76,7 +77,7 @@ class ReadingsContainer extends StatelessWidget {
Expanded( Expanded(
child: _IsoValuePicker( child: _IsoValuePicker(
selectedValue: iso, selectedValue: iso,
values: EquipmentProfile.of(context).isoValues, values: context.listen<EquipmentProfile>().isoValues,
onChanged: onIsoChanged, onChanged: onIsoChanged,
), ),
), ),
@ -84,7 +85,7 @@ class ReadingsContainer extends StatelessWidget {
Expanded( Expanded(
child: _NdValuePicker( child: _NdValuePicker(
selectedValue: nd, selectedValue: nd,
values: EquipmentProfile.of(context).ndValues, values: context.listen<EquipmentProfile>().ndValues,
onChanged: onNdChanged, onChanged: onNdChanged,
), ),
), ),
@ -107,16 +108,16 @@ class _EquipmentProfilePicker extends StatelessWidget {
return AnimatedDialogPicker<EquipmentProfileData>( return AnimatedDialogPicker<EquipmentProfileData>(
icon: Icons.camera, icon: Icons.camera,
title: S.of(context).equipmentProfile, title: S.of(context).equipmentProfile,
selectedValue: EquipmentProfile.of(context), selectedValue: context.listen<EquipmentProfile>(),
values: EquipmentProfiles.of(context), values: context.listen<EquipmentProfiles>(),
itemTitleBuilder: (_, value) => Text(value.id.isEmpty ? S.of(context).none : value.name), itemTitleBuilder: (_, value) => Text(value.id.isEmpty ? S.of(context).none : value.name),
onChanged: EquipmentProfileProvider.of(context).setProfile, onChanged: EquipmentProfileProvider.of(context).setProfile,
closedChild: ReadingValueContainer.singleValue( closedChild: ReadingValueContainer.singleValue(
value: ReadingValue( value: ReadingValue(
label: S.of(context).equipmentProfile, label: S.of(context).equipmentProfile,
value: EquipmentProfile.of(context).id.isEmpty value: context.listen<EquipmentProfile>().id.isEmpty
? S.of(context).none ? S.of(context).none
: EquipmentProfile.of(context).name, : context.listen<EquipmentProfile>().name,
), ),
), ),
); );

View file

@ -39,7 +39,7 @@ class _MeteringFlowState extends State<MeteringFlow> {
create: (context) => MeteringBloc( create: (context) => MeteringBloc(
context.read<MeteringCommunicationBloc>(), context.read<MeteringCommunicationBloc>(),
context.read<MeteringInteractor>(), context.read<MeteringInteractor>(),
EquipmentProfile.of(context, listen: false), context.get<EquipmentProfile>(),
context.get<StopType>(), context.get<StopType>(),
), ),
), ),

View file

@ -16,22 +16,9 @@ import 'package:lightmeter/screens/metering/state_metering.dart';
import 'package:lightmeter/utils/inherited_generics.dart'; import 'package:lightmeter/utils/inherited_generics.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class MeteringScreen extends StatefulWidget { class MeteringScreen extends StatelessWidget {
const MeteringScreen({super.key}); const MeteringScreen({super.key});
@override
State<MeteringScreen> createState() => _MeteringScreenState();
}
class _MeteringScreenState extends State<MeteringScreen> {
MeteringBloc get _bloc => context.read<MeteringBloc>();
@override
void didChangeDependencies() {
super.didChangeDependencies();
_bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)));
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return _InheritedListeners( return _InheritedListeners(
@ -48,22 +35,23 @@ class _MeteringScreenState extends State<MeteringScreen> {
film: state.film, film: state.film,
iso: state.iso, iso: state.iso,
nd: state.nd, nd: state.nd,
onFilmChanged: (value) => _bloc.add(FilmChangedEvent(value)), onFilmChanged: (value) =>
onIsoChanged: (value) => _bloc.add(IsoChangedEvent(value)), context.read<MeteringBloc>().add(FilmChangedEvent(value)),
onNdChanged: (value) => _bloc.add(NdChangedEvent(value)), onIsoChanged: (value) => context.read<MeteringBloc>().add(IsoChangedEvent(value)),
onNdChanged: (value) => context.read<MeteringBloc>().add(NdChangedEvent(value)),
), ),
), ),
), ),
BlocBuilder<MeteringBloc, MeteringState>( BlocBuilder<MeteringBloc, MeteringState>(
builder: (context, state) => MeteringBottomControlsProvider( builder: (context, state) => MeteringBottomControlsProvider(
ev: state is MeteringDataState ? state.ev : null, ev: state is MeteringDataState ? state.ev : null,
isMetering: state is LoadingState || isMetering:
state is MeteringDataState && state.continuousMetering, state is LoadingState || state is MeteringDataState && state.continuousMetering,
hasError: state is MeteringDataState && state.hasError, hasError: state is MeteringDataState && state.hasError,
onSwitchEvSourceType: context.read<Environment>().hasLightSensor onSwitchEvSourceType: context.read<Environment>().hasLightSensor
? EvSourceTypeProvider.of(context).toggleType ? EvSourceTypeProvider.of(context).toggleType
: null, : null,
onMeasure: () => _bloc.add(const MeasureEvent()), onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
onSettings: () => Navigator.pushNamed(context, 'settings'), onSettings: () => Navigator.pushNamed(context, 'settings'),
), ),
), ),
@ -81,7 +69,11 @@ class _InheritedListeners extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return InheritedWidgetListener<StopType>( return InheritedWidgetListener<EquipmentProfile>(
onDidChangeDependencies: (value) {
context.read<MeteringBloc>().add(EquipmentProfileChangedEvent(value));
},
child: InheritedWidgetListener<StopType>(
onDidChangeDependencies: (value) { onDidChangeDependencies: (value) {
context.read<MeteringBloc>().add(StopTypeChangedEvent(value)); context.read<MeteringBloc>().add(StopTypeChangedEvent(value));
}, },
@ -92,6 +84,7 @@ class _InheritedListeners extends StatelessWidget {
}, },
child: child, child: child,
), ),
),
); );
} }
} }
@ -121,7 +114,7 @@ class _MeteringContainerBuidler extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return context.watch<EvSourceType>() == EvSourceType.camera return context.listen<EvSourceType>() == EvSourceType.camera
? CameraContainerProvider( ? CameraContainerProvider(
fastest: fastest, fastest: fastest,
slowest: slowest, slowest: slowest,

View file

@ -3,7 +3,7 @@ import 'package:lightmeter/data/models/supported_locale.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/supported_locale_provider.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: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 { class LanguageListTile extends StatelessWidget {
const LanguageListTile({super.key}); const LanguageListTile({super.key});
@ -13,14 +13,14 @@ class LanguageListTile extends StatelessWidget {
return ListTile( return ListTile(
leading: const Icon(Icons.language), leading: const Icon(Icons.language),
title: Text(S.of(context).language), title: Text(S.of(context).language),
trailing: Text(context.watch<SupportedLocale>().localizedName), trailing: Text(context.listen<SupportedLocale>().localizedName),
onTap: () { onTap: () {
showDialog<SupportedLocale>( showDialog<SupportedLocale>(
context: context, context: context,
builder: (_) => DialogPicker<SupportedLocale>( builder: (_) => DialogPicker<SupportedLocale>(
icon: Icons.language, icon: Icons.language,
title: S.of(context).chooseLanguage, title: S.of(context).chooseLanguage,
selectedValue: context.read<SupportedLocale>(), selectedValue: context.get<SupportedLocale>(),
values: SupportedLocale.values, values: SupportedLocale.values,
titleAdapter: (context, value) => value.localizedName, titleAdapter: (context, value) => value.localizedName,
), ),

View file

@ -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_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/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/screens/shared/sliver_screen/screen_sliver.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class EquipmentProfilesScreen extends StatefulWidget { class EquipmentProfilesScreen extends StatefulWidget {
@ -18,12 +19,13 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
static const maxProfiles = 5 + 1; // replace with a constant from iap static const maxProfiles = 5 + 1; // replace with a constant from iap
late List<GlobalKey<EquipmentProfileContainerState>> profileContainersKeys = []; late List<GlobalKey<EquipmentProfileContainerState>> profileContainersKeys = [];
int get profilesCount => EquipmentProfiles.of(context).length; int get profilesCount => context.listen<EquipmentProfiles>().length;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
profileContainersKeys = EquipmentProfiles.of(context, listen: false) profileContainersKeys = context
.get<EquipmentProfiles>()
.map((e) => GlobalKey<EquipmentProfileContainerState>(debugLabel: e.id)) .map((e) => GlobalKey<EquipmentProfileContainerState>(debugLabel: e.id))
.toList(); .toList();
} }
@ -56,7 +58,7 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
), ),
child: EquipmentProfileContainer( child: EquipmentProfileContainer(
key: profileContainersKeys[index], key: profileContainersKeys[index],
data: EquipmentProfiles.of(context)[index], data: context.listen<EquipmentProfiles>()[index],
onExpand: () => _keepExpandedAt(index), onExpand: () => _keepExpandedAt(index),
onUpdate: (profileData) => _updateProfileAt(profileData, index), onUpdate: (profileData) => _updateProfileAt(profileData, index),
onDelete: () => _removeProfileAt(index), onDelete: () => _removeProfileAt(index),
@ -87,7 +89,7 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
} }
void _removeProfileAt(int index) { void _removeProfileAt(int index) {
EquipmentProfileProvider.of(context).deleteProfile(EquipmentProfiles.of(context)[index]); EquipmentProfileProvider.of(context).deleteProfile(context.listen<EquipmentProfiles>()[index]);
profileContainersKeys.removeAt(index); profileContainersKeys.removeAt(index);
} }

View file

@ -1,8 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/dynamic_colors_state.dart'; import 'package:lightmeter/data/models/dynamic_colors_state.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/theme_provider.dart'; import 'package:lightmeter/providers/theme_provider.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
class DynamicColorListTile extends StatelessWidget { class DynamicColorListTile extends StatelessWidget {
const DynamicColorListTile({super.key}); const DynamicColorListTile({super.key});
@ -12,7 +12,7 @@ class DynamicColorListTile extends StatelessWidget {
return SwitchListTile( return SwitchListTile(
secondary: const Icon(Icons.colorize), secondary: const Icon(Icons.colorize),
title: Text(S.of(context).dynamicColor), title: Text(S.of(context).dynamicColor),
value: context.watch<DynamicColorState>() == DynamicColorState.enabled, value: context.listen<DynamicColorState>() == DynamicColorState.enabled,
onChanged: ThemeProvider.of(context).enableDynamicColor, onChanged: ThemeProvider.of(context).enableDynamicColor,
); );
} }

View file

@ -1,18 +1,17 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/dynamic_colors_state.dart'; import 'package:lightmeter/data/models/dynamic_colors_state.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/theme_provider.dart'; import 'package:lightmeter/providers/theme_provider.dart';
import 'package:lightmeter/res/dimens.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/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 { class PrimaryColorListTile extends StatelessWidget {
const PrimaryColorListTile({super.key}); const PrimaryColorListTile({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (context.watch<DynamicColorState>() == DynamicColorState.enabled) { if (context.listen<DynamicColorState>() == DynamicColorState.enabled) {
return Opacity( return Opacity(
opacity: Dimens.disabledOpacity, opacity: Dimens.disabledOpacity,
child: IgnorePointer( child: IgnorePointer(

View file

@ -3,7 +3,7 @@ import 'package:lightmeter/data/models/theme_type.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/theme_provider.dart'; import 'package:lightmeter/providers/theme_provider.dart';
import 'package:lightmeter/screens/settings/components/shared/dialog_picker.dart/widget_dialog_picker.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 { class ThemeTypeListTile extends StatelessWidget {
const ThemeTypeListTile({super.key}); const ThemeTypeListTile({super.key});
@ -13,14 +13,14 @@ class ThemeTypeListTile extends StatelessWidget {
return ListTile( return ListTile(
leading: const Icon(Icons.brightness_6), leading: const Icon(Icons.brightness_6),
title: Text(S.of(context).theme), title: Text(S.of(context).theme),
trailing: Text(_typeToString(context, context.watch<ThemeType>())), trailing: Text(_typeToString(context, context.listen<ThemeType>())),
onTap: () { onTap: () {
showDialog<ThemeType>( showDialog<ThemeType>(
context: context, context: context,
builder: (_) => DialogPicker<ThemeType>( builder: (_) => DialogPicker<ThemeType>(
icon: Icons.brightness_6, icon: Icons.brightness_6,
title: S.of(context).chooseTheme, title: S.of(context).chooseTheme,
selectedValue: context.read<ThemeType>(), selectedValue: context.get<ThemeType>(),
values: ThemeType.values, values: ThemeType.values,
titleAdapter: _typeToString, titleAdapter: _typeToString,
), ),

View file

@ -1,12 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/dynamic_colors_state.dart'; import 'package:lightmeter/data/models/dynamic_colors_state.dart';
import 'package:lightmeter/generated/l10n.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/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/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/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/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
class ThemeSettingsSection extends StatelessWidget { class ThemeSettingsSection extends StatelessWidget {
const ThemeSettingsSection({super.key}); const ThemeSettingsSection({super.key});
@ -18,7 +17,7 @@ class ThemeSettingsSection extends StatelessWidget {
children: [ children: [
const ThemeTypeListTile(), const ThemeTypeListTile(),
const PrimaryColorListTile(), const PrimaryColorListTile(),
if (context.read<DynamicColorState>() != DynamicColorState.unavailable) if (context.get<DynamicColorState>() != DynamicColorState.unavailable)
const DynamicColorListTile(), const DynamicColorListTile(),
], ],
); );