Flutter:按钮组件Button
简介按钮在我们开发过程中是少不了的,本节将介绍Flutter常用的一些按钮组件,例如:TextButton、OutlinedButton、ElevatedButton
在老的Flutter版本中包含了多种按钮组件:RaisedButton、FlatButton、OutlineButton。它们都继承了MaterialButton组件,后面将这些组件都废弃了,新增了TextButton、OutlinedButton、ElevatedButton组件。本节就介绍下这三个按钮组件的使用。
使用方法都是一样的,但是三个按钮展示不一样,如下图:
这是三个按钮都有两个共同的事件:
- onPressed:点击事件
- onLongPress :长按事件
里面的style属性可以对按钮进行设置,包含了如下:
- textStyle //字体
- backgroundColor //背景色
- foregroundColor //字体颜色
- overlayColor // 高亮色,按钮处于focused, hovered, or pressed时的颜色
- shadowColor // 阴影颜色
- elevation // 阴影值
- padding // padding
- minimumSize //最小尺寸
- side //边框
- shape //形状
- mouseCursor //鼠标指针的光标进入或悬停在此按钮的[InkWell]上时
- visualDensity // 按钮布局的紧凑程度
- tapTargetSize // 响应触摸的区域
- animationDuration //[shape]和[elevation]的动画更改的持续时间。
- enableFeedback // 检测到的手势是否应提供声音和/或触觉反馈。例如,在Android上,点击会产生咔哒声,启用反馈后,长按会产生短暂的振动。通常,组件默认值为true。
下面是使用案例:
import 'package:flutter/material.dart';
class ButtonBaseWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('按钮组件:Button'),
elevation: 0.0,
centerTitle: true,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () {
print("TextButton被点击了");
},
onLongPress: () {
print("TextButton被长按了");
},
child: Text("TextButton"),
),
OutlinedButton(
onPressed: () {
print("OutLineButton被点击了");
},
onLongPress: () {
print("OutLineButton被长按了");
},
child: Text("OutLineButton"),
),
ElevatedButton(
onPressed: () {
print("ElevateButton被点击了");
},
onLongPress: () {
print("ElevateButton被长按了");
},
child: Text("ElevateButton"),
),
ElevatedButton(
style: ButtonStyle(
fixedSize: MaterialStateProperty.all(
Size(double.maxFinite, 100),
), //宽度填充100%,高度100,如果只设置宽度就用Size.fromWidth(double.maxFinite)
backgroundColor: MaterialStateProperty.all(Colors.red), //背景色
foregroundColor: MaterialStateProperty.all(Colors.green), //字体颜色
overlayColor: MaterialStateProperty.all(Colors.blue), //高亮度颜色
elevation: MaterialStateProperty.all(30), //阴影值
shadowColor: MaterialStateProperty.all(Colors.yellow), //阴影颜色
textStyle:
MaterialStateProperty.all(TextStyle(fontSize: 15)), //文本样式
side: MaterialStateProperty.all(
//边框设置
BorderSide(
width: 2,
color: Colors.white,
),
),
),
onPressed: () {
print("ElevateButton被点击了");
},
onLongPress: () {
print("ElevateButton被长按了");
},
child: Text("ElevateButton"),
),
OutlinedButton(
onPressed: () {
print("圆角按钮被点击了");
},
child: Text("圆角Button"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.blue),
foregroundColor: MaterialStateProperty.all(Colors.white),
fixedSize:
MaterialStateProperty.all(Size(double.maxFinite, 150)),
shape: MaterialStateProperty.all(
//设置圆角按钮
CircleBorder(
side: BorderSide(
color: Colors.white,
width: 150,
),
),
),
),
),
],
),
),
);
}
}

网页扫描二维码库:Html5-Qrcode,官网地址:https://scanapp.org/html5-qrcode-docs/
二叉树(Binary tree)是树形结构的一个重要类型。许多实际问题抽象出来的数据结构往往是二叉树形式,即使是一般的树也能简单地转换为二叉树,而且二叉树的存储结构及其算法都较为简单,因此二叉树显得特别重要。二叉树特点是每个结点最多只能有两棵子树,且有左右之分。
APM(Application Performance Management)即应用性能管理系统,是对企业系统及时监控以实现对应用程序性能管理和故障管理的系统化解决方案。应用性能管理,主要指对企业的关键业务应用进行监控、优化,提高企业的应用的可靠性和治理,保证用户得到良好的服务,减低IT总拥有成本。
在于前端攻城狮的兄弟们开发接口的时候,总会遇到一些奇怪的问题。比如IOS对某个字段要求要整数,如果PHP这边返回过去是字符串那么APP就会崩溃。虽然他们可以捕获异常,但是有些时候我们更想后端的攻城狮能否提供一种统一的数据类型,前端想怎么转换就是他们自己的事情,本文我们将给大家带来这方面的处理。
Kong是一个在Nginx中运行的Lua应用程序,可以通过lua-nginx模块实现,Kong不是用这个模块编译Nginx,而是与OpenRestry一起发布,OpenRestry已经包含了lua-nginx-module,OpenRestry是Nginx的一组扩展功能模块。
快速生成表格
Electron页面跳转、浏览器打开链接和打开新窗口
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题