我需要使用嵌套串列,但我不能給它們一個高度,因為串列可以有自己的長度,具體取決于來自服務器的資訊量。我嘗試繪制一個變體,但它不起作用,我收到一個錯誤 - ParentDataWidget 的使用不正確。
下面是我的代碼 -
return Drawer(
child: Container(
margin: const EdgeInsets.symmetric(vertical: 13, horizontal: 13),
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: catalogDrawer.length,
itemBuilder: (BuildContext context, int index) {
var one = catalogDrawer[index].one;
return Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(catalogDrawer[index].name, style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600),),
Expanded(
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: catalogDrawer[index].one.length,
itemBuilder: (BuildContext context, int i) {
var two = catalogDrawer[index].one[i].two;
return Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(left: 10),
padding: const EdgeInsets.all(10),
color: Colors.yellow,
child: Text(one[i].name,style: TextStyle(fontWeight: FontWeight.w500, fontSize: 15),),
),
Expanded(
// height: two.length > 1 ? 76 : 38,
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: catalogDrawer[index].one[i].two.length,
itemBuilder: (BuildContext context, int a) {
return Container(
margin: const EdgeInsets.only(left: 30),
padding: const EdgeInsets.all(10),
color: Colors.red,
child: Text(two[a].name, style: TextStyle(fontWeight: FontWeight.w500, fontSize: 15),),
);
},
),
),
],
)
);
},
),
),
],
)
);
},
),
),
);
我的問題可以改寫 - 如何使用嵌套串列但不指定高度
uj5u.com熱心網友回復:
當您設定shrinkWraptrue 時,您不需要在Expanded內部使用小部件listview,因此請像這樣洗掉所有內容Expanded:
Drawer(
child: Container(
margin: const EdgeInsets.symmetric(vertical: 13, horizontal: 13),
child: ListView.builder(
shrinkWrap: true,
itemCount: catalogDrawer.length,
itemBuilder: (BuildContext context, int index) {
var one = catalogDrawer[index].one;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(catalogDrawer[index].name, style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600),),
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: catalogDrawer[index].one.length,
itemBuilder: (BuildContext context, int i) {
var two = catalogDrawer[index].one[i].two;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(left: 10),
padding: const EdgeInsets.all(10),
color: Colors.yellow,
child: Text(one[i].name,style: TextStyle(fontWeight: FontWeight.w500, fontSize: 15),),
),
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: catalogDrawer[index].one[i].two.length,
itemBuilder: (BuildContext context, int a) {
return Container(
margin: const EdgeInsets.only(left: 30),
padding: const EdgeInsets.all(10),
color: Colors.red,
child: Text(two[a].name, style: TextStyle(fontWeight: FontWeight.w500, fontSize: 15),),
);
},
),
],
);
},
),
],
);
},
),
),
)
uj5u.com熱心網友回復:
class DemoDemo extends StatefulWidget {
const DemoDemo({Key? key}) : super(key: key);
@override
State<DemoDemo> createState() => _DemoDemoState();
}
class _DemoDemoState extends State<DemoDemo> {
late AppsflyerSdk _appsflyerSdk;
@override
void initState() {
// TODO: implement initState
initialize();
super.initState();
}
Future<bool> initialize() async {
final AppsFlyerOptions options = AppsFlyerOptions(
afDevKey: dotenv.env["DEV_KEY"]!,
appId: dotenv.env["APP_ID"]!,
showDebug: true,
timeToWaitForATTUserAuthorization: 15);
_appsflyerSdk = AppsflyerSdk(options);
final networkUserId = await _appsflyerSdk.getAppsFlyerUID();
_appsflyerSdk.onInstallConversionData((data) {
Adapty.updateAttribution(data,
source: AdaptyAttributionNetwork.appsflyer,
networkUserId: networkUserId);
});
await _appsflyerSdk.initSdk(
registerConversionDataCallback: true,
registerOnAppOpenAttributionCallback: true,
registerOnDeepLinkingCallback: true);
return Future<bool>.value(true);
}
@override
Widget build(BuildContext context) {
final List<CatModel1> catalogDrawer = [
CatModel1(one: [
CatModel2(two: [
CatModel3(tree: [CatModel4(name: "CatModel4")], name: "CatModel3")
], name: "CatModel2")
], name: "CatModel1")
];
return Scaffold(
body: Container(),
drawer: Drawer(
child: Container(
margin: const EdgeInsets.symmetric(vertical: 13, horizontal: 13),
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: catalogDrawer.length,
itemBuilder: (BuildContext context, int index) {
var one = catalogDrawer[index].one;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
catalogDrawer[index].name,
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600),
),
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: catalogDrawer[index].one.length,
itemBuilder: (BuildContext context, int i) {
var two = catalogDrawer[index].one[i].two;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(left: 10),
padding: const EdgeInsets.all(10),
color: Colors.yellow,
child: Text(
one[i].name,
style: TextStyle(
fontWeight: FontWeight.w500, fontSize: 15),
),
),
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: catalogDrawer[index].one[i].two.length,
itemBuilder: (BuildContext context, int a) {
return Container(
margin: const EdgeInsets.only(left: 30),
padding: const EdgeInsets.all(10),
color: Colors.red,
child: Text(
two[a].name,
style: TextStyle(
fontWeight: FontWeight.w500, fontSize: 15),
),
);
},
),
],
);
},
),
],
);
},
),
)),
appBar: AppBar(),
);
}
}
class CatModel1 {
List<CatModel2> one;
String name;
CatModel1({required this.one, required this.name});
}
class CatModel2 {
List<CatModel3> two;
String name;
CatModel2({required this.two, required this.name});
}
class CatModel3 {
List<CatModel4> tree;
String name;
CatModel3({required this.tree, required this.name});
}
class CatModel4 {
String name;
CatModel4({required this.name});
}

uj5u.com熱心網友回復:
fontSize: 15), ), ), Wrap( children: ["1", "2"] .map((e) => Container( margin: const EdgeInsets.only(left: 30), padding: const EdgeInsets.all (10)、顏色:Colors.red、子代:const Text("two[a].name", style: TextStyle(fontWeight: FontWeight.w500, fontSize: 15), ), )) .toList(), ) ] , ); }, ), ], ); }, ), )
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/529380.html
標籤:扑镖颤振布局
