ListView with Images

This Article is posted by seven.srikanth at 8/27/2018 2:10:17 AM



This Flutter example will help you to create a ListView with images. In order to try this example, all you need to do is to copy paste the below code into main.dart file of your freshly created flutter project.
The final output of this example is as below,
Before moving into this, here is the latest article which I have written inlines to this.
ListView with Images from the Internet and below is the screenshot of the app we created. Check it out. 
Full code from main.dart
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final title = "ListView List";
return MaterialApp(
title: title,
home: Scaffold(appBar: AppBar(
title: Text(title),
),
body: new ListView(
shrinkWrap: true,
padding: const EdgeInsets.all(20.0),
children: List.generate(choices.length, (index) {
return Center(
child: ChoiceCard(choice: choices[index], item: choices[index]),
);
}
)
)
)
);
}
}
class Choice {
const Choice({this.title, this.icon});
final String title;
final IconData icon;
}
const List<Choice> choices = const <Choice>[
const Choice(title: 'This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car.', icon: Icons.directions_car),
const Choice(title: 'This is a Bicycle, because its a Bicycle. So, it\'s a Bicycle. This is a Bicycle, because its a Bicycle. So, it\'s a Bicycle. This is a Bicycle, because its a Bicycle. So, it\'s a Bicycle.', icon: Icons.directions_bike),
const Choice(title: 'This is a Boat, because its a Boat. So, it\'s a Boat', icon: Icons.directions_boat),
const Choice(title: 'This is a Bus, because its a Bus. So, it\'s a Bus', icon: Icons.directions_bus),
const Choice(title: 'This is a Train, because its a Train. So, it\'s a Train', icon: Icons.directions_railway),
const Choice(title: 'This is a Walk, because its a Walk. So, it\'s a Walk', icon: Icons.directions_walk),
const Choice(title: 'This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car.', icon: Icons.directions_car),
const Choice(title: 'This is a Car, because its a car. So, it\'s a car', icon: Icons.directions_car),
const Choice(title: 'This is a Bicycle, because its a Bicycle. So, it\'s a Bicycle', icon: Icons.directions_bike),
const Choice(title: 'This is a Boat, because its a Boat. So, it\'s a Boat', icon: Icons.directions_boat),
const Choice(title: 'This is a Bus, because its a Bus. So, it\'s a Bus', icon: Icons.directions_bus),
const Choice(title: 'This is a Train, because its a Train. So, it\'s a Train', icon: Icons.directions_railway),
const Choice(title: 'This is a Walk, because its a Walk. So, it\'s a Walk', icon: Icons.directions_walk),
const Choice(title: 'This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car.', icon: Icons.directions_car),
const Choice(title: 'This is a Car, because its a car. So, it\'s a car', icon: Icons.directions_car),
const Choice(title: 'This is a Bicycle, because its a Bicycle. So, it\'s a Bicycle', icon: Icons.directions_bike),
const Choice(title: 'This is a Boat, because its a Boat. So, it\'s a Boat', icon: Icons.directions_boat),
const Choice(title: 'This is a Bus, because its a Bus. So, it\'s a Bus', icon: Icons.directions_bus),
const Choice(title: 'This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car. This is a Car, because its a car. So, it\'s a car.', icon: Icons.directions_car),
const Choice(title: 'This is a Train, because its a Train. So, it\'s a Train', icon: Icons.directions_railway),
const Choice(title: 'This is a Walk, because its a Walk. So, it\'s a Walk', icon: Icons.directions_walk),
const Choice(title: 'This is a Car, because its a car. So, it\'s a car', icon: Icons.directions_car),
const Choice(title: 'This is a Bicycle, because its a Bicycle. So, it\'s a Bicycle', icon: Icons.directions_bike),
const Choice(title: 'This is a Boat, because its a Boat. So, it\'s a Boat', icon: Icons.directions_boat),
const Choice(title: 'This is a Bus, because its a Bus. So, it\'s a Bus', icon: Icons.directions_bus),
const Choice(title: 'This is a Train, because its a Train. So, it\'s a Train', icon: Icons.directions_railway),
const Choice(title: 'This is a Walk, because its a Walk. So, it\'s a Walk', icon: Icons.directions_walk),
];
class ChoiceCard extends StatelessWidget {
const ChoiceCard(
{Key key, this.choice, this.onTap, @required this.item, this.selected: false}
) : super(key: key);
final Choice choice;
final VoidCallback onTap;
final Choice item;
final bool selected;
@override
Widget build(BuildContext context) {
TextStyle textStyle = Theme.of(context).textTheme.display1;
if (selected)
textStyle = textStyle.copyWith(color: Colors.lightGreenAccent[400]);
return Card(
color: Colors.white,
child: Row(
children: <Widget>[
new Container(
padding: const EdgeInsets.all(8.0),
alignment: Alignment.topLeft,
child: Icon(choice.icon, size:80.0, color: textStyle.color,)),
new Expanded(
child: new Container(
padding: const EdgeInsets.all(10.0),
alignment: Alignment.topLeft,
child:
Text(choice.title, style: null, textAlign: TextAlign.left, maxLines: 5,),
)
),
],
crossAxisAlignment: CrossAxisAlignment.start,
)
);
}
}
Note: Instead of images, I used Icons. But it will be easy to replace them with Images. 
Thanks,
Srikanth

Tags: Flutter example will help you to create a ListView with images; Mobile App with ListView and Images; ListView with Images on Mobile App;








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com