2024-04-30 23:38:49 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
2024-09-08 21:21:21 +08:00
|
|
|
class KeepScope extends StatefulWidget {
|
2024-04-30 23:38:49 +08:00
|
|
|
final Widget child;
|
2024-06-03 18:02:05 +08:00
|
|
|
final bool keep;
|
2024-04-30 23:38:49 +08:00
|
|
|
|
2024-09-08 21:21:21 +08:00
|
|
|
const KeepScope({
|
2024-06-03 18:02:05 +08:00
|
|
|
super.key,
|
|
|
|
|
required this.child,
|
|
|
|
|
this.keep = true,
|
|
|
|
|
});
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
@override
|
2024-09-08 21:21:21 +08:00
|
|
|
State<KeepScope> createState() => _KeepContainerState();
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-08 21:21:21 +08:00
|
|
|
class _KeepContainerState extends State<KeepScope>
|
2024-04-30 23:38:49 +08:00
|
|
|
with AutomaticKeepAliveClientMixin {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
super.build(context);
|
|
|
|
|
return widget.child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
2024-06-03 18:02:05 +08:00
|
|
|
bool get wantKeepAlive => widget.keep;
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|