import 'package:flutter/material.dart';
class Person {
final String? name;
final int? height;
Person({this.name, this.height});
}
void main() {
runApp(
MyApp(items: [
Person(name: 'Ali', height: 33),
Person(name: 'Faisal', height: 54),
Person(name: 'Javed', height: 50),
]),
);
}
class MyApp extends StatelessWidget {
final List<Person> items;
MyApp({super.key, required this.items});
@override
Widget build(BuildContext context) {
const title = 'Long List';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: const Text(title),
),
body: ListView.builder(
itemCount: items.length,
prototypeItem: ListTile(
title: Text("${items.first.name}"),
),
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => DetailScreen(
name: items[index].name!,
height: items[index].height!)));
},
);
},
),
),
);
}
}
class DetailScreen extends StatelessWidget {
final String name;
final int height;
const DetailScreen({super.key, required this.name, required this.height});
@override
Widget build(BuildContext context) {
return Text("${name} ${height}");
}
}