Opacity Widget

一般情况下,要移除界面中的某和控件只需要将控件代码删除即可,但是如果希望控件隐藏,但是控件之间占的位置依然保留,就需要使用Opacity来进行包裹.
并且还可以使用AnimatedOpacity添加动画,只需要加一个时长,在重新渲染时就会有一个渲染动画.是不是很酷呢.

import 'package:flutter/material.dart';

class GoogleOpacity extends StatefulWidget {
  @override
  GoogleOpacityState createState() => new GoogleOpacityState();
}

class GoogleOpacityState extends State<GoogleOpacity> {
  double _opacity = 1.0;

  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        Column(
          children: <Widget>[
            Container(
              width: 100.0,
              height: 100.0,
              color: Colors.red,
            ),
            Container(
              width: 100.0,
              height: 100.0,
              color: Colors.green,
            ),
            Container(
              width: 100.0,
              height: 100.0,
              color: Colors.blue,
            ),
          ],
        ),
        Column(
          children: <Widget>[
            Container(
              width: 100.0,
              height: 100.0,
              color: Colors.blue,
            ),
            Opacity(
              opacity: 0.0,
              child: Container(
                width: 100.0,
                height: 100.0,
                color: Colors.green,
              ),
            ),
            Container(
              width: 100.0,
              height: 100.0,
              color: Colors.red,
            ),
          ],
        ),
        Stack(
          children: <Widget>[
            Container(
              width: 200.0,
              height: 200.0,
              child: Image.network(
                  'http://img2.imgtn.bdimg.com/it/u=2755523882,2215399258&fm=200&gp=0.jpg'),
            ),
            AnimatedOpacity(
              duration: Duration(seconds: 1),
              opacity: _opacity,
              child: Container(
                width: 200.0,
                height: 200.0,
                color: Colors.blue,
              ),
            ),
          ],
        ),
      ],
    );
  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    Future.delayed(Duration(seconds: 1), (){
      setState(() {
        _opacity = 0.0;
      });
    });
  }
}

我的博客
代码github

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,295评论 4 61
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,171评论 1 32
  • chapter1: 老公:你听说伦敦恐怖分子事件了吗?(埋首于当天的新报纸) 老婆:哦,你说龙腾铜火锅子啊,倒是吃...
    玫苑姑娘阅读 732评论 0 1
  • ndk 配置及使用 参考这个文章练习使用了一下ndk,基础的搭建这个博客说的很详细了,我就简单写一下中间可能没注意...
    Jasmine_gao阅读 10,974评论 0 0
  • 这趟车要足足开十八个小时才能到达魂牵梦萦的目的地,想到这段无聊又漫长的行程,不禁暗自后悔不该选择火车。...
    大脸猫的自留地阅读 444评论 0 1