【发布时间】:2021-05-17 14:13:31
【问题描述】:
我想在一个屏幕上有太多选项类型的高架按钮,需要可滚动。我试过行小部件而不是列并给出错误,我不知道如何根据屏幕大小将它们并排和下方放置。请指导我哪里出错了?谢谢。试过的代码如下:-
Container(
child: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 70, vertical: 20),
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: hobbieslist.length,
itemBuilder: (BuildContext context, index) {
return Padding(
padding: const EdgeInsets.all(4.0),
child: ElevatedButton(
child: Text("${hobbieslist[index]["name"]}"
,style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500,
// color: man ? mRed : Colors.blueGrey
),
),
onPressed: (){
setState(() {
if (selected.length < 3) {
hobbieslist[index]["ontap"] =
!hobbieslist[index]["ontap"];
if (hobbieslist[index]["ontap"]) {
selected.add(hobbieslist[index]["name"]);
print(hobbieslist[index]["name"]);
print(selected);
} else {
selected.remove(hobbieslist[index]["name"]);
print(selected);
}
} else {
if (hobbieslist[index]["ontap"]) {
hobbieslist[index]["ontap"] =
!hobbieslist[index]["ontap"];
selected.remove(hobbieslist[index]["name"]);
} else {
Fluttertoast.showToast( msg: "Can only select 5",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 3,
backgroundColor: Colors.blueGrey,
textColor: Colors.white,
fontSize: 16.0);
}
}
});
},
style: ElevatedButton.styleFrom(
primary: hobbieslist[index]["ontap"] ? mRed : Colors.blueGrey,
onPrimary: white,
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.7)
),
),
)
);
},
),
),
],
),
),
),
【问题讨论】:
标签: flutter dart flutter-layout flutter-animation