你好,我有一些問題,我需要在我的flutter代碼上把按鈕放在一起,
var selectedButton = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
標題。Text(widget.title),
),
body: 中心(
孩子。容器(
margin: EdgeInsets.all(16)。
裝飾。BoxDecoration(
borderRadius: borderRadius.round(16)。
形狀。BoxShape.rectangle,
邊界。border.all(color: Colors.blue, width: 3))。
孩子。行(
兒童。[
展開(
孩子。容器(
裝飾。BoxDecoration(
borderRadius: borderRadius.round(8)。
形狀。BoxShape.rectangle,
color: selectedButton == 0 ? Colors.blue : Colors.white)。
孩子。TextButton(
onPressed: () {
setState(() {
selectedButton = 0;
});
},
樣式。TextButton.styleFrom(
primary: selectedButton == 0 ? Colors.white : Colors.blue,
),
孩子。文本(
'TextButton'。
風格。TextStyle(fontSize: 16)。
),
),
)),
展開(
孩子。容器(
裝飾。BoxDecoration(
borderRadius: borderRadius.round(8)。
形狀。BoxShape.rectangle,
color: selectedButton == 1 ? Colors.blue : Colors.white)。
孩子。TextButton(
onPressed: () {
setState(() {
selectedButton = 1;
});
},
樣式。TextButton.styleFrom(
primary: selectedButton == 1 ? Colors.white : Colors.blue,
),
孩子。文本(
'TextButton'。
風格。TextStyle(fontSize: 16)。
),
),
)),
],
),
),
),
);
}
uj5u.com熱心網友回復:
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
容器(
width: 260,
孩子。行(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
SizedBox(
width: 130,
高度。50。
孩子。TextButton(
風格。ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.blue),
形狀。MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: borderRadius.all(
Radius.round(
15,
),
),
),
),
),
onPressed: () {},
孩子。文本(
'Login'。
style: TextStyle(color: Colors.white),
),
),
),
SizedBox(
width: 130,
高度。50。
孩子。TextButton(
風格。ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.white),
),
onPressed: () {},
孩子。Text(
'Daftar'。
style: TextStyle(color: Colors.blue),
),
),
),
],
),
),
],
),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/329164.html
標籤:
上一篇:漂浮的動作按鈕向上和向下滾動
