feat: auto-refresh widget colors when the theme is change by the user
This commit is contained in:
parent
5966594b44
commit
8488921075
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user