flutter 常用的一些知识 ,下次用到直接过来获取不用搜索
1、屏幕尺寸和屏幕方向获取
Size screenSize = MediaQuery.of(context).size;
Orientation orientation = MediaQuery.of(context).orientation;
print('[MediaQuery width]: ${screenSize.width.toStringAsFixed(2)}\n\n' +
'[MediaQuery orientation]: ${screenSize.height.toStringAsFixed(2)}');
2、Flutter 页面切换
Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext ctx) {
return Page2(); //跳转
}
3.页面退出
Navigator.of(context).pop();
//打开Screen4页面,并销毁当前页
Navigator.of(context).pushReplacementNamed('/screen4');
4、CupertinoButton
CupertinoButton(
color: Colors.blue,
child: Text('Show AlertDialog'),
onPressed: () {})
5、页面传参
WaterPage({Key key, this.id}) :super(key: key);
6、背景渐变色
decoration:
BoxDecoration(
gradient: LinearGradient(colors: [
Color.fromARGB(255, 66, 159, 227),
Color.fromARGB(255, 50, 104, 175)
]), // 渐变色
orderRadius: BorderRadius.circular(35)),
7 、row位置控制
mainAxisAlignment: MainAxisAlignment.center,