ListView Example

 import "package:flutter/material.dart";


/// EXAMPLE 1

void main()
{
runApp(MyApp());
}
class MyApp extends StatelessWidget
{
MyApp({super.key});
@override
Widget build(BuildContext context)
{
return MaterialApp(
title: "Data Passing",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.deepPurple,
),
home: FirstClass(),
);
}
}

class Todo
{
final String title;
final String description;

Todo(this.title, this.description);
}

class FirstClass extends StatelessWidget
{
FirstClass({super.key});
@override
Widget build(BuildContext context)
{
return Scaffold(
appBar: AppBar(
title: const Text("First Page"),
centerTitle: true,
),
body: Center(
child: SecondClass(
todolist: List.generate(20, (index) {
return Todo("TODO : $index", "Detail is : $index");
}),
),
),
);
}
}

class SecondClass extends StatelessWidget
{
SecondClass({super.key, required this.todolist});

final List<Todo> todolist;

@override
Widget build(BuildContext context)
{
return Scaffold(
appBar: AppBar(
title: const Text("Second Page"),
centerTitle: true,
),
body: Center(
child: ListView.builder(
itemCount: todolist.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(todolist[index].title),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return ThirdClass(todo: todolist[index]);
},
),
);
},
);
},
),
),
);
}
}

class ThirdClass extends StatelessWidget
{
ThirdClass({super.key, required this.todo});

final Todo todo;

@override
Widget build(BuildContext context)
{
return Scaffold(
appBar: AppBar(
title: Text(todo.title),
centerTitle: true,
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(todo.title + " , " + todo.description),
),
),
);
}
}

Comments

Popular posts from this blog

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter