fish_redux 保存TabBarView和PageView的状态

1、自定义KeepAliveWidget

class KeepAliveWidget extends StatefulWidget {
  final Widget child;

  const KeepAliveWidget(this.child);

  @override
  State createState() => KeepAliveState();
}

class KeepAliveState extends State
    with AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    return widget.child;
  }
}

Widget keepAliveWrapper(Widget child) {
  return KeepAliveWidget(child);
}

2、page或者component目录中新建wrapper,返回自定义的KeepAliveWidget

fish_redux 保存TabBarView和PageView的状态_第1张图片
Jietu20190705-175452.jpg
import 'package:flutter/material.dart';
import 'package:lib_flutter/component/widget/keep_alive_widget.dart';

Widget xxxPageWrapper(Widget widget) {
  return KeepAliveWidget(widget);
}

3、在page中使用wrapper

import 'package:fish_redux/fish_redux.dart';

import 'effect.dart';
import 'reducer.dart';
import 'state.dart';
import 'view.dart';
import 'wrapper.dart';

class xxxPage extends Page> {
  TownLinePage()
      : super(
          wrapper: xxxxPageWrapper,
          initState: initState,
          effect: buildEffect(),
          reducer: buildReducer(),
          view: buildView,
          dependencies: Dependencies(
              adapter: null, slots: >{}),
          middleware: >[],
        );

}

4、没了

你可能感兴趣的:(fish_redux 保存TabBarView和PageView的状态)