Bis*_*ret 1 gridview scrollview flutter
我有一个包含不同组件的屏幕,其中之一是 GridView.builder,无论我做什么,它都不会滚动。
我尝试了不同的方法,但没有任何效果,所以我将分享我目前正在尝试的方法:
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: Container(
child: CustomScrollView(
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate(
[
//Some widgets here, some images, some buttons. This section scrolls perfectly.
],
SliverList(
delegate: SliverChildListDelegate(
[
GridView.builder(
//physics: ScrollPhysics(),
shrinkWrap: true,
itemCount: imageURLlist.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
),
itemBuilder: (BuildContext context, int index) {
return ListView(
children: <Widget>[
Image.network(
imageURLlist[index],
height: 150,
width: MediaQuery.of(context).size.width * 0.5,
fit: BoxFit.fill,
),
],
);
}
),
),
],
),
],
),
),
),
}
Run Code Online (Sandbox Code Playgroud)
GridView 部分填充了图像,这很好,但它不可滚动。我可以向下滚动到它,但是一旦到达此部分,我就失去了完全滚动的能力,而且我不知道为什么。
chu*_*han 10
您可以在下面复制粘贴运行完整代码
您可以使用NeverScrollableScrollPhysics()并且在您的情况GridView下ListView
,您可以在没有ListView
GridView.builder(
physics: NeverScrollableScrollPhysics()
...
ListView(
physics: NeverScrollableScrollPhysics()
Run Code Online (Sandbox Code Playgroud)
工作演示
完整代码
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<String> imageURLlist = [
"https://picsum.photos/250?image=9",
"https://picsum.photos/250?image=10",
"https://picsum.photos/250?image=11",
"https://picsum.photos/250?image=12"
];
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: Container(
child: CustomScrollView(slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate(
[
Container(color: Colors.red, height: 150.0),
Container(color: Colors.purple, height: 150.0),
Container(color: Colors.green, height: 150.0),
],
),
),
SliverList(
delegate: SliverChildListDelegate([
GridView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: imageURLlist.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
),
itemBuilder: (BuildContext context, int index) {
return ListView(
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
Image.network(
imageURLlist[index],
height: 150,
width: MediaQuery.of(context).size.width * 0.5,
fit: BoxFit.fill,
),
],
);
}),
]))
])));
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7802 次 |
| 最近记录: |