zoukankan      html  css  js  c++  java
  • tabController保活

    代码:

    import 'package:flutter/material.dart';
    class MyhomePage extends StatefulWidget {
    MyhomePage({Key key}) : super(key: key);

    @override
    _MyhomePageState createState() => _MyhomePageState();
    }

    class _MyhomePageState extends State<MyhomePage> with AutomaticKeepAliveClientMixin {

    int _count = 0;
    @override
    bool get wantKeepAlive => true;//方法
    void _inaddCount(){
    setState(() {
    _count ++;
    });
    }

    @override
    Widget build(BuildContext context) {
    return Scaffold(
    body: Center(
    child: Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
    Text('计数'),
    Text('$_count',style: Theme.of(context).textTheme.display2,)

    ],
    ),
    ),
    floatingActionButton: FloatingActionButton(
    onPressed:_inaddCount,
    tooltip: '点击加1',
    child: Icon(Icons.add),
    ),
    );
    }
    }
    总结:
     

    保活—就是保持tabController中的数据不会归零

    继承于AutomaticKeepAliveClientMixin

    //重写wantKeepAlie 方法 并置为true

      bool get wantKeepAlive => true;//方法

    写个内置函数 重写setState()

  • 相关阅读:
    ios lazying load
    ios 单例模式
    ios 消息推送原理
    C#图片闪烁
    C#使窗体不显示在任务栏
    实时监测鼠标是否按下和鼠标坐标
    winfrom窗体的透明度
    C#获取屏幕的宽度和高度
    HDU 5171 GTY's birthday gift 矩阵快速幂
    HDU 5170 GTY's math problem 水题
  • 原文地址:https://www.cnblogs.com/pp-pping/p/12180714.html
Copyright © 2011-2022 走看看