2022-10-26 14:39:13 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2023-02-02 13:57:20 +08:00
|
|
|
import 'package:flutter_hbb/common.dart';
|
2022-10-26 14:39:13 +08:00
|
|
|
import 'package:flutter_hbb/main.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
|
|
class RefreshWrapper extends StatefulWidget {
|
|
|
|
final Widget Function(BuildContext context) builder;
|
2023-02-02 13:57:20 +08:00
|
|
|
|
2022-10-26 14:39:13 +08:00
|
|
|
const RefreshWrapper({super.key, required this.builder});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<RefreshWrapper> createState() => RefreshWrapperState();
|
|
|
|
|
|
|
|
static RefreshWrapperState? of(BuildContext context) {
|
|
|
|
final state = context.findAncestorStateOfType<RefreshWrapperState>();
|
|
|
|
if (state == null) {
|
|
|
|
debugPrint(
|
|
|
|
"RefreshWrapperState not exists in this context, perhaps RefreshWrapper is not exists?");
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class RefreshWrapperState extends State<RefreshWrapper> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return widget.builder(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
rebuild() {
|
2023-01-23 22:07:50 +08:00
|
|
|
debugPrint("=====Global State Rebuild (win-${kWindowId ?? 'main'})=====");
|
2022-10-26 14:39:13 +08:00
|
|
|
if (Get.context != null) {
|
|
|
|
(context as Element).visitChildren(_rebuildElement);
|
|
|
|
}
|
2023-02-02 13:57:20 +08:00
|
|
|
// Synchronize the window theme of the system.
|
|
|
|
updateSystemWindowTheme();
|
2022-10-26 14:39:13 +08:00
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// set root tree dirty to trigger global rebuild
|
|
|
|
void _rebuildElement(Element el) {
|
|
|
|
el.markNeedsBuild();
|
|
|
|
el.visitChildren(_rebuildElement);
|
|
|
|
}
|
|
|
|
}
|