我試圖顯示ListView.builder在```擴展磁貼中使用的專案串列,但它沒有顯示任何內容,也沒有給出任何錯誤。
這是擴展瓷磚的代碼
customExpansionTile(context, "Additional discount", true,
Icon(Icons.add_task, color: HexColor("#5344ed")), <Widget>[
Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: MediaQuery.of(context).size.width * 0.9,
child: Row(
children: [
SizedBox(
width: MediaQuery.of(context).size.width * 0.022,
),
textformfieldCustomwithouticon(
context,
TextInputType.number,
MediaQuery.of(context).size.width * 0.4,
quantity,
"Enter the quantity",
"Quantity ",
55.0),
SizedBox(
width: MediaQuery.of(context).size.width * 0.03,
),
textformfieldCustomwithouticon(
context,
TextInputType.number,
MediaQuery.of(context).size.width * 0.42,
discountPercentage,
"Enter the discount",
"Discount",
55.0),
],
),
),
SizedBox20(),
customButton(context, "Add", () {},
MediaQuery.of(context).size.width * 0.85, 55.0),
SizedBox20(),
// here i'm using Listview.builder
Flexible(
fit: FlexFit.loose,
child: Container(
width:MediaQuery.of(context).size.width * 0.9,
height:MediaQuery.of(context).size.height*0.5,
child: ListView.builder(
itemCount: books.length,
itemBuilder: (context, index) {
final book = books[index];
return buildDiscount(book);
},
),
)),
],
),
SizedBox10()
]),
構建折扣代碼:
Widget buildDiscount(Book book) => Card(
elevation: 0.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
child: ListTile(
trailing: SizedBox(
height: 100,
child: Column(
children: [
InkWell(
onTap: () {
_getVariantRowInfo(book.id, book.id, book.id);
},
child: Icon(Icons.edit, color: HexColor("#7367f0")),
),
SizedBox(
height: 5,
),
InkWell(
onTap: () {},
child: Icon(Icons.delete, color: HexColor("#7367f0")),
),
],
),
),
title: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 15, 0),
child: Text(
" Quantity: 90",
style: GoogleFonts.montserrat(
fontSize: 15, fontWeight: FontWeight.bold,color: Colors.red),
),
),
horizontalTitleGap: 10,
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
" Discount %: " "10%",
style: GoogleFonts.montserrat(fontSize: 15),
),
Text(
" Discounted Price: " "90",
style: GoogleFonts.montserrat(fontSize: 15),
),
SizedBox(
height: 10,
)
],
),
));
輸出

請幫忙,我做錯的地方。
自定義擴展平鋪
Widget customExpansionTile(context, text,initiallyExpanded,leading,childern) {
return GestureDetector(
child: Container(
width:MediaQuery.of(context).size.width*0.9,
// height: 400,
decoration: BoxDecoration(
border: Border.all(color: HexColor("#6e6b7b")),
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
child: ExpansionTile(
title: Text(
text,
style: GoogleFonts.montserrat(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: HexColor("#5344ed")),
),
initiallyExpanded:initiallyExpanded,
leading:leading,
children: childern,
),
),
);
}
uj5u.com熱心網友回復:
如果你使用的容器寬度和高度u需要不靈活小部件一樣Expanded,并Flexible在父母,洗掉Flexible,還可以添加拆封:真實的ListView.builder
Flexible( /// <--- remove this parent or remove Container if you get flexible ListView.builder
fit: FlexFit.loose,
child: Container(
width:MediaQuery.of(context).size.width * 0.9,
height:MediaQuery.of(context).size.height*0.5,
child: ListView.builder(
itemCount: books.length,
itemBuilder: (context, index) {
final book = books[index];
return buildDiscount(book);
},
),
)),
或者
嘗試使用Expanded類似的東西
Expanded:
child customExpansionTile(context, "Additional discount", true,
Icon(Icons.add_task, color: HexColor("#5344ed")), [
Expanded: child:
Column(
mainAxisSize: MainAxisSize.min,
.....
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/330515.html
下一篇:如何使用換行在串列視圖中顯示容器
