Merge pull request #18 from Nealyang/master

feat:切换tab避免重绘g
This commit is contained in:
Nealyang
2019-01-10 21:33:33 +08:00
committed by GitHub
3 changed files with 21 additions and 4 deletions

View File

@ -20,7 +20,12 @@ class FirstPage extends StatefulWidget {
FirstPageState createState() => new FirstPageState();
}
class FirstPageState extends State<FirstPage> {
class FirstPageState extends State<FirstPage> with AutomaticKeepAliveClientMixin{
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
@override
void initState() {
@ -68,6 +73,7 @@ class FirstPageState extends State<FirstPage> {
@override
Widget build(BuildContext context) {
super.build(context);
return new Column(
children: <Widget>[
new Container(

View File

@ -15,7 +15,7 @@ class CollectionPage extends StatefulWidget {
_CollectionPageState createState() => _CollectionPageState();
}
class _CollectionPageState extends State<CollectionPage> {
class _CollectionPageState extends State<CollectionPage> with AutomaticKeepAliveClientMixin{
_CollectionPageState() {
final eventBus = new EventBus();
ApplicationEvent.event = eventBus;
@ -23,6 +23,11 @@ class _CollectionPageState extends State<CollectionPage> {
CollectionControlModel _collectionControl = new CollectionControlModel();
List<Collection> _collectionList;
ScrollController _scrollController = new ScrollController();
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
@override
void initState() {
super.initState();
@ -102,7 +107,7 @@ class _CollectionPageState extends State<CollectionPage> {
@override
Widget build(BuildContext context) {
print(_collectionList);
super.build(context);
if (_collectionList.length == 0) {
return ListView(
children: <Widget>[

View File

@ -13,7 +13,7 @@ class WidgetPage extends StatefulWidget {
SecondPageState createState() => new SecondPageState(catModel);
}
class SecondPageState extends State<WidgetPage> {
class SecondPageState extends State<WidgetPage> with AutomaticKeepAliveClientMixin{
CatControlModel catModel;
SecondPageState(this.catModel) : super();
@ -23,6 +23,11 @@ class SecondPageState extends State<WidgetPage> {
List<Cat> categories = [];
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
@override
void initState() {
super.initState();
renderCats();
@ -52,6 +57,7 @@ class SecondPageState extends State<WidgetPage> {
@override
Widget build(BuildContext context) {
super.build(context);
if (categories.length == 0) {
return ListView(
children: <Widget>[new Container()],