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啥区别

 

 

)

原文地址:https://www.cnblogs.com/pp-pping/p/12188717.html