其他分享
首页 > 其他分享> > 13. Flutter——AppBar按钮组件

13. Flutter——AppBar按钮组件

作者:互联网

1. Flutter 中的按钮组件


属性名称值类型属性值
onPressedVoidCallback ,一般接收一个方法必填参数,按下按钮时触发的回调,接收一个方法,传 null 表示按钮禁用,会显示禁用相关样式
childWidget文本控件
textColorColor文本颜色
colorColor按钮颜色
disabledColorColor按钮禁用颜色
disabledTextColorColor按钮禁用时的文本颜色
splashColorColor点击按钮时水波纹的颜色
highlightColorColor点击(长按)按钮后按钮的颜色
elevationdouble阴影的范围,值越大阴影范围越大
padding内边距
shape设置按钮的形状

import 'package:flutter/material.dart';

class ButtonDemoPage extends StatelessWidget {
	const ButtonDemoPage({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
	return Scaffold(
		appBar: AppBar(
			title: Text("按钮演示页面"),
),
body: Center(
	child: Column(
		mainAxisAlignment: MainAxisAlignment.center,
		children: <Widget>[
			Row(
				mainAxisAlignment: MainAxisAlignment.center,
				children: <Widget>[
				RaisedButton(
				child: Text('普通按钮'),
				onPressed: () {
				print('点击了');
				},
			),
				SizedBox(width: 20),
				RaisedButton(
					child: Text('有颜色的按钮'),
					textColor: Colors.white,
					color: Colors.blue,
					onPressed: () {
						print('点击了');
				},
			),
				SizedBox(width: 20),
				RaisedButton(
					child: Text('阴影按钮'),
					textColor: Colors.white,
					color: Colors.blue,
					elevation:10,
					onPressed: () {
						print('点击了');
				},
			)
		],
	),
	SizedBox(height: 40),
	Row(
		mainAxisAlignment: MainAxisAlignment.center,
		children: <Widget>[
			Container(
			height: 60,
			width: 200,
			child: RaisedButton(
			 child: Text('有宽高的按钮'),
			 textColor: Colors.white,
			 color: Colors.blue,
			 elevation:10,
			 onPressed: () {
				print('点击了');
			},
		  )
		 )
		],
	),
	SizedBox(height: 40),
	Row(
		mainAxisAlignment: MainAxisAlignment.center,
		children: <Widget>[
			Expanded(
				child: Container(
					height: 60,
					margin: EdgeInsets.all(20),
					child: RaisedButton(
						child: Text('全屏按钮'),
						textColor: Colors.white,
						color: Colors.blue,
						elevation:10,
						onPressed: () {
							print('点击了');
						},
					),
				)
			  )
			],
		),
		Row(
			mainAxisAlignment: MainAxisAlignment.center,
			children: <Widget>[
			Expanded(
				child: Container(
				height: 60,
				margin: EdgeInsets.all(20),
				child: RaisedButton(
					child: Text('带圆角的按钮'),
					textColor: Colors.white,
					color: Colors.blue,
					elevation:10,
					shape: RoundedRectangleBorder(
					borderRadius: BorderRadius.circular(10),
				),
				onPressed: () {
					print('点击了');
				},
			 ),
			)
		   )
		 ],
	    )
	  ],
	),
  ),
 );
}
}

标签:13,RaisedButton,Text,AppBar,child,Colors,按钮,print,Flutter
来源: https://blog.csdn.net/qq_38556217/article/details/112062716