Compare commits

..

No commits in common. "61620acf9787eace4e758bb8890a177c31b66ce1" and "5aa6dccd3cc14bb69bceb2633892cfcfdb59659b" have entirely different histories.

7 changed files with 58 additions and 445 deletions

View file

@ -1,8 +1,5 @@
<img src="resources/social_preview.png" width="100%" />
![](https://github.com/vodemn/m3_lightmeter/actions/workflows/pr_check.yml/badge.svg)
![](https://github.com/vodemn/m3_lightmeter/actions/workflows/create_release.yml/badge.svg)
# Table of contents
- [Table of contents](#table-of-contents)

View file

@ -30,23 +30,20 @@ class ApplicationWrapper extends StatelessWidget {
builder: (_, snapshot) {
if (snapshot.data != null) {
final iapService = IAPStorageService(snapshot.data![0] as SharedPreferences);
final userPreferencesService = UserPreferencesService(snapshot.data![0] as SharedPreferences);
final hasLightSensor = snapshot.data![1] as bool;
return ServicesProvider(
caffeineService: const CaffeineService(),
environment: env.copyWith(hasLightSensor: hasLightSensor),
environment: env.copyWith(hasLightSensor: snapshot.data![1] as bool),
hapticsService: const HapticsService(),
lightSensorService: const LightSensorService(LocalPlatform()),
permissionsService: const PermissionsService(),
userPreferencesService: userPreferencesService,
userPreferencesService:
UserPreferencesService(snapshot.data![0] as SharedPreferences),
volumeEventsService: const VolumeEventsService(LocalPlatform()),
child: EquipmentProfileProvider(
storageService: iapService,
child: FilmsProvider(
storageService: iapService,
child: UserPreferencesProvider(
hasLightSensor: hasLightSensor,
userPreferencesService: userPreferencesService,
child: child,
),
),

View file

@ -7,7 +7,6 @@ import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/data/volume_events_service.dart';
import 'package:lightmeter/environment.dart';
// coverage:ignore-start
class ServicesProvider extends InheritedWidget {
final CaffeineService caffeineService;
final Environment environment;
@ -35,4 +34,3 @@ class ServicesProvider extends InheritedWidget {
@override
bool updateShouldNotify(ServicesProvider oldWidget) => false;
}
// coverage:ignore-end

View file

@ -8,20 +8,14 @@ import 'package:lightmeter/data/models/supported_locale.dart';
import 'package:lightmeter/data/models/theme_type.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/res/theme.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class UserPreferencesProvider extends StatefulWidget {
final bool hasLightSensor;
final UserPreferencesService userPreferencesService;
final Widget child;
const UserPreferencesProvider({
required this.hasLightSensor,
required this.userPreferencesService,
required this.child,
super.key,
});
const UserPreferencesProvider({required this.child, super.key});
static _UserPreferencesProviderState of(BuildContext context) {
return context.findAncestorStateOfType<_UserPreferencesProviderState>()!;
@ -44,7 +38,8 @@ class UserPreferencesProvider extends StatefulWidget {
}
static bool meteringScreenFeatureOf(BuildContext context, MeteringScreenLayoutFeature feature) {
return InheritedModel.inheritFrom<_MeteringScreenLayoutModel>(context, aspect: feature)!.data[feature]!;
return InheritedModel.inheritFrom<_MeteringScreenLayoutModel>(context, aspect: feature)!
.data[feature]!;
}
static StopType stopTypeOf(BuildContext context) {
@ -70,20 +65,28 @@ class UserPreferencesProvider extends StatefulWidget {
State<UserPreferencesProvider> createState() => _UserPreferencesProviderState();
}
class _UserPreferencesProviderState extends State<UserPreferencesProvider> with WidgetsBindingObserver {
late EvSourceType _evSourceType;
late StopType _stopType = widget.userPreferencesService.stopType;
late MeteringScreenLayoutConfig _meteringScreenLayout = widget.userPreferencesService.meteringScreenLayout;
late SupportedLocale _locale = widget.userPreferencesService.locale;
late ThemeType _themeType = widget.userPreferencesService.themeType;
late Color _primaryColor = widget.userPreferencesService.primaryColor;
late bool _dynamicColor = widget.userPreferencesService.dynamicColor;
class _UserPreferencesProviderState extends State<UserPreferencesProvider>
with WidgetsBindingObserver {
UserPreferencesService get userPreferencesService =>
ServicesProvider.of(context).userPreferencesService;
late bool dynamicColor = userPreferencesService.dynamicColor;
late EvSourceType evSourceType;
late MeteringScreenLayoutConfig meteringScreenLayout =
userPreferencesService.meteringScreenLayout;
late Color primaryColor = userPreferencesService.primaryColor;
late StopType stopType = userPreferencesService.stopType;
late SupportedLocale locale = userPreferencesService.locale;
late ThemeType themeType = userPreferencesService.themeType;
@override
void initState() {
super.initState();
_evSourceType = widget.userPreferencesService.evSourceType;
_evSourceType = _evSourceType == EvSourceType.sensor && !widget.hasLightSensor ? EvSourceType.camera : _evSourceType;
evSourceType = userPreferencesService.evSourceType;
evSourceType = evSourceType == EvSourceType.sensor &&
!ServicesProvider.of(context).environment.hasLightSensor
? EvSourceType.camera
: evSourceType;
WidgetsBinding.instance.addObserver(this);
}
@ -106,8 +109,9 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider> with
late final DynamicColorState state;
late final Color? dynamicPrimaryColor;
if (lightDynamic != null && darkDynamic != null) {
if (_dynamicColor) {
dynamicPrimaryColor = (_themeBrightness == Brightness.light ? lightDynamic : darkDynamic).primary;
if (dynamicColor) {
dynamicPrimaryColor =
(_themeBrightness == Brightness.light ? lightDynamic : darkDynamic).primary;
state = DynamicColorState.enabled;
} else {
dynamicPrimaryColor = null;
@ -120,13 +124,13 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider> with
return _UserPreferencesModel(
brightness: _themeBrightness,
dynamicColorState: state,
evSourceType: _evSourceType,
locale: _locale,
primaryColor: dynamicPrimaryColor ?? _primaryColor,
stopType: _stopType,
themeType: _themeType,
evSourceType: evSourceType,
locale: locale,
primaryColor: dynamicPrimaryColor ?? primaryColor,
stopType: stopType,
themeType: themeType,
child: _MeteringScreenLayoutModel(
data: _meteringScreenLayout,
data: meteringScreenLayout,
child: widget.child,
),
);
@ -136,65 +140,65 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider> with
void enableDynamicColor(bool enable) {
setState(() {
_dynamicColor = enable;
dynamicColor = enable;
});
widget.userPreferencesService.dynamicColor = enable;
userPreferencesService.dynamicColor = enable;
}
void toggleEvSourceType() {
if (!widget.hasLightSensor) {
if (!ServicesProvider.of(context).environment.hasLightSensor) {
return;
}
setState(() {
switch (_evSourceType) {
switch (evSourceType) {
case EvSourceType.camera:
_evSourceType = EvSourceType.sensor;
evSourceType = EvSourceType.sensor;
case EvSourceType.sensor:
_evSourceType = EvSourceType.camera;
evSourceType = EvSourceType.camera;
}
});
widget.userPreferencesService.evSourceType = _evSourceType;
userPreferencesService.evSourceType = evSourceType;
}
void setLocale(SupportedLocale locale) {
S.load(Locale(locale.intlName)).then((value) {
setState(() {
_locale = locale;
this.locale = locale;
});
widget.userPreferencesService.locale = locale;
userPreferencesService.locale = locale;
});
}
void setMeteringScreenLayout(MeteringScreenLayoutConfig config) {
setState(() {
_meteringScreenLayout = config;
meteringScreenLayout = config;
});
widget.userPreferencesService.meteringScreenLayout = _meteringScreenLayout;
userPreferencesService.meteringScreenLayout = meteringScreenLayout;
}
void setPrimaryColor(Color primaryColor) {
setState(() {
_primaryColor = primaryColor;
this.primaryColor = primaryColor;
});
widget.userPreferencesService.primaryColor = primaryColor;
userPreferencesService.primaryColor = primaryColor;
}
void setStopType(StopType stopType) {
setState(() {
_stopType = stopType;
this.stopType = stopType;
});
widget.userPreferencesService.stopType = stopType;
userPreferencesService.stopType = stopType;
}
void setThemeType(ThemeType themeType) {
setState(() {
_themeType = themeType;
this.themeType = themeType;
});
widget.userPreferencesService.themeType = themeType;
userPreferencesService.themeType = themeType;
}
Brightness get _themeBrightness {
switch (_themeType) {
switch (themeType) {
case ThemeType.light:
return Brightness.light;
case ThemeType.dark:
@ -254,7 +258,8 @@ class _UserPreferencesModel extends InheritedModel<_Aspect> {
_UserPreferencesModel oldWidget,
Set<_Aspect> dependencies,
) {
return (dependencies.contains(_Aspect.dynamicColorState) && dynamicColorState != oldWidget.dynamicColorState) ||
return (dependencies.contains(_Aspect.dynamicColorState) &&
dynamicColorState != oldWidget.dynamicColorState) ||
(dependencies.contains(_Aspect.evSourceType) && evSourceType != oldWidget.evSourceType) ||
(dependencies.contains(_Aspect.locale) && locale != oldWidget.locale) ||
(dependencies.contains(_Aspect.stopType) && stopType != oldWidget.stopType) ||

View file

@ -17,7 +17,10 @@ class SelectableInheritedModel<T> extends InheritedModel<SelectableAspect> {
bool updateShouldNotify(SelectableInheritedModel oldWidget) => true;
@override
bool updateShouldNotifyDependent(SelectableInheritedModel oldWidget, Set<SelectableAspect> dependencies) {
bool updateShouldNotifyDependent(
SelectableInheritedModel oldWidget,
Set<SelectableAspect> dependencies,
) {
if (dependencies.contains(SelectableAspect.list)) {
return true;
} else if (dependencies.contains(SelectableAspect.selected)) {

View file

@ -110,9 +110,6 @@ void main() {
expectFilmsCount(mockFilms.length + 1);
expectFilmsInUseCount(mockFilms.length + 1);
expectSelectedFilmName('');
verify(() => mockIAPStorageService.filmsInUse = mockFilms.skip(0).toList()).called(1);
verifyNever(() => mockIAPStorageService.selectedFilm = const Film.other());
},
);
@ -134,9 +131,6 @@ void main() {
expectFilmsCount(mockFilms.length + 1);
expectFilmsInUseCount(mockFilms.length + 1);
expectSelectedFilmName(mockFilms.first.name);
verifyNever(() => mockIAPStorageService.filmsInUse = any<List<Film>>());
verify(() => mockIAPStorageService.selectedFilm = mockFilms.first).called(1);
},
);
@ -154,7 +148,6 @@ void main() {
expectFilmsInUseCount(1);
expectSelectedFilmName('');
verifyNever(() => mockIAPStorageService.filmsInUse = any<List<Film>>());
verify(() => mockIAPStorageService.selectedFilm = const Film.other()).called(1);
},
);
@ -170,7 +163,6 @@ void main() {
expectFilmsInUseCount(1);
expectSelectedFilmName('');
verifyNever(() => mockIAPStorageService.filmsInUse = any<List<Film>>());
verifyNever(() => mockIAPStorageService.selectedFilm = const Film.other());
},
);
@ -195,9 +187,6 @@ void main() {
expectFilmsCount(mockFilms.length + 1);
expectFilmsInUseCount((mockFilms.length - 1) + 1);
expectSelectedFilmName('');
verify(() => mockIAPStorageService.filmsInUse = mockFilms.skip(1).toList()).called(1);
verify(() => mockIAPStorageService.selectedFilm = const Film.other()).called(1);
},
);
},

View file

@ -1,376 +0,0 @@
import 'package:dynamic_color/test_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
import 'package:lightmeter/data/models/ev_source_type.dart';
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
import 'package:lightmeter/data/models/supported_locale.dart';
import 'package:lightmeter/data/models/theme_type.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart';
import 'package:lightmeter/res/theme.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:material_color_utilities/material_color_utilities.dart';
import 'package:mocktail/mocktail.dart';
class _MockUserPreferencesService extends Mock implements UserPreferencesService {}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late _MockUserPreferencesService mockUserPreferencesService;
setUpAll(() {
mockUserPreferencesService = _MockUserPreferencesService();
});
setUp(() {
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.camera);
when(() => mockUserPreferencesService.stopType).thenReturn(StopType.third);
when(() => mockUserPreferencesService.meteringScreenLayout).thenReturn({
MeteringScreenLayoutFeature.extremeExposurePairs: true,
MeteringScreenLayoutFeature.filmPicker: true,
MeteringScreenLayoutFeature.equipmentProfiles: true,
MeteringScreenLayoutFeature.histogram: true,
});
when(() => mockUserPreferencesService.locale).thenReturn(SupportedLocale.en);
when(() => mockUserPreferencesService.themeType).thenReturn(ThemeType.light);
when(() => mockUserPreferencesService.primaryColor).thenReturn(primaryColorsList[5]);
when(() => mockUserPreferencesService.dynamicColor).thenReturn(false);
});
tearDown(() {
reset(mockUserPreferencesService);
});
Future<void> pumpTestWidget(
WidgetTester tester, {
bool hasLightSensor = true,
required WidgetBuilder builder,
}) async {
await tester.pumpWidget(
UserPreferencesProvider(
hasLightSensor: hasLightSensor,
userPreferencesService: mockUserPreferencesService,
child: _Application(builder: builder),
),
);
}
group('[evSourceType]', () {
Future<void> pumpEvTestApplication(WidgetTester tester, {required bool hasLightSensor}) async {
await pumpTestWidget(
tester,
hasLightSensor: hasLightSensor,
builder: (context) => Column(
children: [
Text('EV source type: ${UserPreferencesProvider.evSourceTypeOf(context)}'),
ElevatedButton(
onPressed: UserPreferencesProvider.of(context).toggleEvSourceType,
child: const Text('toggleEvSourceType'),
),
],
),
);
}
void expectEvSource(EvSourceType evSourceType) {
expect(find.text("EV source type: $evSourceType"), findsOneWidget);
}
testWidgets(
'Init evSourceType when has sensor & stored sensor',
(tester) async {
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor);
await pumpEvTestApplication(tester, hasLightSensor: true);
expectEvSource(EvSourceType.sensor);
},
);
testWidgets(
'Init evSourceType when has no sensor & stored camera',
(tester) async {
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.camera);
await pumpEvTestApplication(tester, hasLightSensor: false);
expectEvSource(EvSourceType.camera);
},
);
testWidgets(
'Init evSourceType when has no sensor & stored sensor -> Reset to camera',
(tester) async {
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor);
await pumpEvTestApplication(tester, hasLightSensor: false);
expectEvSource(EvSourceType.camera);
},
);
testWidgets(
'Try toggleEvSourceType() when has no sensor',
(tester) async {
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.camera);
await pumpEvTestApplication(tester, hasLightSensor: false);
await tester.tap(find.text('toggleEvSourceType'));
await tester.pumpAndSettle();
verifyNever(() => mockUserPreferencesService.evSourceType = EvSourceType.sensor);
},
);
testWidgets(
'Try toggleEvSourceType() when has sensor',
(tester) async {
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.camera);
await pumpEvTestApplication(tester, hasLightSensor: true);
await tester.tap(find.text('toggleEvSourceType'));
await tester.pumpAndSettle();
expectEvSource(EvSourceType.sensor);
verify(() => mockUserPreferencesService.evSourceType = EvSourceType.sensor).called(1);
await tester.tap(find.text('toggleEvSourceType'));
await tester.pumpAndSettle();
expectEvSource(EvSourceType.camera);
verify(() => mockUserPreferencesService.evSourceType = EvSourceType.camera).called(1);
},
);
});
testWidgets(
'Set different stop type',
(tester) async {
when(() => mockUserPreferencesService.stopType).thenReturn(StopType.third);
await pumpTestWidget(
tester,
builder: (context) => Column(
children: [
Text('Stop type: ${UserPreferencesProvider.stopTypeOf(context)}'),
ElevatedButton(
onPressed: () => UserPreferencesProvider.of(context).setStopType(StopType.full),
child: const Text('setStopType'),
),
],
),
);
expect(find.text("Stop type: ${StopType.third}"), findsOneWidget);
await tester.tap(find.text('setStopType'));
await tester.pumpAndSettle();
expect(find.text("Stop type: ${StopType.full}"), findsOneWidget);
verify(() => mockUserPreferencesService.stopType = StopType.full).called(1);
},
);
testWidgets(
'Set metering screen layout config',
(tester) async {
await pumpTestWidget(
tester,
builder: (context) {
final config = UserPreferencesProvider.meteringScreenConfigOf(context);
return Column(
children: [
...List.generate(
config.length,
(index) => Text('${config.keys.toList()[index]}: ${config.values.toList()[index]}'),
),
...List.generate(
MeteringScreenLayoutFeature.values.length,
(index) => Text(
'${MeteringScreenLayoutFeature.values[index]}: ${UserPreferencesProvider.meteringScreenFeatureOf(context, MeteringScreenLayoutFeature.values[index])}',
),
),
ElevatedButton(
onPressed: () => UserPreferencesProvider.of(context).setMeteringScreenLayout({
MeteringScreenLayoutFeature.equipmentProfiles: true,
MeteringScreenLayoutFeature.extremeExposurePairs: false,
MeteringScreenLayoutFeature.filmPicker: false,
MeteringScreenLayoutFeature.histogram: true,
}),
child: const Text(''),
),
],
);
},
);
// Match `findsNWidgets(2)` to verify that `meteringScreenFeatureOf` specific results are the same as the whole config
expect(find.text("${MeteringScreenLayoutFeature.equipmentProfiles}: true"), findsNWidgets(2));
expect(find.text("${MeteringScreenLayoutFeature.extremeExposurePairs}: true"), findsNWidgets(2));
expect(find.text("${MeteringScreenLayoutFeature.filmPicker}: true"), findsNWidgets(2));
expect(find.text("${MeteringScreenLayoutFeature.histogram}: true"), findsNWidgets(2));
await tester.tap(find.byType(ElevatedButton));
await tester.pumpAndSettle();
expect(find.text("${MeteringScreenLayoutFeature.equipmentProfiles}: true"), findsNWidgets(2));
expect(find.text("${MeteringScreenLayoutFeature.extremeExposurePairs}: false"), findsNWidgets(2));
expect(find.text("${MeteringScreenLayoutFeature.filmPicker}: false"), findsNWidgets(2));
expect(find.text("${MeteringScreenLayoutFeature.histogram}: true"), findsNWidgets(2));
verify(
() => mockUserPreferencesService.meteringScreenLayout = {
MeteringScreenLayoutFeature.extremeExposurePairs: false,
MeteringScreenLayoutFeature.filmPicker: false,
MeteringScreenLayoutFeature.equipmentProfiles: true,
MeteringScreenLayoutFeature.histogram: true,
},
).called(1);
},
);
testWidgets(
'Set different locale',
(tester) async {
when(() => mockUserPreferencesService.locale).thenReturn(SupportedLocale.en);
await pumpTestWidget(
tester,
builder: (context) => ElevatedButton(
onPressed: () => UserPreferencesProvider.of(context).setLocale(SupportedLocale.fr),
child: Text('${UserPreferencesProvider.localeOf(context)}'),
),
);
expect(find.text("${SupportedLocale.en}"), findsOneWidget);
await tester.tap(find.text("${SupportedLocale.en}"));
await tester.pumpAndSettle();
expect(find.text("${SupportedLocale.fr}"), findsOneWidget);
verify(() => mockUserPreferencesService.locale = SupportedLocale.fr).called(1);
},
);
group('[theme]', () {
testWidgets(
'Set dark theme type',
(tester) async {
when(() => mockUserPreferencesService.themeType).thenReturn(ThemeType.light);
await pumpTestWidget(
tester,
builder: (context) => Column(
children: [
ElevatedButton(
onPressed: () => UserPreferencesProvider.of(context).setThemeType(ThemeType.dark),
child: Text('${UserPreferencesProvider.themeTypeOf(context)}'),
),
Text('${Theme.of(context).colorScheme.brightness}')
],
),
);
expect(find.text("${ThemeType.light}"), findsOneWidget);
expect(find.text("${Brightness.light}"), findsOneWidget);
await tester.tap(find.text("${ThemeType.light}"));
await tester.pumpAndSettle();
expect(find.text("${ThemeType.dark}"), findsOneWidget);
expect(find.text("${Brightness.dark}"), findsOneWidget);
verify(() => mockUserPreferencesService.themeType = ThemeType.dark).called(1);
},
);
testWidgets(
'Set systemDefault theme type and toggle platform brightness',
(tester) async {
when(() => mockUserPreferencesService.themeType).thenReturn(ThemeType.light);
await pumpTestWidget(
tester,
builder: (context) => Column(
children: [
ElevatedButton(
onPressed: () => UserPreferencesProvider.of(context).setThemeType(ThemeType.systemDefault),
child: Text('${UserPreferencesProvider.themeTypeOf(context)}'),
),
Text('${Theme.of(context).colorScheme.brightness}')
],
),
);
TestWidgetsFlutterBinding.instance.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
expect(find.text("${ThemeType.light}"), findsOneWidget);
expect(find.text("${Brightness.light}"), findsOneWidget);
await tester.tap(find.text("${ThemeType.light}"));
await tester.pumpAndSettle();
expect(find.text("${ThemeType.systemDefault}"), findsOneWidget);
expect(find.text("${Brightness.dark}"), findsOneWidget);
verify(() => mockUserPreferencesService.themeType = ThemeType.systemDefault).called(1);
TestWidgetsFlutterBinding.instance.platformDispatcher.platformBrightnessTestValue = Brightness.light;
await tester.pumpAndSettle();
expect(find.text("${ThemeType.systemDefault}"), findsOneWidget);
expect(find.text("${Brightness.light}"), findsOneWidget);
},
);
testWidgets(
'Set primary color',
(tester) async {
when(() => mockUserPreferencesService.primaryColor).thenReturn(primaryColorsList[5]);
await pumpTestWidget(
tester,
builder: (context) => ElevatedButton(
onPressed: () => UserPreferencesProvider.of(context).setPrimaryColor(primaryColorsList[7]),
child: Text('${UserPreferencesProvider.themeOf(context).primaryColor}'),
),
);
expect(find.text("${primaryColorsList[5]}"), findsOneWidget);
await tester.tap(find.text("${primaryColorsList[5]}"));
await tester.pumpAndSettle();
expect(find.text("${primaryColorsList[7]}"), findsOneWidget);
verify(() => mockUserPreferencesService.primaryColor = primaryColorsList[7]).called(1);
},
);
testWidgets(
'Dynamic colors not available',
(tester) async {
when(() => mockUserPreferencesService.dynamicColor).thenReturn(true);
await pumpTestWidget(
tester,
builder: (context) => ElevatedButton(
onPressed: () => UserPreferencesProvider.of(context).enableDynamicColor(false),
child: Text('${UserPreferencesProvider.dynamicColorStateOf(context)}'),
),
);
await tester.pumpAndSettle();
expect(
find.text("${DynamicColorState.unavailable}"),
findsOneWidget,
reason:
"Even though dynamic colors usage is enabled, the core palette can be unavailable. Therefore `DynamicColorState` is also unavailable.",
);
},
);
testWidgets(
'Toggle dynamic color state',
(tester) async {
DynamicColorTestingUtils.setMockDynamicColors(corePalette: CorePalette.of(0xffffffff));
when(() => mockUserPreferencesService.dynamicColor).thenReturn(true);
await pumpTestWidget(
tester,
builder: (context) => ElevatedButton(
onPressed: () => UserPreferencesProvider.of(context).enableDynamicColor(false),
child: Text('${UserPreferencesProvider.dynamicColorStateOf(context)}'),
),
);
await tester.pumpAndSettle();
expect(find.text("${DynamicColorState.enabled}"), findsOneWidget);
await tester.tap(find.text("${DynamicColorState.enabled}"));
await tester.pumpAndSettle();
expect(find.text("${DynamicColorState.disabled}"), findsOneWidget);
verify(() => mockUserPreferencesService.dynamicColor = false).called(1);
},
);
});
}
class _Application extends StatelessWidget {
final WidgetBuilder builder;
const _Application({required this.builder});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: UserPreferencesProvider.themeOf(context),
home: Scaffold(body: Center(child: Builder(builder: builder))),
);
}
}