[英]Flutter) I want to know how to apply the same scroll to the child widget list within ListView
(我稍微修改了內容,ExpansionTile => GridView)
我正在創建一個包含許多 GridView 小部件的 ListView。 這樣做的問題是 ListView 具有垂直滾動,但它不適用於 ListView 中的 GridView Widget。 ListView 中的滾動僅適用於空白空間,不適用於子窗口小部件的區域。
Container(
height: size!.height * 0.6,
padding: EdgeInsets.all(common_padding),
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
width: 0.7,
),
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
child: ListView(
children: [
// GridView.builder() .... // many widgets
]
),
)
我的代碼簡要如上。 如何將滾動應用到列表視圖中的子小部件?
我不明白擴展小部件是什么意思,但是您應該將列表中的每個項目逐一堆疊,而不是將所有項目打包在一個小部件中。 例如,根據您的代碼,
MaterialApp(
home: Scaffold(
body: Container(
height: double.infinity,
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
width: 0.7,
),
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
child: ListView(children: [
//putting each item one by one
Container(
height: 500,
color: Colors.blue,
),
Container(
height: 500,
color: Colors.green,
),
Container(
height: 500,
color: Colors.red,
),
Container(
height: 500,
color: Colors.yellow,
),
]),
),
),
);
對 ListView.builder 使用shrinkWrap: true
和physics: const NeverScrollableScrollPhysics(),
試試這個例子:
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: 30,
shrinkWrap: true,
itemBuilder: (BuildContext context, findex) {
return ExpansionTile(
key: Key(findex.toString()),
title: const Text("title",
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold,color: Colors.black),
),
children: [
ListView.builder(
itemCount: 10,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (BuildContext context, sindex) {
return const ListTile(
title: Text(
"user tierl",
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold,color: Colors.black),
),
);
},
),
],
);
},
),
);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.