当前位置: 首页 > news >正文

十堰做网站排名电话销售如何快速吸引客户

十堰做网站排名,电话销售如何快速吸引客户,wordpress 伪静态tags,做今网站flutter开发实战-实现自定义按钮类似UIButton效果 最近开发过程中需要实现一下UIButton效果的flutter按钮,这里使用的是监听手势点击事件。 一、GestureDetector GestureDetector属性定义 GestureDetector({super.key,this.child,this.onTapDown,this.onTapUp,t…

flutter开发实战-实现自定义按钮类似UIButton效果

最近开发过程中需要实现一下UIButton效果的flutter按钮,这里使用的是监听手势点击事件。

一、GestureDetector

GestureDetector属性定义

GestureDetector({super.key,this.child,this.onTapDown,this.onTapUp,this.onTap,this.onTapCancel,this.onSecondaryTap,this.onSecondaryTapDown,this.onSecondaryTapUp,this.onSecondaryTapCancel,this.onTertiaryTapDown,this.onTertiaryTapUp,this.onTertiaryTapCancel,this.onDoubleTapDown,this.onDoubleTap,this.onDoubleTapCancel,this.onLongPressDown,this.onLongPressCancel,this.onLongPress,this.onLongPressStart,
...

由于属性太多,我们实现onTapDown、onTapUp、onTapCancel、onTap。

二、实现flutter自定义按钮

实现自定义按钮类似,我们实现onTapDown、onTapUp、onTapCancel、onTap这几个方法

return GestureDetector(onTapDown: handleTapDown,// 处理按下事件onTapUp: handleTapUp,// 处理抬起事件onTap: handleTap,onTapCancel: handleTapCancel,
}void handleTapDown(TapDownDetails details) {if (widget.enabled != null && widget.enabled == true) {setState(() {_highlighted = true;});}}void handleTapUp(TapUpDetails details) {setState(() {_highlighted = false;});}void handleTapCancel() {setState(() {_highlighted = false;});}void handleTap() {if (widget.enabled != null && widget.enabled == true) {setState(() {_highlighted = true;});Future.delayed(Duration(milliseconds: 100), () {if (mounted) {setState(() {_highlighted = false;});}});if (widget.enabled != null && widget.enabled == true) {widget.onPressed();}}}

完整代码如下

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';//枚举类的声明
enum ButtonAlignment { Center, Left, Right }class ButtonWidget extends StatefulWidget {const ButtonWidget({Key? key,this.bgColor,this.bgHighlightedColor,this.color,this.highlightedColor,this.disableColor,this.bgDisableColor,this.width,this.height,this.borderRadius,this.buttonAlignment: ButtonAlignment.Center,this.text: "",this.textFontSize,this.icon,this.iconTextPadding,required this.onPressed,this.enabled = true,required this.child,this.border,this.padding,}) : super(key: key);final Color? bgColor; // 背景颜色final Color? bgHighlightedColor; // 背景点击高亮颜色final Color? color;final Color? highlightedColor;final Color? disableColor;final Color? bgDisableColor;final double? width;final double? height;final VoidCallback onPressed;final double? borderRadius;final ButtonAlignment? buttonAlignment;final String? text;final double? textFontSize;final Icon? icon;final double? iconTextPadding;final bool? enabled;final Widget child;final Border? border;final EdgeInsetsGeometry? padding;_ButtonWidgetState createState() => _ButtonWidgetState();
}class _ButtonWidgetState extends State<ButtonWidget> {bool _highlighted = false;void initState() {// TODO: implement initStatesuper.initState();_highlighted = false;}void handleTapDown(TapDownDetails details) {if (widget.enabled != null && widget.enabled == true) {setState(() {_highlighted = true;});}}void handleTapUp(TapUpDetails details) {setState(() {_highlighted = false;});}void handleTapCancel() {setState(() {_highlighted = false;});}void handleTap() {if (widget.enabled != null && widget.enabled == true) {setState(() {_highlighted = true;});Future.delayed(Duration(milliseconds: 100), () {if (mounted) {setState(() {_highlighted = false;});}});if (widget.enabled != null && widget.enabled == true) {widget.onPressed();}}}AlignmentGeometry showAlignment(ButtonAlignment? buttonAlignment) {AlignmentGeometry alignment = Alignment.center;if (buttonAlignment != null) {if (buttonAlignment == ButtonAlignment.Left) {alignment = Alignment.centerLeft;} else if (buttonAlignment == ButtonAlignment.Right) {alignment = Alignment.centerRight;} else {alignment = Alignment.center;}}return alignment;}Widget build(BuildContext context) {return GestureDetector(onTapDown: handleTapDown,// 处理按下事件onTapUp: handleTapUp,// 处理抬起事件onTap: handleTap,onTapCancel: handleTapCancel,child: Container(padding: widget.padding,width: widget.width,height: widget.height,alignment: showAlignment(widget.buttonAlignment),decoration: BoxDecoration(color: boxDecorationBgColor(),borderRadius: BorderRadius.circular(widget.borderRadius ?? 0),border: widget.border),child: widget.child,),);}Color? boxDecorationBgColor() {if (widget.enabled != null && widget.enabled == true) {return (_highlighted ? widget.bgHighlightedColor : widget.bgColor);}return widget.bgDisableColor ?? widget.bgColor;}Color? textColor() {if (widget.enabled != null && widget.enabled == true) {return (_highlighted ? widget.highlightedColor : widget.color);}return widget.disableColor ?? widget.bgColor;}
}

三、小结

flutter开发实战-实现自定义按钮类似UIButton效果,通过监听手势GestureDetector的onTapDown、onTapUp、onTapCancel、onTap来实现按下背景变换,松开背景恢复默认等效果。

学习记录,每天不停进步。

http://www.hkea.cn/news/867008/

相关文章:

  • 网站建设洪塔网站搜索优化排名
  • 专业做设计师品牌网站深圳百度总部
  • 网站兼容工具seo关键词排名优化教程
  • O2O网站制作需要多少钱美区下载的app怎么更新
  • 上海做网站 公司做电商必备的几个软件
  • caozi.com网站建设中百度指数如何分析数据
  • 互联网舆情处置公司武汉seo外包平台
  • 消防器材网站建设背景seo工作职位
  • 专业网站制作公司名称seo咨询茂名
  • 做b2c网站建网站seo
  • 代理注册香港公司seo技术交流论坛
  • 想要提高网站排名应该怎么做seo网站推广费用
  • 专业做食材网站seo链接优化建议
  • 做画册的网站附近哪里有计算机培训班
  • 大兴建站推广google登录
  • 长春个人做网站哪家好百度指数热度榜
  • 嘉兴手机网站开发费用百度学术论文官网入口
  • 刷业务网站怎么做seo关键词挖掘
  • 企业移动网站品牌苏州网站外包
  • 网站建设流程 文档东莞seo技术
  • 公众号开发网站建设合同信息流广告投放流程
  • 长清网站建设费用友情链接出售平台
  • 先做网站再付款百度推广的广告真实可信吗
  • 湖南省人民政府一事一办企业网站seo排名优化
  • 深圳招聘网官方网站网站搜索引擎优化
  • 怎么知道一个网站是谁做的中国最大的企业培训公司
  • m2c是什么意思南昌百度seo
  • 专业做羽绒服的服装网站域名注册网
  • 公司网站建设需要显示什么软件世界球队最新排名
  • 做微信平台图片网站有没有免费的广告平台