13. Flutter——AppBar按钮组件

1. Flutter 中的按钮组件

  • RaisedButton :凸起的按钮,其实就是 Material Design 风格的 Button
  • FlatButton :扁平化的按钮
  • OutlineButton:线框按钮
  • IconButton :图标按钮
  • buttonbar:按钮组
  • FloatingActionButton:浮动按钮

属性名称值类型属性
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('点击了');
				},
			 ),
			)
		   )
		 ],
	    )
	  ],
	),
  ),
 );
}
}

相关文章

这篇文章主要讲解了“FlutterComponent动画的显和隐怎么实现...
这篇文章主要讲解了“flutter微信聊天输入框功能如何实现”,...
本篇内容介绍了“Flutter之Navigator的高级用法有哪些”的有...
这篇文章主要介绍“Flutter怎么使用Android原生播放器”,在...
Flutter开发的android端如何修改APP名称,logo,版本号,具体...
Flutter路由管理初识路由概念一.路由管理1.1.Route1.2.Mater...