
我是新手,我嘗試使用 listview.builder 進行此操作,但它不起作用。我還查找了有關堆疊溢位先前問題的錯誤,但沒有任何幫助。我想制作一個水平串列作為影像并顯示一些資料并更改所選專案的顏色。但是一次只能選擇一個專案,當我選擇其他專案時,之前選擇的專案應該被取消選擇。任何幫助,將不勝感激。
uj5u.com熱心網友回復:
您需要在使用水平 listView 時提供高度。關于無限高度/寬度的精彩視頻 | 解碼顫振
你可以玩這個小部件。
class MyApp extends StatefulWidget {
MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int? _selectedIndex; // if you want to provide default selection, init here
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
SizedBox(
height: 30,
), //top level space
SizedBox(
height: 68, // play with height
child: ListView.builder(
itemCount: 33, //number of item you like show
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: () {
setState(() {
_selectedIndex = index;
});
},
child: Container(
alignment: Alignment.center,
width: 48,
height: 48,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color:
_selectedIndex == index ? Colors.blue : Colors.grey,
),
child: Text("$index"),
),
),
);
},
),
)
],
),
);
}
}
在flutter.dev上查看有關布局的更多資訊
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/496689.html
上一篇:UWPGridView/ListView:可以修改拖放回應嗎?
下一篇:從冗余索引串列更新矩陣
