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