In this example, I'm going to share code on how to create a ListView which moves to new page when ListView Item is clicked in Flutter. Basically, we are navigating from one page to another.
In this app, we will have a List of Articles and when a user clicks on a article, it will take to a new page. When back button is clicked, it will get back to the actual list.
Here is how the final output is going to look.
 is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.MacBook Pro (sometimes abbreviated as MBP) is a line of Macintosh portable computers introduced in January 2006 by Apple Inc.',
imglink:
color: #ce9178;]('https://images.unsplash.com/photo-1517694712202-14dd9538aa97?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'),
color: #569cd6;](const color: #4ec9b0;](Choice(
id: color: #b5cea8;](2,
title: color: #ce9178;]('MacBook Air',
date: color: #ce9178;]('1 June 2016',
description:
color: #ce9178;]('MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.MacBook Air is a line of laptop computers developed and manufactured by Apple Inc. It consists of a full-size keyboard, a machined aluminum case, and a thin light structure.',
imglink:
color: #ce9178;]('https://images.unsplash.com/photo-1499673610122-01c7122c5dcb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'),
color: #569cd6;](const color: #4ec9b0;](Choice(
id: color: #b5cea8;](3,
title: color: #ce9178;]('iMac',
date: color: #ce9178;]('1 June 2019',
description:
color: #ce9178;]('iMac is a family of all-in-one Macintosh desktop computers designed and built by Apple Inc. It has been the primary part of Apple consumer desktop offerings since its debut in August 1998, and has evolved through seven distinct forms.iMac is a family of all-in-one Macintosh desktop computers designed and built by Apple Inc. It has been the primary part of Apple consumer desktop offerings since its debut in August 1998, and has evolved through seven distinct forms.iMac is a family of all-in-one Macintosh desktop computers designed and built by Apple Inc. It has been the primary part of Apple consumer desktop offerings since its debut in August 1998, and has evolved through seven distinct forms.iMac is a family of all-in-one Macintosh desktop computers designed and built by Apple Inc. It has been the primary part of Apple consumer desktop offerings since its debut in August 1998, and has evolved through seven distinct forms.iMac is a family of all-in-one Macintosh desktop computers designed and built by Apple Inc. It has been the primary part of Apple consumer desktop offerings since its debut in August 1998, and has evolved through seven distinct forms.iMac is a family of all-in-one Macintosh desktop computers designed and built by Apple Inc. It has been the primary part of Apple consumer desktop offerings since its debut in August 1998, and has evolved through seven distinct forms.iMac is a family of all-in-one Macintosh desktop computers designed and built by Apple Inc. It has been the primary part of Apple consumer desktop offerings since its debut in August 1998, and has evolved through seven distinct forms.iMac is a family of all-in-one Macintosh desktop computers designed and built by Apple Inc. It has been the primary part of Apple consumer desktop offerings since its debut in August 1998, and has evolved through seven distinct forms.iMac is a family of all-in-one Macintosh desktop computers designed and built by Apple Inc. It has been the primary part of Apple consumer desktop offerings since its debut in August 1998, and has evolved through seven distinct forms.iMac is a family of all-in-one Macintosh desktop computers designed and built by Apple Inc. It has been the primary part of Apple consumer desktop offerings since its debut in August 1998, and has evolved through seven distinct forms.',
imglink:
color: #ce9178;]('https://images.unsplash.com/photo-1517059224940-d4af9eec41b7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'),
color: #569cd6;](const color: #4ec9b0;](Choice(
id: color: #b5cea8;](4,
title: color: #ce9178;]('Mac Mini',
date: color: #ce9178;]('1 June 2017',
description:
color: #ce9178;]('Mac mini (branded with lowercase "mini") is a desktop computer made by Apple Inc. One of four desktop computers in the current Macintosh lineup, along with the iMac, Mac Pro, and iMac Pro, it uses many components usually featured in laptops to achieve its small size.Mac mini (branded with lowercase "mini") is a desktop computer made by Apple Inc. One of four desktop computers in the current Macintosh lineup, along with the iMac, Mac Pro, and iMac Pro, it uses many components usually featured in laptops to achieve its small size.Mac mini (branded with lowercase "mini") is a desktop computer made by Apple Inc. One of four desktop computers in the current Macintosh lineup, along with the iMac, Mac Pro, and iMac Pro, it uses many components usually featured in laptops to achieve its small size.Mac mini (branded with lowercase "mini") is a desktop computer made by Apple Inc. One of four desktop computers in the current Macintosh lineup, along with the iMac, Mac Pro, and iMac Pro, it uses many components usually featured in laptops to achieve its small size.Mac mini (branded with lowercase "mini") is a desktop computer made by Apple Inc. One of four desktop computers in the current Macintosh lineup, along with the iMac, Mac Pro, and iMac Pro, it uses many components usually featured in laptops to achieve its small size.Mac mini (branded with lowercase "mini") is a desktop computer made by Apple Inc. One of four desktop computers in the current Macintosh lineup, along with the iMac, Mac Pro, and iMac Pro, it uses many components usually featured in laptops to achieve its small size.Mac mini (branded with lowercase "mini") is a desktop computer made by Apple Inc. One of four desktop computers in the current Macintosh lineup, along with the iMac, Mac Pro, and iMac Pro, it uses many components usually featured in laptops to achieve its small size.Mac mini (branded with lowercase "mini") is a desktop computer made by Apple Inc. One of four desktop computers in the current Macintosh lineup, along with the iMac, Mac Pro, and iMac Pro, it uses many components usually featured in laptops to achieve its small size.Mac mini (branded with lowercase "mini") is a desktop computer made by Apple Inc. One of four desktop computers in the current Macintosh lineup, along with the iMac, Mac Pro, and iMac Pro, it uses many components usually featured in laptops to achieve its small size.',
imglink:
color: #ce9178;]('https://www.apple.com/v/mac-mini/f/images/shared/og_image__4mdtjbfhcduu_large.png?201904170831'),
color: #569cd6;](const color: #4ec9b0;](Choice(
id: color: #b5cea8;](5,
title: color: #ce9178;]('Mac Pro',
date: color: #ce9178;]('1 June 2018',
description:
color: #ce9178;]('Mac Pro is a series of workstation and server computer cases designed, manufactured and sold by Apple Inc. since 2006. The Mac Pro, in most configurations and in terms of speed and performance, is the most powerful computer that Apple offers.Mac Pro is a series of workstation and server computer cases designed, manufactured and sold by Apple Inc. since 2006. The Mac Pro, in most configurations and in terms of speed and performance, is the most powerful computer that Apple offers.Mac Pro is a series of workstation and server computer cases designed, manufactured and sold by Apple Inc. since 2006. The Mac Pro, in most configurations and in terms of speed and performance, is the most powerful computer that Apple offers.Mac Pro is a series of workstation and server computer cases designed, manufactured and sold by Apple Inc. since 2006. The Mac Pro, in most configurations and in terms of speed and performance, is the most powerful computer that Apple offers.Mac Pro is a series of workstation and server computer cases designed, manufactured and sold by Apple Inc. since 2006. The Mac Pro, in most configurations and in terms of speed and performance, is the most powerful computer that Apple offers.Mac Pro is a series of workstation and server computer cases designed, manufactured and sold by Apple Inc. since 2006. The Mac Pro, in most configurations and in terms of speed and performance, is the most powerful computer that Apple offers.Mac Pro is a series of workstation and server computer cases designed, manufactured and sold by Apple Inc. since 2006. The Mac Pro, in most configurations and in terms of speed and performance, is the most powerful computer that Apple offers.Mac Pro is a series of workstation and server computer cases designed, manufactured and sold by Apple Inc. since 2006. The Mac Pro, in most configurations and in terms of speed and performance, is the most powerful computer that Apple offers.Mac Pro is a series of workstation and server computer cases designed, manufactured and sold by Apple Inc. since 2006. The Mac Pro, in most configurations and in terms of speed and performance, is the most powerful computer that Apple offers.Mac Pro is a series of workstation and server computer cases designed, manufactured and sold by Apple Inc. since 2006. The Mac Pro, in most configurations and in terms of speed and performance, is the most powerful computer that Apple offers.',
imglink:
color: #ce9178;]('https://i0.wp.com/9to5mac.com/wp-content/uploads/sites/6/2017/01/mac-pro-2-concept-image.png?resize=1000%2C500&quality=82&strip=all&ssl=1'),
];
color: #569cd6;](class color: #4ec9b0;](MyApp color: #569cd6;](extends color: #4ec9b0;](StatelessWidget {
color: #569cd6;](@override
color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext context) {
color: #569cd6;](final title = color: #ce9178;]("Fluttercentral";
color: #c586c0;](return color: #4ec9b0;](Scaffold(
appBar: color: #4ec9b0;](AppBar(
title: color: #4ec9b0;](Text(title),
),
body: color: #c586c0;](new color: #4ec9b0;](ListView(
shrinkWrap: color: #569cd6;](true,
padding: color: #569cd6;](const color: #4ec9b0;](EdgeInsets.color: #dcdcaa;](all(color: #b5cea8;](20.0),
children: color: #4ec9b0;](List.color: #dcdcaa;](generate(choices.length, (index) {
color: #c586c0;](return color: #4ec9b0;](Center(
child: color: #4ec9b0;](ChoiceCard(choice: choices[index], item: choices[index]),
);
})));
}
}
color: #569cd6;](class color: #4ec9b0;](Choice {
color: #569cd6;](final color: #4ec9b0;](int id;
color: #569cd6;](final color: #4ec9b0;](String title;
color: #569cd6;](final color: #4ec9b0;](String date;
color: #569cd6;](final color: #4ec9b0;](String description;
color: #569cd6;](final color: #4ec9b0;](String imglink;
color: #569cd6;](const color: #4ec9b0;](Choice(
{color: #569cd6;](this.id, color: #569cd6;](this.title, color: #569cd6;](this.date, color: #569cd6;](this.description, color: #569cd6;](this.imglink});
}
color: #569cd6;](class color: #4ec9b0;](ChoiceCard color: #569cd6;](extends color: #4ec9b0;](StatelessWidget {
color: #569cd6;](const color: #4ec9b0;](ChoiceCard(
{color: #4ec9b0;](Key key,
color: #569cd6;](this.choice,
color: #569cd6;](this.onTap,
color: #569cd6;](@required color: #569cd6;](this.item,
color: #569cd6;](this.selected: color: #569cd6;](false})
: color: #569cd6;](super(key: key);
color: #569cd6;](final color: #4ec9b0;](Choice choice;
color: #569cd6;](final color: #4ec9b0;](VoidCallback onTap;
color: #569cd6;](final color: #4ec9b0;](Choice item;
color: #569cd6;](final color: #4ec9b0;](bool selected;
color: #569cd6;](@override
color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext context) {
color: #4ec9b0;](TextStyle textStyle = color: #4ec9b0;](Theme.color: #dcdcaa;](of(context).textTheme.display1;
color: #c586c0;](if (selected)
textStyle = textStyle.color: #dcdcaa;](copyWith(color: color: #4ec9b0;](Colors.lightGreenAccent[color: #b5cea8;](400]);
color: #c586c0;](return color: #4ec9b0;](FlatButton(
onPressed: () {
color: #4ec9b0;](Navigator.color: #dcdcaa;](push(
context,
color: #4ec9b0;](MaterialPageRoute(
builder: (context) =>
color: #4ec9b0;](ArticleReadPage(index: choices.color: #dcdcaa;](indexOf(choice))));
},
child: color: #4ec9b0;](Card(
color: color: #4ec9b0;](Colors.white,
child: color: #4ec9b0;](Column(
children: [
color: #c586c0;](new color: #4ec9b0;](Container(
padding: color: #569cd6;](const color: #4ec9b0;](EdgeInsets.color: #dcdcaa;](all(color: #b5cea8;](8.0),
child: color: #4ec9b0;](Image.color: #dcdcaa;](network(choice.imglink)),
color: #c586c0;](new color: #4ec9b0;](Container(
padding: color: #569cd6;](const color: #4ec9b0;](EdgeInsets.color: #dcdcaa;](all(color: #b5cea8;](10.0),
child: color: #4ec9b0;](Column(
mainAxisAlignment: color: #4ec9b0;](MainAxisAlignment.spaceEvenly,
crossAxisAlignment: color: #4ec9b0;](CrossAxisAlignment.start,
children: [
color: #4ec9b0;](Text(choice.title,
style: color: #4ec9b0;](Theme.color: #dcdcaa;](of(context).textTheme.title),
color: #4ec9b0;](Text(choice.date,
style: color: #4ec9b0;](TextStyle(color: color: #4ec9b0;](Colors.black.color: #dcdcaa;](withOpacity(color: #b5cea8;](0.5))),
color: #4ec9b0;](Text(choice.description.color: #dcdcaa;](substring(color: #b5cea8;](0, color: #b5cea8;](100) + color: #ce9178;]('...'),
],
),
)
],
crossAxisAlignment: color: #4ec9b0;](CrossAxisAlignment.start,
)),
);
}
}
color: #569cd6;](class color: #4ec9b0;](ArticleReadPage color: #569cd6;](extends color: #4ec9b0;](StatelessWidget {
color: #569cd6;](final color: #4ec9b0;](int index;
color: #569cd6;](const color: #4ec9b0;](ArticleReadPage({color: #4ec9b0;](Key key, color: #569cd6;](this.index}) : color: #569cd6;](super(key: key);
color: #569cd6;](@override
color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext context) {
color: #c586c0;](return color: #4ec9b0;](Center(
child: color: #4ec9b0;](ChoiceCardRead(choice: choices[index]),
);
}
}
color: #569cd6;](class color: #4ec9b0;](ChoiceCardRead color: #569cd6;](extends color: #4ec9b0;](StatelessWidget {
color: #569cd6;](const color: #4ec9b0;](ChoiceCardRead({color: #4ec9b0;](Key key, color: #569cd6;](this.choice}) : color: #569cd6;](super(key: key);
color: #569cd6;](final color: #4ec9b0;](Choice choice;
color: #569cd6;](@override
color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext context) {
color: #c586c0;](return color: #4ec9b0;](SingleChildScrollView(
child: color: #4ec9b0;](Container(
child: color: #4ec9b0;](Card(
color: color: #4ec9b0;](Colors.white,
child: color: #4ec9b0;](Column(
children: [
color: #c586c0;](new color: #4ec9b0;](Container(
padding: color: #569cd6;](const color: #4ec9b0;](EdgeInsets.color: #dcdcaa;](all(color: #b5cea8;](8.0),
child: color: #4ec9b0;](Image.color: #dcdcaa;](network(choice.imglink)),
color: #c586c0;](new color: #4ec9b0;](Container(
padding: color: #569cd6;](const color: #4ec9b0;](EdgeInsets.color: #dcdcaa;](all(color: #b5cea8;](10.0),
child: color: #4ec9b0;](Column(
mainAxisAlignment: color: #4ec9b0;](MainAxisAlignment.spaceEvenly,
crossAxisAlignment: color: #4ec9b0;](CrossAxisAlignment.start,
children: [
color: #4ec9b0;](Text(choice.title,
style: color: #4ec9b0;](Theme.color: #dcdcaa;](of(context).textTheme.title),
color: #4ec9b0;](Text(choice.date,
style:
color: #4ec9b0;](TextStyle(color: color: #4ec9b0;](Colors.black.color: #dcdcaa;](withOpacity(color: #b5cea8;](0.5))),
color: #4ec9b0;](Text(choice.description),
],
),
)
],
crossAxisAlignment: color: #4ec9b0;](CrossAxisAlignment.start,
)),
),
);
}
}
`
Hope this will be helpful to you.
Thanks,
Srikanth