I want to display a list of images in GridView. And I'm not able to do that. I want to know the data type for a list of images from the assets and how a constructor would help in this case. I've just started to learn flutter and I don't know how to use it.
class Home extends StatefulWidget {
final String title;
Home({this.title}) : super();
@override
_HomeState createState() => _HomeState();
}
@override
Widget build(BuildContext context) {
var gridView = new GridView.builder(
itemCount: 20,
gridDelegate:
new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (BuildContext context, int index) {
return new GestureDetector(
child: new Card(
elevation: 10,
child: new Container(
// child: *Image list as child*, but don't know about the list datatype hence not created it!
alignment: Alignment.center,
),
),
onTap: () {},
);
});
return new Scaffold(
appBar: new AppBar(
backgroundColor: Colors.red,
title: new Text("Flutter TabBar"),
),
body: Container(
padding: EdgeInsets.all(10),
child: gridView,
),
);
}
}
GestureDetector(
child: new Card(
elevation: 10,
child: new Container(
// child: *Image list as child*, but don't know about the list datatype hence not created it!
alignment: Alignment.center,
child:GridView.builder(
itemCount: items.length,
gridDelegate:
// crossAxisCount stands for number of columns you want for displaying
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (BuildContext context, int index) {
// return your grid widget here, like how your images will be displayed
return Image.network('https://picsum.photos/250?image=9',);
}),
),
),
onTap: () {},
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.