flutter的按钮如何变为不可选中_flutter:选中按钮的自定义

```dart

import 'dart:ffi';

import 'package:flutter/material.dart';

class setting extends StatefulWidget {

@override

_settingStatecreateState() =>_settingState();

}

class_settingStateextendsState {

@override

Widget build(BuildContext context) {

return Scaffold(

body:Container(

width:double.infinity,

child:Column(

mainAxisAlignment:MainAxisAlignment.center,

crossAxisAlignment:CrossAxisAlignment.center,

children: [

customButton(

'状态按钮',

normalColor:Colors.white,

normalTextColor:Colors.black,

selectedColor:Colors.red,

borderWidth:1,

normalBorderColor:Colors.grey,

selectedBorderColor:Colors.blue,

selected:false,

touchDown: (boolselected) {

if(selected) {

returnfalse;

}else{

returntrue;

}

},

)

]),

));

}

}

classcustomButtonextendsStatefulWidget{

boolselected =false;

doubleborderWidth;

ColornormalColor =Colors.white;

StringnormalText ='';

ColornormalTextColor =Colors.black;

ColornormalBorderColor =Colors.black;

ColorselectedColor;

StringselectedText ='';

ColorselectedTextColor;

ColorselectedBorderColor;

FunctiontouchDown;

customButton(this.normalText,

{this.normalColor,

this.normalTextColor,

this.normalBorderColor,

this.selectedColor,

this.selectedText,

this.selectedTextColor,

this.selectedBorderColor,

this.selected ,

this.touchDown,

this.borderWidth =0}) {

if(this.selectedColor ==null) {

this.selectedColor =this.normalColor;

}

if(this.selectedText ==null) {

this.selectedText =this.normalText;

}

if(this.selectedTextColor ==null) {

this.selectedTextColor =this.normalTextColor;

}

if(this.selectedBorderColor ==null) {

this.selectedBorderColor =this.normalBorderColor;

}

}

@override

_customButtonStatecreateState() =>_customButtonState(this.normalText,

normalColor:this.normalColor,

normalTextColor:this.normalTextColor,

normalBorderColor:this.normalBorderColor,

selectedColor:this.selectedColor,

selectedText:this.selectedText,

selectedTextColor:this.selectedTextColor,

selected:this.selected,

selectedBorderColor:this.selectedBorderColor,

touchDown:this.touchDown,

borderWidth:this.borderWidth);

}

class_customButtonStateextendsState {

boolselected;

ColornormalColor;

StringnormalText;

ColornormalTextColor;

ColornormalBorderColor;

ColorselectedColor;

StringselectedText;

ColorselectedTextColor;

ColorselectedBorderColor;

doubleborderWidth;

FunctiontouchDown;

_customButtonState(this.normalText,

{this.normalColor,

this.normalTextColor,

this.normalBorderColor,

this.selectedColor,

this.selectedText,

this.selectedTextColor,

this.selectedBorderColor,

this.selected,

this.touchDown,

this.borderWidth}) {}

@override

Widget build(BuildContext context) {

return  RaisedButton(

autofocus:true,

color:this.selected ?this.selectedColor :this.normalColor,

shape:RoundedRectangleBorder(

borderRadius:BorderRadius.all(Radius.circular(1)),

side:BorderSide(

color:this.selected

?this.selectedBorderColor

:this.normalBorderColor,

width:this.borderWidth,

style:BorderStyle.solid)),

onPressed: () {

boolvalue =this.touchDown(this.selected);

if(value !=this.selected) {

setState(() {

this.selected = value;

});

}

},

child:Container(

child:Row(

mainAxisSize:MainAxisSize.min,

mainAxisAlignment:MainAxisAlignment.center,

crossAxisAlignment:CrossAxisAlignment.center,

children: [

Text(

this.selected ?this.selectedText :this.normalText,

style:TextStyle(

color:this.selected

?this.selectedTextColor

:this.normalTextColor),

),

SizedBox(width:30),

Text(

this.selected ?this.selectedText :this.normalText,

style:TextStyle(

color:this.selected

?this.selectedTextColor

:this.normalTextColor),

),

]

),

),

);

}

}

```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值