feat: auto-refresh widget colors when the theme is change by the user

This commit is contained in:
pml68 2024-03-07 19:58:38 +01:00
parent 5966594b44
commit 8488921075
2 changed files with 20 additions and 0 deletions

View File

@ -248,6 +248,9 @@ public class WidgetTimetableDataProvider implements RemoteViewsService.RemoteVie
}
private void initData() {
// refresh theme
fullTheme = getFullTheme(context);
rday = WidgetTimetable.selectDay(context, appWidgetId, 0, false);
day_subjects.clear();

View File

@ -1,4 +1,20 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:home_widget/home_widget.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
Future<bool?> updateWidget() async {
try {
return HomeWidget.updateWidget(name: 'widget_timetable.WidgetTimetable');
} on PlatformException catch (exception) {
if (kDebugMode) {
print('Error Updating Widget After changeTheme. $exception');
}
}
return false;
}
class ThemeModeObserver extends ChangeNotifier {
ThemeMode _themeMode;
@ -13,6 +29,7 @@ class ThemeModeObserver extends ChangeNotifier {
void changeTheme(ThemeMode mode, {bool updateNavbarColor = true}) {
_themeMode = mode;
_updateNavbarColor = updateNavbarColor;
if (Platform.isAndroid) updateWidget();
notifyListeners();
}
}