按钮修改

null_safety
张萌 4 years ago
parent 81e39621bc
commit 56c23c0c98

@ -1,4 +1,5 @@
import 'package:ansu_ui/ansu_ui.dart'; import 'package:ansu_ui/ansu_ui.dart';
import 'package:ansu_ui/buttons/as_gradientbutton.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ExampleButton extends StatefulWidget { class ExampleButton extends StatefulWidget {
@ -14,17 +15,60 @@ class _ExampleButtonState extends State<ExampleButton> {
return ASScaffold( return ASScaffold(
title: 'Button', title: 'Button',
body: ListView( body: ListView(
children: [ ASButton.delete(title: '删除订单',onPressed: (){},), children: [
ASButton.info(title: '删除订单',onPressed: (){},), ASButton.delete(
ASButton.warn(title: '删除订单',onPressed: (){},), title: '删除订单',
ASButton.opration(title: '删除订单',onPressed: (){},), onPressed: () {},
),
ASButton.info(
title: '删除订单',
onPressed: () {},
),
ASButton.warn(
title: '删除订单',
onPressed: () {},
),
ASButton.opration(
title: '删除订单',
onPressed: () {},
),
SizedBox(height: 12.w), SizedBox(height: 12.w),
ASLongButton.solid(title: '确认',onPressed: (){},), ASLongButton.solid(
ASLongButton.hollow(title: '确认',onPressed: (){},), title: '确认',
onPressed: () {},
),
ASLongButton.hollow(
title: '确认',
onPressed: () {},
),
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: 100.w), padding: EdgeInsets.symmetric(horizontal: 100.w),
child: ASLongButton.solid(title: 'null',onPressed:(){} ), child: ASLongButton.solid(title: 'null', onPressed: () {}),
), ),
Row(
children: [
ASGradientButton.pay(
title: '支付',
onPressed: () {},
),
ASButton.delete(
title: '删除',
onPressed: () {},
),
ASGradientButton.operation(
title: 'null',
onPressed: () {},
),
],
),
Row(
children: [
ASButton.order(
title: '立即下单',
onPressed: () {},
)
],
)
], ],
), ),
); );

@ -34,6 +34,12 @@ class ASButton extends StatefulWidget {
/// ///
final double width; final double width;
///
final Color disableColor;
///
final Color disableTextColor;
ASButton({ ASButton({
Key key, Key key,
this.bgcolor, this.bgcolor,
@ -46,6 +52,8 @@ class ASButton extends StatefulWidget {
@required this.title, @required this.title,
this.onPressed, this.onPressed,
this.width, this.width,
this.disableColor,
this.disableTextColor,
}) : super(key: key); }) : super(key: key);
ASButton.warn( ASButton.warn(
@ -56,7 +64,9 @@ class ASButton extends StatefulWidget {
this.bgcolor, this.bgcolor,
this.onPressed, this.onPressed,
@required this.title, @required this.title,
this.width}) this.width,
this.disableColor,
this.disableTextColor})
: outline = true, : outline = true,
outlineColor = Color(0xFFE50112), outlineColor = Color(0xFFE50112),
textColor = Color(0xFFE50112), textColor = Color(0xFFE50112),
@ -70,7 +80,9 @@ class ASButton extends StatefulWidget {
this.padding, this.padding,
@required this.title, @required this.title,
this.onPressed, this.onPressed,
this.width}) this.width,
this.disableColor,
this.disableTextColor})
: outline = true, : outline = true,
outlineColor = Color(0x73000000), outlineColor = Color(0x73000000),
textColor = Color(0xD9000000), textColor = Color(0xD9000000),
@ -84,7 +96,9 @@ class ASButton extends StatefulWidget {
this.padding, this.padding,
@required this.title, @required this.title,
this.onPressed, this.onPressed,
this.width}) this.width,
this.disableColor,
this.disableTextColor})
: bgcolor = Color(0xFFFFB600), : bgcolor = Color(0xFFFFB600),
textColor = Color(0xD9FFFFFF), textColor = Color(0xD9FFFFFF),
outline = false, outline = false,
@ -97,11 +111,30 @@ class ASButton extends StatefulWidget {
this.padding, this.padding,
@required this.title, @required this.title,
this.onPressed, this.onPressed,
this.width}) this.width,
this.disableColor,
this.disableTextColor})
: bgcolor = Color(0xFFF2F2F2), : bgcolor = Color(0xFFF2F2F2),
textColor = Color(0xD9000000), textColor = Color(0xD9000000),
outline = false, outline = false,
super(key: key); super(key: key);
ASButton.order({
Key key,
@required this.title,
this.onPressed,
this.outlineColor,
this.width,
}) : bgcolor = Color(0xFFFFBD32),
textColor=Color(0xFF0000000),
textStyle = TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.bold),
radius = 5.w,
outline = false,
disableColor = Color(0xFFFFDF9B),
disableTextColor = Color(0x73000000),
padding=EdgeInsets.symmetric(vertical: 8.w),
super(key: key);
@override @override
_ASButtonState createState() => _ASButtonState(); _ASButtonState createState() => _ASButtonState();
@ -111,6 +144,9 @@ class _ASButtonState extends State<ASButton> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialButton( return MaterialButton(
disabledColor: widget.disableColor ?? widget.bgcolor,
disabledTextColor: widget.disableTextColor ?? Color(0x73000000),
textColor: widget.textColor ?? Color(0xFFFFB600),
minWidth: widget.width ?? 75.w, minWidth: widget.width ?? 75.w,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: widget.onPressed, onPressed: widget.onPressed,
@ -118,7 +154,6 @@ class _ASButtonState extends State<ASButton> {
? Text(widget.title, ? Text(widget.title,
style: widget.textStyle ?? style: widget.textStyle ??
TextStyle( TextStyle(
color: widget.textColor ?? Color(0xFFFFB600),
fontSize: 13.sp)) fontSize: 13.sp))
: widget.title, : widget.title,
padding: widget.padding ?? EdgeInsets.symmetric(vertical: 6.w), padding: widget.padding ?? EdgeInsets.symmetric(vertical: 6.w),
@ -129,6 +164,9 @@ class _ASButtonState extends State<ASButton> {
borderRadius: BorderRadius.circular(widget.radius ?? 15.5.w)), borderRadius: BorderRadius.circular(widget.radius ?? 15.5.w)),
color: widget.bgcolor ?? Color(0xFFFFFFFF), color: widget.bgcolor ?? Color(0xFFFFFFFF),
elevation: 0, elevation: 0,
focusElevation: 0,
highlightElevation: 0,
hoverElevation: 0,
); );
} }
} }

@ -17,7 +17,7 @@ class ASGradientButton extends StatefulWidget {
final TextStyle textStyle; final TextStyle textStyle;
/// ///
final Padding padding; final EdgeInsetsGeometry padding;
/// ///
final VoidCallback onPressed; final VoidCallback onPressed;
@ -33,9 +33,15 @@ class ASGradientButton extends StatefulWidget {
/// ///
final double width; final double width;
///
final Color disableColor;
///
final Color disableTextColor;
ASGradientButton( ASGradientButton(
{Key key, {Key key,
this.title, @required this.title,
this.textColor, this.textColor,
this.radius, this.radius,
this.textStyle, this.textStyle,
@ -44,20 +50,43 @@ class ASGradientButton extends StatefulWidget {
this.colors, this.colors,
this.width, this.width,
this.begin, this.begin,
this.end}) this.end,
this.disableColor,
this.disableTextColor})
: super(key: key); : super(key: key);
ASGradientButton.pay({ ASGradientButton.pay({
Key key, Key key,
this.title, @required this.title,
this.textStyle, this.textStyle,
this.padding,
this.onPressed, this.onPressed,
this.disableColor,
this.disableTextColor,
}) : textColor = Color(0xD9FFFFFF), }) : textColor = Color(0xD9FFFFFF),
radius = 19.w, radius = 19.w,
colors = [Color(0xFFF89B14), Color(0xFFF86B140)], colors = [Color(0xFFF89B14), Color(0xFFF86B14)],
width = 100.w, width = 100.w,
begin = Alignment.centerLeft, begin = Alignment.centerLeft,
end = Alignment.centerRight, end = Alignment.centerRight,
padding = EdgeInsets.symmetric(vertical: 8.w),
super(key: key);
ASGradientButton.operation(
{Key key,
@required this.title,
this.textColor,
this.onPressed,
this.disableColor,
this.width,
this.radius,
this.begin,
this.end,
this.padding,
this.disableTextColor})
: textStyle = TextStyle(
color: Color(0xFFFFFFFF),
fontSize: 14.sp,
fontWeight: FontWeight.bold),
colors = [Color(0xFFFFA700), Color(0xFFFFBD00)],
super(key: key); super(key: key);
@override @override
@ -68,27 +97,28 @@ class _ASGradientButtonState extends State<ASGradientButton> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
width: widget.width ?? 100.w, width: widget.width ?? 110.w,
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient( gradient: LinearGradient(
begin: widget.begin ?? Alignment.centerLeft, begin: widget.begin ?? Alignment.centerLeft,
end: widget.end ?? Alignment.centerRight, end: widget.end ?? Alignment.centerRight,
colors: widget.colors ?? [Color(0xFFF89B14), Color(0xFFF86B140)], colors: widget.colors ?? [Color(0xFFFFA700), Color(0xFFFFBD00)],
), ),
borderRadius: BorderRadius.circular(widget.radius ?? 19.w), borderRadius: BorderRadius.circular(widget.radius ?? 20.w),
), ),
child: MaterialButton( child: MaterialButton(
minWidth: widget.width ?? 100.w, disabledColor: widget.disableColor ?? Colors.grey,
textColor: widget.textColor ?? Color(0xD9FFFFFF),
disabledTextColor: widget.disableTextColor ?? Color(0x73000000),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: widget.onPressed, onPressed: widget.onPressed,
child: widget.title is String child: widget.title is String
? Text(widget.title, ? Text(widget.title,
style: widget.textStyle ?? style: widget.textStyle ?? TextStyle(fontSize: 18.sp))
TextStyle(
color: widget.textColor ?? Color(0xD9FFFFFF),
fontSize: 18.sp))
: widget.title, : widget.title,
padding: widget.padding ?? EdgeInsets.symmetric(vertical: 8.w), padding: widget.padding ?? EdgeInsets.symmetric(vertical: 10.w),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(widget.radius ?? 20.w)),
elevation: 0, elevation: 0,
), ),
); );

@ -34,6 +34,12 @@ class ASLongButton extends StatefulWidget {
/// ///
final double width; final double width;
///
final Color disableColor;
///
final Color disableTextColor;
ASLongButton( ASLongButton(
{Key key, {Key key,
@required this.title, @required this.title,
@ -45,7 +51,9 @@ class ASLongButton extends StatefulWidget {
this.outline = false, this.outline = false,
this.outlineColor, this.outlineColor,
this.onPressed, this.onPressed,
this.width}) this.width,
this.disableColor,
this.disableTextColor})
: super(key: key); : super(key: key);
ASLongButton.solid({ ASLongButton.solid({
@ -57,9 +65,11 @@ class ASLongButton extends StatefulWidget {
@required this.title, @required this.title,
this.onPressed, this.onPressed,
this.width, this.width,
this.disableTextColor,
}) : bgColor = Color(0xFFF6B72D), }) : bgColor = Color(0xFFF6B72D),
textColor = Color(0xFFFFFFFF), textColor = Color(0xFFFFFFFF),
outline = false, outline = false,
disableColor = Color(0xFFC1BDB5),
super(key: key); super(key: key);
ASLongButton.hollow( ASLongButton.hollow(
{Key key, {Key key,
@ -68,7 +78,9 @@ class ASLongButton extends StatefulWidget {
this.padding, this.padding,
this.onPressed, this.onPressed,
@required this.title, @required this.title,
this.width}) this.width,
this.disableColor,
this.disableTextColor})
: bgColor = Color(0xFFFFFFFF), : bgColor = Color(0xFFFFFFFF),
textColor = Color(0xFFF6B72D), textColor = Color(0xFFF6B72D),
outline = true, outline = true,
@ -83,15 +95,14 @@ class _ASLongButtonState extends State<ASLongButton> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialButton( return MaterialButton(
minWidth: widget.width ?? 280.w, minWidth: widget.width ?? 280.w,
disabledColor: Color(0xFFC1BDB5), disabledColor: widget.disableColor ?? widget.bgColor,
textColor: widget.textColor ?? Color(0xFFFFFFFF),
disabledTextColor: widget.disableTextColor ?? Color(0x73000000),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: widget.onPressed, onPressed: widget.onPressed,
child: widget.title is String child: widget.title is String
? Text(widget.title, ? Text(widget.title,
style: widget.textStyle ?? style: widget.textStyle ?? TextStyle(fontSize: 20.sp))
TextStyle(
color: widget.textColor ?? Color(0xFFFFFFFF),
fontSize: 20.sp))
: widget.title, : widget.title,
padding: widget.padding ?? EdgeInsets.symmetric(vertical: 8.w), padding: widget.padding ?? EdgeInsets.symmetric(vertical: 8.w),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
@ -101,6 +112,9 @@ class _ASLongButtonState extends State<ASLongButton> {
borderRadius: BorderRadius.circular(widget.radius ?? 22.5.w)), borderRadius: BorderRadius.circular(widget.radius ?? 22.5.w)),
color: widget.bgColor ?? Color(0xFFFFFFFF), color: widget.bgColor ?? Color(0xFFFFFFFF),
elevation: 0, elevation: 0,
// // focusElevation: 0,
// // hoverElevation: 0,
highlightElevation: 0,
); );
} }
} }

Loading…
Cancel
Save