From c9cab81eafc8a778f988f76aca53e49094f5ae8c Mon Sep 17 00:00:00 2001 From: zhang <494089941@qq.com> Date: Mon, 23 Nov 2020 17:36:55 +0800 Subject: [PATCH] add ASbutton --- example/lib/main.dart | 2 +- lib/buttons/as_button.dart | 84 +++++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index f7bce79..25e0508 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -61,7 +61,7 @@ class _MyHomePageState extends State { ), body: ListView( children: [ - ASButton(), + ASButton.gray('删除订单', (){}), SizedBox(height: 12.w), ], ), diff --git a/lib/buttons/as_button.dart b/lib/buttons/as_button.dart index b32f8e3..b6d2e78 100644 --- a/lib/buttons/as_button.dart +++ b/lib/buttons/as_button.dart @@ -1,8 +1,69 @@ import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; ///安速按钮 class ASButton extends StatefulWidget { - ASButton({Key key}) : super(key: key); + ///按钮颜色 + final Color color; + + ///按钮文字 + ///动态类型,可以是string或者widget + final dynamic title; + + ///按钮圆角 + final double radius; + + ///按钮边框 + final bool outline; + + ///按钮边框颜色 + final Color outlineColor; + + ///按钮文字颜色 + final Color textColor; + + ///按钮文字格式 + final TextStyle textStyle; + + ///内边距 + final EdgeInsets padding; + + ///点击事件 + final VoidCallback onpressed; + + ASButton({ + Key key, + this.color, + this.radius, + this.outline = false, + this.outlineColor, + this.textColor, + this.textStyle, + this.padding, + @required this.title, + @required this.onpressed, + }) : super(key: key); + + ASButton.red(this.title, this.onpressed, + {Key key, this.textStyle, this.padding, this.radius, this.color}) + : outline = true, + outlineColor = Color(0xFFE50112), + textColor = Color(0xFFE50112), + super(key: key); + + ASButton.gray(this.title, this.onpressed, + {Key key, this.color, this.radius, this.textStyle, this.padding}) + : outline = true, + outlineColor = Color(0x73000000), + textColor = Color(0xD9000000), + super(key: key); + + ASButton.yellow(this.title, this.onpressed, + {Key key, this.radius, this.outlineColor, this.textStyle, this.padding}) + : color = Color(0xFFFFB600), + textColor = Color(0xD9FFFFFF), + outline = false, + super(key: key); @override _ASButtonState createState() => _ASButtonState(); @@ -11,6 +72,25 @@ class ASButton extends StatefulWidget { class _ASButtonState extends State { @override Widget build(BuildContext context) { - return SizedBox(); + return MaterialButton( + onPressed: widget.onpressed, + child: widget.title is String + ? Text( + widget.title, + style: widget.textStyle == null + ? TextStyle(color: widget.textColor, fontSize: 13.sp) + : widget.textStyle, + ) + : widget.title, + padding: widget.padding ?? + EdgeInsets.symmetric(vertical: 6.w, horizontal: 12.w), + shape: RoundedRectangleBorder( + side: widget.outline + ? BorderSide(color: widget.outlineColor, width: 0.5) + : BorderSide.none, + borderRadius: BorderRadius.circular(widget.radius ?? 15.5.w)), + color: widget.color ?? Color(0xFFFFFFFF), + elevation: 0, + ); } }