【发布时间】:2021-06-05 04:43:43
【问题描述】:
我是 Flutter 的新手,我正在尝试将 GridView 添加到我的列表视图的末尾,我的目标是在屏幕末尾找到 gridview,但我有错误:
The relevant error-causing widget was:
GridView file:///C:/Users/Fares/AndroidStudioProjects/tl_fantasy/lib/tl/tl.dart:211:33
When the exception was thrown, this was the stack:
#0 RenderViewport.performResize.<anonymous closure> (package:flutter/src/rendering/viewport.dart:1356:15)
#1 RenderViewport.performResize (package:flutter/src/rendering/viewport.dart:1417:6)
#2 RenderObject.layout (package:flutter/src/rendering/object.dart:1756:9)
#3 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:113:14)
#4 RenderObject.layout (package:flutter/src/rendering/object.dart:1777:7)
只有当我在文件末尾添加 gridview 的容器时才会出现此错误
英雄我的代码:
import 'package:flutter/material.dart';
class TL extends StatelessWidget{
List<String> images = [
"https://static.javatpoint.com/tutorial/flutter/images/flutter-logo.png",
"https://static.javatpoint.com/tutorial/flutter/images/flutter-logo.png",
"https://static.javatpoint.com/tutorial/flutter/images/flutter-logo.png",
"https://static.javatpoint.com/tutorial/flutter/images/flutter-logo.png"
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Colors.purple, Colors.blue])
),
child: ListView(
children: [
SizedBox(
height: 20,
),
Container(
margin: EdgeInsets.fromLTRB(10, 0, 0, 0),
child: Text(
"Tunisian League",
style: TextStyle(fontSize: 25, fontWeight: FontWeight.w900, color: Colors.white),
),
),
SizedBox(
height: 30,
),
Container(
margin: EdgeInsets.fromLTRB(15, 0, 15, 0),
child: Column(
children: [
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 10,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 10,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 1,
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
child: Align(
child: Text("Click Here", style: TextStyle(fontSize: 17),textAlign: TextAlign.right, ),
alignment: Alignment.centerLeft,
),
onPressed: (){},
color: Colors.grey.shade300,
textColor: Colors.black,
padding: EdgeInsets.fromLTRB(15, 8, 8, 8),
splashColor: Colors.blue,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
),
SizedBox(
height: 30,
)
],
),
),
Container(
padding: EdgeInsets.all(12.0),
child: GridView.builder(
itemCount: images.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 4.0,
mainAxisSpacing: 4.0
),
itemBuilder: (BuildContext context, int index){
return Image.network(images[index]);
},
)
)
],
),
)
);
}
}
我希望我能找到解决这个问题的方法
【问题讨论】: