按钮修改

null_safety
张萌 4 years ago
parent 7c257c7339
commit 1409eafa20

@ -45,13 +45,18 @@ class _MyHomePageState extends State<MyHomePage> {
), ),
body: ListView( body: ListView(
children: [ children: [
ASButton.delete('删除订单', () {}), ASButton.delete(title: '删除订单',onpressed: (){},),
ASButton.info('删除订单', () {}), ASButton.info(title: '删除订单',onpressed: (){},),
ASButton.warn('删除订单', () {}), ASButton.warn(title: '删除订单',onpressed: (){},),
ASButton.opration('删除订单', (){}), ASButton.opration(title: '删除订单',onpressed: (){},),
SizedBox(height: 12.w), SizedBox(height: 12.w),
ASLongButton.solid('确认', () {}), ASLongButton.solid(title: '确认',onpressed: (){},),
ASLongButton.hollow('确认', () {}), ASLongButton.hollow(title: '确认',onpressed: (){},),
Padding(
padding: EdgeInsets.symmetric(horizontal: 100.w),
child: ASLongButton.solid(title: 'null',onpressed:(){} ),
),
TextButton( TextButton(
onPressed: () { onPressed: () {
Get.to(ExampleScaffold()); Get.to(ExampleScaffold());

@ -32,6 +32,8 @@ class ASButton extends StatefulWidget {
/// ///
final VoidCallback onpressed; final VoidCallback onpressed;
///
final double width;
ASButton({ ASButton({
Key key, Key key,
this.bgcolor, this.bgcolor,
@ -42,31 +44,60 @@ class ASButton extends StatefulWidget {
this.textStyle, this.textStyle,
this.padding, this.padding,
@required this.title, @required this.title,
@required this.onpressed, this.onpressed,
this.width,
}) : super(key: key); }) : super(key: key);
ASButton.warn(this.title, this.onpressed, ASButton.warn(
{Key key, this.textStyle, this.padding, this.radius, this.bgcolor}) {Key key,
this.textStyle,
this.padding,
this.radius,
this.bgcolor,
this.onpressed,
@required this.title,
this.width})
: outline = true, : outline = true,
outlineColor = Color(0xFFE50112), outlineColor = Color(0xFFE50112),
textColor = Color(0xFFE50112), textColor = Color(0xFFE50112),
super(key: key); super(key: key);
ASButton.info(this.title, this.onpressed, ASButton.info(
{Key key, this.bgcolor, this.radius, this.textStyle, this.padding}) {Key key,
this.bgcolor,
this.radius,
this.textStyle,
this.padding,
@required this.title,
this.onpressed,
this.width})
: outline = true, : outline = true,
outlineColor = Color(0x73000000), outlineColor = Color(0x73000000),
textColor = Color(0xD9000000), textColor = Color(0xD9000000),
super(key: key); super(key: key);
ASButton.delete(this.title, this.onpressed, ASButton.delete(
{Key key, this.radius, this.outlineColor, this.textStyle, this.padding}) {Key key,
this.radius,
this.outlineColor,
this.textStyle,
this.padding,
@required this.title,
this.onpressed,
this.width})
: bgcolor = Color(0xFFFFB600), : bgcolor = Color(0xFFFFB600),
textColor = Color(0xD9FFFFFF), textColor = Color(0xD9FFFFFF),
outline = false, outline = false,
super(key: key); super(key: key);
ASButton.opration(this.title, this.onpressed, ASButton.opration(
{Key key, this.radius, this.outlineColor, this.textStyle, this.padding}) {Key key,
this.radius,
this.outlineColor,
this.textStyle,
this.padding,
@required this.title,
this.onpressed,
this.width})
: bgcolor = Color(0xFFF2F2F2), : bgcolor = Color(0xFFF2F2F2),
textColor = Color(0xD9000000), textColor = Color(0xD9000000),
outline = false, outline = false,
@ -80,6 +111,7 @@ class _ASButtonState extends State<ASButton> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialButton( return MaterialButton(
minWidth: widget.width ?? 75.w,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: widget.onpressed, onPressed: widget.onpressed,
child: widget.title is String child: widget.title is String
@ -89,8 +121,7 @@ class _ASButtonState extends State<ASButton> {
color: widget.textColor ?? Color(0xFFFFB600), color: widget.textColor ?? Color(0xFFFFB600),
fontSize: 13.sp)) fontSize: 13.sp))
: widget.title, : widget.title,
padding: widget.padding ?? padding: widget.padding ?? EdgeInsets.symmetric(vertical: 6.w),
EdgeInsets.symmetric(vertical: 6.w, horizontal: 12.w),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
side: widget.outline side: widget.outline
? BorderSide(color: widget.outlineColor, width: 0.5.w) ? BorderSide(color: widget.outlineColor, width: 0.5.w)

@ -31,6 +31,9 @@ class ASLongButton extends StatefulWidget {
/// ///
final VoidCallback onpressed; final VoidCallback onpressed;
///
final double width;
ASLongButton( ASLongButton(
{Key key, {Key key,
@required this.title, @required this.title,
@ -41,23 +44,31 @@ class ASLongButton extends StatefulWidget {
this.padding, this.padding,
this.outline = false, this.outline = false,
this.outlineColor, this.outlineColor,
@required this.onpressed}) this.onpressed,
this.width})
: super(key: key); : super(key: key);
ASLongButton.solid( ASLongButton.solid({
this.title,
this.onpressed, {
Key key, Key key,
this.textStyle, this.textStyle,
this.padding, this.padding,
this.outlineColor, this.outlineColor,
this.radius, this.radius,
@required this.title,
this.onpressed,
this.width,
}) : bgColor = Color(0xFFF6B72D), }) : bgColor = Color(0xFFF6B72D),
textColor = Color(0xFFFFFFFF), textColor = Color(0xFFFFFFFF),
outline = false, outline = false,
super(key: key); super(key: key);
ASLongButton.hollow(this.title, this.onpressed, ASLongButton.hollow(
{Key key, this.radius, this.textStyle, this.padding}) {Key key,
this.radius,
this.textStyle,
this.padding,
this.onpressed,
@required this.title,
this.width})
: bgColor = Color(0xFFFFFFFF), : bgColor = Color(0xFFFFFFFF),
textColor = Color(0xFFF6B72D), textColor = Color(0xFFF6B72D),
outline = true, outline = true,
@ -71,6 +82,8 @@ class _ASLongButtonState extends State<ASLongButton> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialButton( return MaterialButton(
minWidth: widget.width ?? 280.w,
disabledColor: Color(0xFFC1BDB5),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: widget.onpressed, onPressed: widget.onpressed,
child: widget.title is String child: widget.title is String
@ -80,8 +93,7 @@ class _ASLongButtonState extends State<ASLongButton> {
color: widget.textColor ?? Color(0xFFFFFFFF), color: widget.textColor ?? Color(0xFFFFFFFF),
fontSize: 20.sp)) fontSize: 20.sp))
: widget.title, : widget.title,
padding: widget.padding ?? padding: widget.padding ?? EdgeInsets.symmetric(vertical: 8.w),
EdgeInsets.symmetric(vertical: 8.w, horizontal: 112.w),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
side: widget.outline side: widget.outline
? BorderSide(color: widget.outlineColor, width: 1.w) ? BorderSide(color: widget.outlineColor, width: 1.w)

Loading…
Cancel
Save