page_keep_alive_wrapper.dart 609 B

123456789101112131415161718192021222324
  1. import 'package:flutter/cupertino.dart';
  2. /// 用于PageView的缓存使用的包装组件
  3. class PageKeepAliveWrapper extends StatefulWidget {
  4. final Widget child;
  5. const PageKeepAliveWrapper({super.key, required this.child});
  6. @override
  7. PageKeepAliveWrapperState createState() => PageKeepAliveWrapperState();
  8. }
  9. class PageKeepAliveWrapperState extends State<PageKeepAliveWrapper>
  10. with AutomaticKeepAliveClientMixin {
  11. /// 返回需要缓存
  12. @override
  13. bool get wantKeepAlive => true;
  14. @override
  15. Widget build(BuildContext context) {
  16. super.build(context);
  17. return widget.child;
  18. }
  19. }