mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-04 12:42:22 +01:00
Cleanup
This commit is contained in:
@@ -115,7 +115,7 @@ class Exercises extends _$Exercises {
|
||||
final lowerTerm = term.toLowerCase();
|
||||
for (final e in _exercises) {
|
||||
for (final lang in languages) {
|
||||
final title = (e.getTranslation(lang).name ?? '').toLowerCase();
|
||||
final title = e.getTranslation(lang).name.toLowerCase();
|
||||
if (title.contains(lowerTerm)) {
|
||||
out.add(e);
|
||||
break;
|
||||
|
||||
@@ -137,10 +137,10 @@ class PlateCalculatorState {
|
||||
class PlateCalculatorNotifier extends Notifier<PlateCalculatorState> {
|
||||
final _logger = Logger('PlateCalculatorNotifier');
|
||||
|
||||
late SharedPreferencesAsync prefs;
|
||||
late SharedPreferencesAsync _prefs;
|
||||
|
||||
PlateCalculatorNotifier({SharedPreferencesAsync? prefs}) : super() {
|
||||
this.prefs = prefs ?? PreferenceHelper.asyncPref;
|
||||
_prefs = prefs ?? PreferenceHelper.asyncPref;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -151,12 +151,12 @@ class PlateCalculatorNotifier extends Notifier<PlateCalculatorState> {
|
||||
|
||||
Future<void> saveToSharedPrefs() async {
|
||||
_logger.fine('Saving plate data to SharedPreferences');
|
||||
await prefs.setString(PREFS_KEY_PLATES, jsonEncode(state.toJson()));
|
||||
await _prefs.setString(PREFS_KEY_PLATES, jsonEncode(state.toJson()));
|
||||
}
|
||||
|
||||
Future<void> _readDataFromSharedPrefs() async {
|
||||
_logger.fine('Reading plate data from SharedPreferences');
|
||||
final prefsData = await prefs.getString(PREFS_KEY_PLATES);
|
||||
final prefsData = await _prefs.getString(PREFS_KEY_PLATES);
|
||||
|
||||
if (prefsData != null) {
|
||||
try {
|
||||
|
||||
@@ -103,7 +103,7 @@ void main() {
|
||||
await tester.pumpWidget(createWidget(container: container));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final initial = container.read(appSettingsProvider).value!.dashboardItems.visibleWidgets;
|
||||
final initial = container.read(appSettingsProvider).requireValue.dashboardItems.visibleWidgets;
|
||||
expect(initial[0], DashboardWidget.networkInfo);
|
||||
expect(initial[1], DashboardWidget.trophies);
|
||||
expect(initial[2], DashboardWidget.routines);
|
||||
@@ -115,7 +115,7 @@ void main() {
|
||||
await tester.drag(firstHandle, const Offset(0, 100));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final updated = container.read(appSettingsProvider).value!.dashboardItems.visibleWidgets;
|
||||
final updated = container.read(appSettingsProvider).requireValue.dashboardItems.visibleWidgets;
|
||||
expect(updated[0], DashboardWidget.trophies);
|
||||
expect(updated[1], DashboardWidget.routines);
|
||||
expect(updated[2], DashboardWidget.networkInfo);
|
||||
|
||||
@@ -105,7 +105,7 @@ void main() {
|
||||
await container.read(appSettingsProvider.future);
|
||||
await container.read(appSettingsProvider.notifier).setThemeMode(ThemeMode.dark);
|
||||
|
||||
expect(container.read(appSettingsProvider).value!.themeMode, ThemeMode.dark);
|
||||
expect(container.read(appSettingsProvider).requireValue.themeMode, ThemeMode.dark);
|
||||
verify(mockSharedPreferences.setBool(PREFS_USER_DARK_THEME, true)).called(1);
|
||||
});
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ void main() {
|
||||
// Drift returns rows in `Meta.ordering = ['-date']` order.
|
||||
final container = await containerWithImages([image2, image1]);
|
||||
|
||||
final images = container.read(galleryProvider).value!;
|
||||
final images = container.read(galleryProvider).requireValue;
|
||||
expect(images, hasLength(2));
|
||||
expect(images.first.id, 59);
|
||||
verify(mockRepo.watchAllDrift()).called(1);
|
||||
|
||||
@@ -105,7 +105,7 @@ void main() {
|
||||
);
|
||||
final container = await containerWithPlans([plan]);
|
||||
expect(
|
||||
container.read(nutritionProvider.notifier).currentPlan?.id,
|
||||
container.read(nutritionProvider).requireValue.currentPlan?.id,
|
||||
equals(plan.id),
|
||||
);
|
||||
});
|
||||
@@ -127,7 +127,7 @@ void main() {
|
||||
);
|
||||
final container = await containerWithPlans([olderPlan, newerPlan]);
|
||||
expect(
|
||||
container.read(nutritionProvider.notifier).currentPlan?.id,
|
||||
container.read(nutritionProvider).requireValue.currentPlan?.id,
|
||||
equals(newerPlan.id),
|
||||
);
|
||||
});
|
||||
@@ -136,7 +136,7 @@ void main() {
|
||||
group('currentPlan correctly returns the active plan', () {
|
||||
test('no plans available -> null', () async {
|
||||
final container = await containerWithPlans([]);
|
||||
expect(container.read(nutritionProvider.notifier).currentPlan, isNull);
|
||||
expect(container.read(nutritionProvider).requireValue.currentPlan, isNull);
|
||||
});
|
||||
|
||||
test('no active plan -> null', () async {
|
||||
@@ -155,7 +155,7 @@ void main() {
|
||||
),
|
||||
];
|
||||
final container = await containerWithPlans(plans);
|
||||
expect(container.read(nutritionProvider.notifier).currentPlan, isNull);
|
||||
expect(container.read(nutritionProvider).requireValue.currentPlan, isNull);
|
||||
});
|
||||
|
||||
test('active plan exists -> return it', () async {
|
||||
@@ -167,7 +167,7 @@ void main() {
|
||||
);
|
||||
final container = await containerWithPlans([plan]);
|
||||
expect(
|
||||
container.read(nutritionProvider.notifier).currentPlan?.id,
|
||||
container.read(nutritionProvider).requireValue.currentPlan?.id,
|
||||
equals(plan.id),
|
||||
);
|
||||
});
|
||||
@@ -187,7 +187,7 @@ void main() {
|
||||
);
|
||||
final container = await containerWithPlans([plan, inactivePlan]);
|
||||
expect(
|
||||
container.read(nutritionProvider.notifier).currentPlan?.id,
|
||||
container.read(nutritionProvider).requireValue.currentPlan?.id,
|
||||
equals(plan.id),
|
||||
);
|
||||
});
|
||||
@@ -209,7 +209,7 @@ void main() {
|
||||
);
|
||||
final container = await containerWithPlans([olderPlan, newerPlan]);
|
||||
expect(
|
||||
container.read(nutritionProvider.notifier).currentPlan?.id,
|
||||
container.read(nutritionProvider).requireValue.currentPlan?.id,
|
||||
equals(newerPlan.id),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -70,7 +70,7 @@ void main() {
|
||||
);
|
||||
// Explicit listener keeps the provider element alive while we wait for
|
||||
// the Drift-stream emission ([plan1]) to land in state. Required so that
|
||||
// any addMeal call in the test can resolve the plan via findById.
|
||||
// the form widget sees the seeded plan in state when it builds.
|
||||
container.listen(nutritionProvider, (_, _) {});
|
||||
await pumpEventQueue();
|
||||
});
|
||||
|
||||
@@ -151,7 +151,7 @@ void main() {
|
||||
);
|
||||
// Explicit listener keeps the provider element alive while we wait for
|
||||
// the Drift-stream emission ([plan1]) to land in state. Required so that
|
||||
// any addMealItem call in the test can resolve the plan via findById.
|
||||
// the form widget sees the seeded plan in state when it builds.
|
||||
container.listen(nutritionProvider, (_, _) {});
|
||||
await pumpEventQueue();
|
||||
});
|
||||
|
||||
@@ -125,11 +125,11 @@ void main() {
|
||||
final notifier = container.read(appSettingsProvider.notifier);
|
||||
|
||||
await notifier.setWidgetVisible(DashboardWidget.routines, false);
|
||||
var items = container.read(appSettingsProvider).value!.dashboardItems;
|
||||
var items = container.read(appSettingsProvider).requireValue.dashboardItems;
|
||||
expect(items.isWidgetVisible(DashboardWidget.routines), false);
|
||||
|
||||
await notifier.setWidgetVisible(DashboardWidget.routines, true);
|
||||
items = container.read(appSettingsProvider).value!.dashboardItems;
|
||||
items = container.read(appSettingsProvider).requireValue.dashboardItems;
|
||||
expect(items.isWidgetVisible(DashboardWidget.routines), true);
|
||||
});
|
||||
|
||||
@@ -137,14 +137,22 @@ void main() {
|
||||
await container.read(appSettingsProvider.future);
|
||||
final notifier = container.read(appSettingsProvider.notifier);
|
||||
|
||||
final initial = container.read(appSettingsProvider).value!.dashboardItems.visibleWidgets;
|
||||
final initial = container
|
||||
.read(appSettingsProvider)
|
||||
.requireValue
|
||||
.dashboardItems
|
||||
.visibleWidgets;
|
||||
final initialFirst = initial[0];
|
||||
final initialSecond = initial[1];
|
||||
|
||||
// move first to second position (ReorderableListView semantics)
|
||||
await notifier.setDashboardOrder(0, 2);
|
||||
|
||||
final updated = container.read(appSettingsProvider).value!.dashboardItems.visibleWidgets;
|
||||
final updated = container
|
||||
.read(appSettingsProvider)
|
||||
.requireValue
|
||||
.dashboardItems
|
||||
.visibleWidgets;
|
||||
expect(updated[0], initialSecond);
|
||||
expect(updated[1], initialFirst);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user