当前位置:网站首页>Flutter Getting Started and Advanced Tour (8) Button Widget
Flutter Getting Started and Advanced Tour (8) Button Widget
2022-08-09 13:19:00 【Xie Dong_】
引言
In a blog post we learnedGestureDetector,Learn to useGestureDetectorCan give some itself does not have click callbackwidgetClick on the correction ability,Finish some simple gesture interaction with users and make corresponding logic to handle,We also mentioned somewidget像RaisedButton和FloatingActionButtonThe control itself hasonPressed回调,When the user clicks the control trigger callback.This blog, we took the last blog reference to variousButtonClassified unified explain.
ButtonCollection rendering
上述RaisedButton、FlatButton、OutlineButton、MaterialButton、还有RawMaterialButton、FloationgActionButton,I points three categories to everyone,OutlineButton作为一类,RaisedButton、FlatButton、MaterialButton、RawMaterialButtonWhether from the constructor or using the similar,这几个button分为一类,另外FloatingActionButton作为一类.
1.OutlineButton:
OutlineButtonThe default with a border,We can attribute to specify the normal,With the user clicks on a state border color.
我们来看下OutlineButton的构造方法,And under the instructions of its corresponding attributes do.
const OutlineButton({
Key key,
@required VoidCallback onPressed,
ButtonTextTheme textTheme, //The button font theme
Color textColor, //字体颜色
Color disabledTextColor, //按钮禁用时候文字的颜色
Color color, //按钮背景颜色
Color highlightColor,//点击或者toch控件高亮的时候显示在控件上面,水波纹下面的颜色
Color splashColor, //水波纹的颜色
double highlightElevation,//高亮时候的阴影
this.borderSide,//按钮边框
this.disabledBorderColor, //Button is disabled when the color of the frame
this.highlightedBorderColor,//Position is the color of the frame
EdgeInsetsGeometry padding,//边距
ShapeBorder shape, //设置shape
Clip clipBehavior = Clip.none,
Widget child,
})
上述OutlineButtonEffect on the twobutton的具体代码:
Do not specify any style:
new OutlineButton(onPressed: () {
}, child: new Text("OutlineButton")),
效果图
设置边框样式
new OutlineButton(
textColor: Colors.blue,
highlightedBorderColor: Colors.deepOrange,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
borderSide: new BorderSide(color: Colors.blueAccent),
onPressed: () {
},
child: new Text("OutlineButton")
),
效果图
2.FloatingActionButton
FloatingActionButtonDid the native android development of readers should be familiar with this name,在FlutterNot only refers to the native android called,使用方法也大同小异.
构造方法
const FloatingActionButton({
Key key,
this.child,
this.tooltip,
this.foregroundColor,
this.backgroundColor,
this.heroTag = const _DefaultHeroTag(),
this.elevation = 6.0,
this.highlightElevation = 12.0,
@required this.onPressed,
this.mini = false,
this.shape = const CircleBorder(),
this.clipBehavior = Clip.none,
this.materialTapTargetSize,
this.isExtended = false,
})
Due to the use method with native android similar,I will not spread in detail,I'll put all the code on the preliminaries rendering with,You may refer to the facefloatingactionbutton的用法.
3.RaisedButton、FlatButton、OutlineButton、MaterialButton
这几类button十分类似,So I put them in the same class as do explain,But also can have subtle differences,像FlatButtonDoes not support set the color of the finger after raising,Other conventional usage almost unanimously,About the specific nuances,The reader can compare method to construct,自行测试,我拿RaisedButton把代码,贴上代码,Demonstrated under the categories for youButtonThe commonly used attributes configuration instructions.
new RaisedButton(
color: Colors.blueAccent,
//按钮的背景颜色
padding: EdgeInsets.all(15.0),
//Button from the content inside the padding
textColor: Colors.white,
//文字的颜色
textTheme: ButtonTextTheme.normal,
//按钮的主题
onHighlightChanged: (bool b) {
//水波纹高亮变化回调
},
disabledTextColor: Colors.black54,
//按钮禁用时候文字的颜色
disabledColor: Colors.black54,
//Buttons are disabled when the color of the display
highlightColor: Colors.green,
//点击或者toch控件高亮的时候显示在控件上面,水波纹下面的颜色
splashColor: Colors.amberAccent,
//水波纹的颜色
colorBrightness: Brightness.light,
//按钮主题高亮
elevation: 10.0,
//按钮下面的阴影
highlightElevation: 10.0,
//高亮时候的阴影
disabledElevation: 10.0,
//按下的时候的阴影
shape: new RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
//设置形状
onPressed: () {
},
child: new Text("RaisedButton"),
),
The explanation of the reader if you have not understand place can reference articles posted in the openingbuttonRendering of the source code for your reference,Leave a message or give me a piece of discussion,The article begins with the post ofbuttonRendering of the source code is as follows.
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(home: new ButtonPage()));
}
class ButtonPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Button Widget"),
),
floatingActionButton: new FloatingActionButton(
onPressed: () {
}, child: new Icon(Icons.adb), tooltip: "点击"),
body: new ListView(
children: <Widget>[
new Text("简单样式",
textAlign: TextAlign.center,
style: new TextStyle(color: Colors.brown, fontSize: 20.0)),
new RaisedButton(onPressed: () {
}, child: new Text("RaisedButton")),
new FlatButton(onPressed: () {
}, child: new Text("FlatButton")),
new MaterialButton(
onPressed: () {
}, child: new Text("MaterialButton")),
new RawMaterialButton(
onPressed: () {
}, child: new Text("RawMaterialButton")),
new OutlineButton(onPressed: () {
}, child: new Text("OutlineButton")),
new SizedBox(height: 20),
new Text("To upgrade the style",
textAlign: TextAlign.center,
style: new TextStyle(color: Colors.brown, fontSize: 20.0)),
new RaisedButton(
color: Colors.blueAccent,
//按钮的背景颜色
padding: EdgeInsets.all(15.0),
//Button from the content inside the padding
textColor: Colors.white,
//文字的颜色
textTheme: ButtonTextTheme.normal,
//按钮的主题
onHighlightChanged: (bool b) {
//水波纹高亮变化回调
},
disabledTextColor: Colors.black54,
//按钮禁用时候文字的颜色
disabledColor: Colors.black54,
//Buttons are disabled when the color of the display
highlightColor: Colors.green,
//点击或者toch控件高亮的时候显示在控件上面,水波纹下面的颜色
splashColor: Colors.amberAccent,
//水波纹的颜色
colorBrightness: Brightness.light,
//按钮主题高亮
elevation: 10.0,
//按钮下面的阴影
highlightElevation: 10.0,
//高亮时候的阴影
disabledElevation: 10.0,
//按下的时候的阴影
shape: new RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
//设置形状
onPressed: () {
},
child: new Text("RaisedButton"),
),
new FlatButton(
color: Colors.lightGreen,
textColor: Colors.red,
onPressed: () {
}, child: new Text("FlatButton")),
new OutlineButton(
textColor: Colors.blue,
highlightedBorderColor: Colors.deepOrange,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
borderSide: new BorderSide(color: Colors.blueAccent),
onPressed: () {
},
child: new Text("OutlineButton")
),
MaterialButton(
color: Colors.yellow,
textColor: Colors.red,
onPressed: () {
},
child: new Text("MaterialButton")
),
RawMaterialButton(
fillColor: Colors.deepOrange,
onPressed: () {
},
child: new Text("RawMaterialButton",style: new TextStyle(color: Colors.white),)
)
],
),
);
}
}
边栏推荐
- Flutter Getting Started and Advanced Tour (2) Hello Flutter
- 在已打开图片上加水印(文字)
- Report: The number of students who want to learn AI has increased by 200%, and there are not enough teachers
- 智驾科技完成C1轮融资,此前2轮已融4.5亿元
- Glory to the Blue Yonder, speeds up the strategic growth
- Rust from entry to proficient 04 - data types
- Batch大小不一定是2的n次幂!ML资深学者最新结论
- 世界第4疯狂的科学家,在103岁生日那天去世了
- 基于STM32+铂电阻设计的测温仪
- The grep command Shell regular expressions, the three musketeers
猜你喜欢
JD.com architects tidy up: what are the core technical knowledge points of jvm and performance tuning
保存Simulink仿真模型为图片或者PDF的方法
一甲子,正青春,CCF创建六十周年庆典在苏州举行
Intranet penetration tool ngrok usage tutorial
API调用,API传参,面向对接开发,你真的会写接口文档吗?
读写分离后,性能居然提升100%了呀
WeChat side: what is consistent hashing, usage scenarios, and what problems does it solve?
AI basketball referee, walking is special, ask harden care don't care
Flutter入门进阶之旅(七)GestureDetector
The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
随机推荐
用皮肤“听”音乐,网友戴上这款装备听音乐会:仿佛住在钢琴里
【HCIP持续更新】IS-IS协议原理与配置
苹果Meta都在冲的Pancake技术,中国VR团队YVR竟抢先交出产品答卷
大佬们,请教一下,我看官方文档中,sqlserver cdc只支持2012版之后的,对于sqlser
Rust从入门到精通04-数据类型
京东架构师呕心整理:jvm与性能调优有哪些核心技术知识点
无需精子卵子子宫体外培育胚胎,Cell论文作者这番话让网友们炸了
[Microservice ~ Remote Call] Integrate RestTemplate, WebClient, Feign
微服务架构的核心关键点
Blocking, non-blocking, multiplexing, synchronous, asynchronous, BIO, NIO, AIO all in one pot
1小时直播招募令:行业大咖干货分享,企业报名开启丨量子位·视点
史上最猛“员工”,疯狂吐槽亿万富翁老板小扎:那么有钱,还总穿着同样的衣服!...
保存Simulink仿真模型为图片或者PDF的方法
两分钟录音就可秒变语言通!火山语音音色复刻技术如何修炼而成?
Say goodbye to the AI era of hand looms
国产抗新冠口服药每瓶不超300元/ 我国IPv6网络全面建成/ 谷歌入局折叠屏手机...今日更多新鲜事在此...
We really need DApp?Really can't meet our fantasy App?
MySQL principle and optimization of Group By optimization techniques
Information system project managers must memorize the core test sites (63) The main process of project portfolio management & DIPP analysis
00后写个暑假作业,被监控成这笔样