mirror of
https://github.com/wanghongenpin/proxypin.git
synced 2026-03-19 05:19:47 +08:00
31 lines
866 B
Dart
31 lines
866 B
Dart
import 'package:flutter/material.dart';
|
|
|
|
class KeepAliveWrapper extends StatefulWidget {
|
|
const KeepAliveWrapper({super.key, this.keepAlive = true, required this.child});
|
|
final bool keepAlive;
|
|
final Widget child;
|
|
|
|
@override
|
|
State<KeepAliveWrapper> createState() => _KeepAliveWrapperState();
|
|
}
|
|
|
|
class _KeepAliveWrapperState extends State<KeepAliveWrapper> with AutomaticKeepAliveClientMixin {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
super.build(context);
|
|
return widget.child;
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant KeepAliveWrapper oldWidget) {
|
|
if (oldWidget.keepAlive != widget.keepAlive) {
|
|
// keepAlive 状态需要更新,实现在 AutomaticKeepAliveClientMixin 中
|
|
updateKeepAlive();
|
|
}
|
|
super.didUpdateWidget(oldWidget);
|
|
}
|
|
|
|
@override
|
|
bool get wantKeepAlive => widget.keepAlive && mounted;
|
|
}
|