—————————————————————————————————List板块——————————————————————————————————————
List倒叙reversed.toList();
List增加数据
List a=['香蕉','苹果','西瓜'];
a.add('value');
a.addAll(['iterable','123']);拼接数组
a.indexof('苹果')查找数组中的数据在第几位,如果不存在输出-1
a.removie('西瓜')按字符串删除
a.removieAt(2)按索引删除
a.fillRange(1,2,'aaa');将索引从1开始到2结尾改为aaa,也就是将苹果改为aaa
a.insert(1,'aaa')在索引0后面插入aaa
a.insertAll(1,['aaa','bbb']);在索引0后面插入两个索引
a.join(',');转换为字符串 香蕉,苹果,西瓜
字符串转换为数组a.split(',');
forEach方法使用
a.forEach((value){
print("$value");
});
map效果
var b=a.map((value){
return value;
});
print(b);
I/flutter (26639): (1, 2, 3, 4, 5, 6)
where效果
var bb=a.where((value){
return value>5;
});
print(bb);
I/flutter (26639): (6)
any效果
var bc=a.any((value){
return value>5;
});
print(bc);
I/flutter (26639): true
—————————————————————————————————Set板块——————————————————————————————————————
var s=new Set()
s.add('香蕉');
s.add('苹果');
s.add('苹果');//重复值无效果
s.add(["香蕉","苹果","葡萄"]);
效果{香蕉,苹果};
s.toList()后[香蕉,苹果]
set.forEach((value)=>print(value));
—————————————————————————————————Map板块——————————————————————————————————————
Map person={
"name":"张三",
"age":20
};
var m=new Map();
m["name"]="李四";
person.keys 打印出keys值 (name, age)
person.keys.toList() 打印出keys值并数组化 [name, age]
person.values 打印出values值 (张三, 20)
person.keys.toList() 打印出values值并数组化 [张三, 20]
person.addAll({
"work":["敲代码","送外卖"],
"age":160//相同的key会被覆盖掉
});Map添加数据
person.remove("age");//删除对应的key及values值
print(person.containsValue("张三"));判断张三是否存在
map.addAll({
"name":"张三",
"age":1234
});
map.forEach((key, value) {
print("$key--$value");
});
I/flutter (26639): name--张三
I/flutter (26639): age--1234
—————————————————————————————————整体板块——————————————————————————————————————
底部导航条:
bottomNavigationBar:BottomNavigationBar
iconSize: 20,//底部图案大小
fixedColor: Colors.red,//选中的颜色
type: BottomNavigationBarType.fixed,//配置底部可以有多个按钮(超过三个)
onTap(int index){}//用于获取点击的是第几个
currentIndex:0//跳转到指定第几页
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text("首页"),
),
界面刷新
setState(() {
});
点击事件:
onPressed: (){}
返回界面:
Navigator.of(context).pop();
跳转事件//跳转传值
Navigator.of(context).push(
MaterialPageRoute(
builder: (context)=>luyou("我再传值"))//luyou为新界面
);
//第二界面
String name1;
class luyou extends StatefulWidget{
luyou(String name){
name1=name;
}}
命名路由跳转//命名路由传值
在MaterialApp内注册
routes: {
'/home_one':(context)=>home_one(),
'/home_two':(context)=>home_two(),
'/lu':(context)=>luyou("传过去的指"),
}
执行跳转
Navigator.pushNamed(context,'/lu');
清空所有路由跳转到新界面:
Navigator.of(context).pushAndRemoveUntil(
new MaterialPageRoute(builder: (context)=>new myful()),
(route)=>route==null
—————————————————————————————————Text板块——————————————————————————————————————
Text(//Text属性
"文本内容",
textAlign: TextAlign.left,//居左显示,可改为center
overflow: TextOverflow.ellipsis,//文本超出部分用...代替
maxLines: 2,//显示的最大行数
textScaleFactor: 2,//字体按比例放大
style: TextStyle(
fontSize: 16.0,//字体大小
color: Colors.white,//字体颜色
fontWeight: FontWeight.w800,//字体粗细
fontStyle: FontStyle.italic,//字体倾斜
decoration: TextDecoration.lineThrough,//划线
decorationColor: Colors.blue,//划线颜色
decorationStyle: TextDecorationStyle.dashed,//虚线
letterSpacing: 5.0//字体间隔
)
)
—————————————————————————————————Container容器板块——————————————————————————————————————
Container(
width: 200,//宽度
height: 200,//高度
decoration: BoxDecoration(//容器属性盒子
color:Colors.green,//容器颜色(设置背景颜色)
border: Border.all(//边框设置
color: Colors.black,//边框颜色黑色
width: 5),//边框大小
borderRadius: BorderRadius.all(
Radius.circular(20)//绘制圆角150等于直接画圆
)//圆角
),
padding:EdgeInsets.all(20),//内边距
padding: EdgeInsets.fromLTRB(left, top, right, bottom),//上下左右的内边距,不设置就为0
margin: EdgeInsets.all(20),//外边距
transform: Matrix4.translationValues(100, 0, 0),//位移
transform: Matrix4.rotationZ(-0.3),//旋转
transform:Matrix4.diagonal3Values(1.2, 1, 1),//拉伸
alignment: Alignment.bottomCenter,//内部元素底部居中
),
—————————————————————————————————Image图片板块——————————————————————————————————————
本地图片:Image.asset
pubspec.yaml中在uses-material-design: true下面配置图片位置,如下:
assets:
- images/b.webp
- images/c.jpeg
网络图片:Image.network
Image.network(
"https://alpan.51huanqi.cn/d/HQW/电影图片/一条狗的使命2.webp?pw=8601caa430e86dc7",
alignment: Alignment.topLeft,//顶部居左
color: Colors.blue,
colorBlendMode: BlendMode.screen,//混合颜色
fit: BoxFit.cover,//充满容器但不变形
fit:BoxFit.fill//拉伸
fit:BoxFit.contain,//正常大小铺满
repeat: ImageRepeat.repeat,//铺满
),
图片进到圆形
child: ClipOval(//椭圆控件包Image
child: Image.asset('images/b.webp',
fit: BoxFit.cover,
width: 100,
height: 100,
),
),
—————————————————————————————————Listview板块——————————————————————————————————————
ListView(
// padding: EdgeInsets.all(0),
children: <Widget>[
ListTile(
leading: Image.network(url),//左图片
title:Text("hasjidjdijs",//中间上部分文字
style: TextStyle(
fontSize: 20
),),
subtitle: Text("市第三大按键的"),//中间下部分文字
trailing: Image.network(url),//右图片
),
])