keep_alive_wrapper.dart 552 B

1234567891011121314151617181920212223242526
  1. import 'package:flutter/material.dart';
  2. /// 页面缓存
  3. class KeepAliveWrapper extends StatefulWidget {
  4. final Widget child;
  5. const KeepAliveWrapper({Key? key, required this.child}) : super(key: key);
  6. @override
  7. _KeepAliveWrapperState createState() => _KeepAliveWrapperState();
  8. }
  9. class _KeepAliveWrapperState extends State<KeepAliveWrapper>
  10. with AutomaticKeepAliveClientMixin {
  11. @override
  12. bool get wantKeepAlive => true;
  13. @override
  14. Widget build(BuildContext context) {
  15. super.build(context);
  16. return widget.child;
  17. }
  18. }