使用 2 ListView.builder 時無法正確滾動
我是新手,無法正確滾動。我正在使用 2 listView.builders,但我不知道我做錯了什么。我試圖將物理形式 NeverScrollableScrollPhysics 更改為 AlwaysScrollableScrollPhysics 但仍然無法正確滾動
這是代碼。
import 'package:flutter/material.dart';
import 'package:map/containerWidget.dart';
class Body extends StatefulWidget {
const Body({Key? key}) : super(key: key);
@override
_BodyState createState() => _BodyState();
}
class _BodyState extends State<Body> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: 3,
itemBuilder: (BuildContext context, int index) {
return SizedBox(
height: 10000,
child: Padding(
padding: const EdgeInsets.only(left: 5, right: 5, top: 5),
child: Scaffold(
appBar: AppBar(),
body: DefaultTabController(
length: 4,
child: NestedScrollView(
headerSliverBuilder: (context, _) {
return [
SliverList(
delegate: SliverChildListDelegate(
[
ListView.builder(
shrinkWrap: true,
physics:
const AlwaysScrollableScrollPhysics(),
itemCount: 3,
itemBuilder:
(BuildContext context, int index) {
return Column(
crossAxisAlignment:
CrossAxisAlignment
.center,
children: const [
SizedBox(
width: 300,
height: 300,
child: Card(
color: Colors.blue,
)),
]);
})
],
),
),
];
},
body: Column(
children: <Widget>[
Material(
color: Colors.white,
child: TabBar(
isScrollable: true,
labelColor: Colors.black,
unselectedLabelColor: Colors.grey[400],
indicatorWeight: 1.5,
indicatorColor: Colors.black,
tabs: const [
Tab(
text: "1",
),
Tab(
text: "2",
),
Tab(
text: "3",
),
Tab(
text: "4",
),
],
),
),
const Expanded(
child: TabBarView(
children: [
ContainerWidget(),
ContainerWidget(),
ContainerWidget(),
ContainerWidget(),
],
),
),
],
),
),
),
),
),
);
}));
}
}
uj5u.com熱心網友回復:
您不應該嵌套兩個 ListView 小部件來實作多個串列。這會產生沖突。
添加兩個串列而不會出現任何滾動故障。使用CustomScrollView小部件。示例 https://api.flutter.dev/flutter/widgets/CustomScrollView-class.html
按照上面的鏈接,它有詳細的用法說明。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/457142.html
標籤:扑
上一篇:沒有改變容器的顏色
