zoukankan      html  css  js  c++  java
  • warp 流式布局

    代码:

    import 'package:flutter/material.dart';

    class WarpDemo extends StatefulWidget {
    WarpDemo({Key key}) : super(key: key);

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

    class _WarpDemoState extends State<WarpDemo> {

    List<Widget> demoList;

    @override
    void initState() {

    super.initState();
    demoList = List<Widget>()..add(buildAddButton());//初始化
    }
    @override
    Widget build(BuildContext context) {
    final width = MediaQuery.of(context).size.width;//屏幕宽
    final height = MediaQuery.of(context).size.height;//屏幕高
    return Scaffold(
    appBar: AppBar(
    title: Text('流式布局'),
     
    ),
    body: Center(
    child: Opacity(opacity: 0.8,child:Container(
    width,
    height: height/2,
    color: Colors.grey,
    child: Wrap(
    children: demoList,
    spacing: 26.0,//间距
    ),
    ),),//透明
    ),
    );
    }


    Widget buildAddButton(){//也算是方法其实我更觉得是个全局变量 返回widget的方法
    return GestureDetector(//手势识别
    onTap: (){
    if (demoList.length < 9) {
    setState(() {//
    demoList.insert(demoList.length - 1, buildPhoto());//在demoList.length - 1 插入元素buildPhoto() //集合改变 在这里
    });
     
    }
    },
    child: Padding(
    padding: const EdgeInsets.all(10.0),
    child: Container(
    80.0,
    height: 80.0,
    color: Colors.greenAccent,
    child: Icon(Icons.add),
    ),
    ),
    );

     
    }

    Widget buildPhoto (){
    return Padding(
    padding: const EdgeInsets.all(10.0),
    child: Container(
    80.0,
    height: 80.0,
    color: Colors.orange,
    child: Center(
    child: Text('照片'),
    ),
    ),
    );
    }

    }
    总结:

    //wrap 流式布局

     

    Wrap(

    children:xx,//xx 数据集合

     

    )

     

    xx.inser(index,value)//xx 数据集合, index 在第index个位置 添加数据为value,这个和OC 不一样,flutter inser语法是先修改元素后扩充集合。

     

    padding(//????还不明白这个是不是类似于View 如果是 那和 Contain啥区别

     

     

    )

  • 相关阅读:
    python爬虫系列之爬取多页gif图像
    python连续爬取多个网页的图片分别保存到不同的文件夹
    python多线程同步
    python多线程简单例子
    python定时器爬取豆瓣音乐Top榜歌名
    python模拟Get请求保存网易歌曲的url
    python使用get在百度搜索并保存第一页搜索结果
    python爬取某个网页的图片-如百度贴吧
    完全揭秘log file sync等待事件-转自itpub
    两表关联更新
  • 原文地址:https://www.cnblogs.com/pp-pping/p/12188717.html
Copyright © 2011-2022 走看看