【发布时间】:2021-07-31 08:51:25
【问题描述】:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
var items = [
"https://raw.githubusercontent.com/AmmarMohib/Economic-app/master/lib/1.jpeg",
"https://raw.githubusercontent.com/AmmarMohib/Economic-app/master/lib/2.jpeg",
"https://raw.githubusercontent.com/AmmarMohib/Economic-app/master/lib/3.jpeg",
"https://raw.githubusercontent.com/AmmarMohib/Economic-app/master/lib/4.jpeg"
];
var text =[
"Iphone 12",
"Iphone 12",
"Iphone 12",
"Iphone 12",
];
var reviews =[
"5.0 (23 reviews)"
"5.0 (23 reviews)"
"5.0 (23 reviews)"
"5.0 (23 reviews)"
];
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Economic app",
home: Home(),
);
}
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: Text("Economic app",style: TextStyle(color: Colors.black,fontFamily: 'Lobster',fontWeight: FontWeight.w600,fontSize: 30),),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.notifications_active,
color: Colors.black,
),
onPressed: () {
print(Text("hello"));
},
)
],centerTitle: true,backgroundColor: Colors.white,
),
body:GridView.count(
childAspectRatio: (45/15),
crossAxisCount: 1,
mainAxisSpacing: 7.5,
children: List.generate(items.length , (index) {
return Padding(
padding: const EdgeInsets.only(left:20.0,right: 20.0,top: 20.0),
child:ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
color: Colors.white,
child: Center(child: Column(
children: [
GridTile(
child: Title(
color: Colors.red,
child: Row(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10),
child:
Image.network(items[index],height: 110,)
),
Padding(
padding: const EdgeInsets.only(bottom:75.0,left: 10),
child: Text(text[index],style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold),),
),
// IconButton(
// icon: Icon(
// Icons.star_border_purple500,
// color: Colors.yellow,
// ),
// onPressed: () {
// },
// ),
Text(reviews[index])
],
)
)),
])
),
),
),
);
})
)
),
);
}
}
这是我的代码,我想实现文本抛出网格视图计数,我已经在顶部完成了,但是当我在底部实现时,它抛出了索引超出范围索引应小于 1:1 的范围错误,
我已经尝试了很多,但它抛出了这个错误,
请帮助我认为你会理解我的问题
【问题讨论】: