현재 Flutter에서 Android 앱을 개발 중입니다. 둥근 버튼을 어떻게 추가 할 수 있습니까?
RaisedButton 위젯을 사용할 수 있습니다. 제기 버튼 위젯에는 아래 스 니펫과 같이 활용할 수있는 모양 속성이 있습니다.
RaisedButton(
child: Text("Press Me"),
onPressed: null,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
)
단순히 RaisedButton
을 사용하거나 InkWell
을 사용하여 사용자 정의 버튼과 onDoubleTap
, onLongPress
및 etc
과 같은 속성을 가져올 수 있습니다.
new InkWell(
onTap: () => print('hello'),
child: new Container(
//width: 100.0,
height: 50.0,
decoration: new BoxDecoration(
color: Colors.blueAccent,
border: new Border.all(color: Colors.white, width: 2.0),
borderRadius: new BorderRadius.circular(10.0),
),
child: new Center(child: new Text('Click Me', style: new TextStyle(fontSize: 18.0, color: Colors.white),),),
),
),
splashColor
위젯에서 highlightColor
, InkWell
속성을 사용하려면 컨테이너를 꾸미는 대신 Material
위젯을 InkWell
위젯의 부모로 사용하십시오 (장식 속성 삭제). 이유를 읽으시겠습니까? .
간단히 RaisedButton
Padding(
padding: EdgeInsets.only(left: 150.0, right: 0.0),
child: RaisedButton(
textColor: Colors.white,
color: Colors.black,
child: Text("Search"),
onPressed: () {},
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
),
)
산출:
여러 가지 방법이 있습니다. 나는 여기에 몇 가지를 나열하고 있습니다.
(1) RoundedRectangleBorder
사용
RaisedButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
onPressed: () {},
child: Text("Button"),
)
(2) ClipRRect
사용
ClipRRect(
borderRadius: BorderRadius.circular(40),
child: RaisedButton(
onPressed: () {},
child: Text("Button"),
),
)
(3) ClipOval
사용
ClipOval(
child: RaisedButton(
onPressed: () {},
child: Text("Button"),
),
)
(4) ButtonTheme
사용
ButtonTheme(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
child: RaisedButton(
onPressed: () {},
child: Text("Button"),
),
)
(5) StadiumBorder
사용
RaisedButton(
shape: StadiumBorder(),
onPressed: () {},
child: Text("Button"),
)
특히이 문서 페이지에 익숙해 져야합니다 : rounding corners .
이 문서는 이미 익숙한 경우 구성 요소의 스타일과 CSS의 해당 스타일을 변경하는 방법을 보여줍니다.
아래 코드를 사용하여 그라디언트 색상의 둥근 버튼을 만들 수 있습니다.
Container(
width: 130.0,
height: 43.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
gradient: LinearGradient(
// Where the linear gradient begins and ends
begin: Alignment.topRight,
end: Alignment.bottomLeft,
// Add one stop for each color. Stops should increase from 0 to 1
stops: [0.1, 0.9],
colors: [
// Colors are easy thanks to Flutter's Colors class.
Color(0xff1d83ab),
Color(0xff0cbab8),
],
),
),
child: FlatButton(
child: Text(
'Sign In',
style: TextStyle(
fontSize: 16.0,
fontFamily: 'Righteous',
fontWeight: FontWeight.w600,
),
),
textColor: Colors.white,
color: Colors.transparent,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(30.0)),
onPressed: () {
},
),
);
BoxDecoration
내부의 색상 속성에 투명 색상을 전달하여이 버튼을 투명 둥근 버튼에 사용할 수 있습니다. 예. color: Colors.transparent
. 또한이 버튼은 Container
및 GestureDetector
위젯 만 사용합니다.
Container(
height: 50.0,
child: GestureDetector(
onTap: () {},
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xFFF05A22),
style: BorderStyle.solid,
width: 1.0,
),
color: Colors.transparent,
borderRadius: BorderRadius.circular(30.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
child: Text(
"BUTTON",
style: TextStyle(
color: Color(0xFFF05A22),
fontFamily: 'Montserrat',
fontSize: 16,
fontWeight: FontWeight.w600,
letterSpacing: 1,
),
),
)
],
),
),
),
)
FlatButton 및 RaisedButton에 모양을 사용할 수 있습니다.
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)),
모양 : new RoundedRectangleBorder (borderRadius : 새 BorderRadius.circular (0.0), 측면 : BorderSide (color : Colors.red)),
.
Row( mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[ FlatButton( shape: new RoundedRectangleBorder( borderRadius: new BorderRadius.circular(18.0), side: BorderSide(color: Colors.red)), color: Colors.white, textColor: Colors.red, padding: EdgeInsets.all(8.0), onPressed: () {}, child: Text( "Add to Cart".toUpperCase(), style: TextStyle( fontSize: 14.0, ), ), ), SizedBox(width: 10), RaisedButton( shape: new RoundedRectangleBorder( borderRadius: new BorderRadius.circular(18.0), side: BorderSide(color: Colors.red)), onPressed: () {}, color: Colors.red, textColor: Colors.white, child: Text("Buy now".toUpperCase(), style: TextStyle(fontSize: 14)), ), ], )
머티리얼 앱을 메인 위젯으로 사용하는 경우 언제든지 머티리얼 버튼을 사용할 수 있습니다.
Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Material(
borderRadius: BorderRadius.circular(30.0),//Set this up for rounding corners.
shadowColor: Colors.lightBlueAccent.shade100,
child: MaterialButton(
minWidth: 200.0,
height: 42.0,
onPressed: (){//Actions here//},
color: Colors.lightBlueAccent,
child: Text('Log in', style: TextStyle(color: Colors.white),),
),
),
)