Flutter 中的常见的按钮组件 以及自定义按钮组件
Flutter 里有很多的 Button 组件很多,常见的按钮组件有:RaisedButton、FlatButton、
IconButton、OutlineButton、ButtonBar、FloatingActionButton 等。
RaisedButton :凸起的按钮,其实就是 Material Design 风格的 Button FlatButton :扁平化的按钮
OutlineButton:线框按钮
IconButton :图标按钮
ButtonBar:按钮组
FloatingActionButton:浮动按钮
Flutter 按钮组件中的一些属性
属性名称 |
值类型 |
属性值 |
onPressed |
VoidCallback ,一般接收一个 方法 |
必填参数,按下按钮时触发的回调,接收一个 方法,传 null 表示按钮禁用,会显示禁用相关 样式 |
child |
Widget |
文本控件 |
textColor |
Color |
文本颜色 |
color |
Color |
按钮的颜色 |
|
Color |
按钮禁用时的颜色 |
|
Color |
按钮禁用时的文本颜色 |
splashColor |
Color |
点击按钮时水波纹的颜色 |
|
Color |
|
elevation |
double |
|
padding |
内边距 |
|
shape |
设置按钮的形状 shape: RoundedRectangleBorder(
) |
- 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("按钮演示页面"),
- actions: <Widget>[
- IconButton(
- icon: Icon(Icons.settings),
- onPressed: (){
- },
- )
- ],
- ),
- body: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- RaisedButton(
- child: Text('普通按钮'),
- onPressed: () {
- print("普通按钮");
- },
- ),
- SizedBox(width: 5),
- RaisedButton(
- child: Text('颜色按钮'),
- color: Colors.blue,
- textColor: Colors.white,
- onPressed: () {
- print("有颜色按钮");
- },
- ),
- SizedBox(width: 5),
- RaisedButton(
- child: Text('阴影按钮'),
- color: Colors.blue,
- textColor: Colors.white,
- elevation: 20,
- onPressed: () {
- print("有阴影按钮");
- },
- ),
- SizedBox(width: 5),
- RaisedButton.icon(
- icon: Icon(Icons.search),
- label: Text('图标按钮'),
- color: Colors.blue,
- textColor: Colors.white,
- // onPressed: null,
- onPressed: () {
- print("图标按钮");
- })
- ],
- ),
- SizedBox(height: 10),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Container(
- height: 50,
- width: 400,
- child: RaisedButton(
- child: Text('宽度高度'),
- color: Colors.blue,
- textColor: Colors.white,
- elevation: 20,
- onPressed: () {
- print("宽度高度");
- },
- ),
- )
- ],
- ),
- SizedBox(height: 10),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Expanded(
- child: Container(
- height: 60,
- margin: EdgeInsets.all(10),
- child: RaisedButton(
- child: Text('自适应按钮'),
- color: Colors.blue,
- textColor: Colors.white,
- elevation: 20,
- onPressed: () {
- print("自适应按钮");
- },
- ),
- ),
- )
- ],
- ),
- SizedBox(height: 10),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- RaisedButton(
- child: Text('圆角按钮'),
- color: Colors.blue,
- textColor: Colors.white,
- elevation: 20,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(10)),
- onPressed: () {
- print("圆角按钮");
- }),
- Container(
- height: 80,
- child: RaisedButton(
- child: Text('圆形按钮'),
- color: Colors.blue,
- textColor: Colors.white,
- elevation: 20,
- splashColor: Colors.red,
- shape:
- CircleBorder(side: BorderSide(color: Colors.white)),
- onPressed: () {
- print("圆形按钮");
- }),
- ),
- FlatButton(
- child: Text("按钮"),
- color: Colors.blue,
- textColor: Colors.yellow,
- onPressed: () {
- print('FlatButton');
- },
- ),
- SizedBox(width: 10),
- OutlineButton(
- child: Text("按钮"),
- // color: Colors.red, //没有效果
- // textColor: Colors.yellow,
- onPressed: () {
- print('FlatButton');
- })
- ],
- ),
- SizedBox(height: 10),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Expanded(
- child: Container(
- margin: EdgeInsets.all(20),
- height: 50,
- child: OutlineButton(child: Text("注册"), onPressed: () {}),
- ),
- )
- ],
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: <Widget>[
- ButtonBar(
- children: <Widget>[
- RaisedButton(
- child: Text('登录'),
- color: Colors.blue,
- textColor: Colors.white,
- elevation: 20,
- onPressed: () {
- print("宽度高度");
- },
- ),
- RaisedButton(
- child: Text('注册'),
- color: Colors.blue,
- textColor: Colors.white,
- elevation: 20,
- onPressed: () {
- print("宽度高度");
- },
- ),
- MyButton(text: "自定义按钮",height: 60.0,width: 100.0,pressed: (){
- print('自定义按钮');
- })
- ],
- )
- ],
- )
- ],
- ));
- }
- }
- //自定义按钮组件
- class MyButton extends StatelessWidget {
- final text;
- final pressed;
- final width;
- final height;
- const MyButton({this.text='',this.pressed=null,this.width=80,this.height=30}) ;
- @override
- Widget build(BuildContext context) {
- return Container(
- height: this.height,
- width: this.width,
- child: RaisedButton(
- child: Text(this.text),
- onPressed:this.pressed ,
- ),
- );
- }
- }
Flutter 中的常见的按钮组件 以及自定义按钮组件的更多相关文章
- 22Flutter中的常见的按钮组件 以及自定义按钮组件
/* Flutter中的常见的按钮组件 以及自定义按钮组件 一.Flutter中的按钮组件介绍 Flutter里有很多的Button组件,常见的按钮组件有:RaisedButton/FlatButto ...
- echarts 显示下载按钮,echarts 自定义按钮,echarts 添加按钮
echarts 显示下载按钮,echarts 自定义按钮,echarts 添加按钮 >>>>>>>>>>>>>>&g ...
- #003 React 组件 继承 自定义的组件
主题:React组件 继承 自定义的 组件 一.需求说明 情况说明: 有A,B,C,D 四个组件,里面都有一些公用的逻辑,比如 设置数据,获取数据,有某些公用的的属性,不想在 每一个 组件里面写这些属 ...
- Flutter 中的常见的按钮组件 以及自 定义按钮组件
一.Flutter 中的按钮组件介绍 Flutter 里有很多的 Button 组件很多,常见的按钮组件有:RaisedButton.FlatButton. IconButton.Outlin ...
- Flutter中的普通路由与命名路由(Navigator组件)
Flutter 中的路由通俗的讲就是页面跳转.在 Flutter 中通过 Navigator 组件管理路由导航.并提供了管理堆栈的方法.如:Navigator.push 和 Navigator.pop ...
- Flutter中的日期、格式化日期、日期选择器组件
Flutter中的日期和时间戳 //獲取當前日期 DateTime _nowDate = DateTime.now(); print(_nowDate);//2019-10-29 10:57:20.3 ...
- MIP组件开发 自定义js组件开发步骤
什么是百度MIP? MIP(Mobile Instant Pages - 移动网页加速器)主要用于移动端页面加速 官网参考:https://www.mipengine.org/doc/00-mip-1 ...
- flutter中的按钮组件
Flutter 里有很多的 Button 组件很多,常见的按钮组件有:RaisedButton.FlatButton.IconButton.OutlineButton.ButtonBar.Floati ...
- Flutter 中的路由
Flutter 中的路由通俗的讲就是页面跳转.在 Flutter 中通过 Navigator 组件管理路由导航. 并提供了管理堆栈的方法.如:Navigator.push 和 Navigator.po ...
随机推荐
- python使用二分法实现在一个有序列表中查找指定的元素
二分法是一种快速查找的方法,时间复杂度低,逻辑简单易懂,总的来说就是不断的除以2除以2... 例如需要查找有序list里面的某个关键字key的位置,那么首先确认list的中位数mid,下面分为三种情况 ...
- python_并发编程——多进程
from multiprocessing import Process import os def func1(): print('子进程1',os.getpid()) #子进程:获取当前进程的进程号 ...
- hbase实践之协处理器Coprocessor
HBase客户端查询存在的问题 Scan 用Get/Scan查询数据, Filter 用Filter查询特定数据 以上情况只适合几千行数据以及不是很多的列的"小数据". 当表扩展为 ...
- 查看mysql日志文件
开启mysql日志 /etc/mysql/mysql.conf.d/mysqld.cnf sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 找到第68,69行 前面 ...
- java发送邮件javamail, freemarker读取html模板内容
https://www.cnblogs.com/xdp-gacl/p/4216311.html 一.RFC882文档简单说明 RFC882文档规定了如何编写一封简单的邮件(纯文本邮件),一封简单的邮件 ...
- LightOJ - 1170 - Counting Perfect BST(卡特兰数)
链接: https://vjudge.net/problem/LightOJ-1170 题意: BST is the acronym for Binary Search Tree. A BST is ...
- Hbase节点及原理
1.Hbase架构:Clinet.Zookeeper.Master.RegionServer.Region.Store.MemStore.HLog 1.读过程 2.写过程 https://www.cn ...
- Longest Continuous Increasing Subsequence II
Description Given an integer matrix. Find the longest increasing continuous subsequence in this matr ...
- MySQL 实现 Oracle row_number over 数据排序功能
一.方法一GROUP_CONCAT.SUBSTRING_INDEX 1.GROUP_CONCAT 2.SUBSTRING_INDEX 3.例子 首先我们可以首先根据job_id 排序然后根据start ...
- am335x system upgrade rootfs for dhcpcd cross compile(十三)
dhcpcd移植 [目的] 移植dhcpcd的目是在AM335X开发板上使用dhcp功能,获取WAN口设备的IP,并且可以通过参数指定其matric,matric值越小,其优先级越高.如设备可以以太网 ...