-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo03.dart
60 lines (51 loc) · 1.42 KB
/
demo03.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Create list with index
// parameters pass
import 'package:flutter/material.dart';
class Product{
final String title;
final String description;
Product(this.title,this.description);
}
void main(){
runApp(MaterialApp(
title: 'navigator data pass and get',
home: ProductList(
products:List.generate(20, (index) => Product('goods $index','this is a good detail, code $index'))
),
));
}
class ProductList extends StatelessWidget {
final List<Product> products;
ProductList({Key key,@required this.products}):super(key:key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('good list')),
body: ListView.builder(
itemCount: products.length,
itemBuilder: (context,index){
return ListTile(
title: Text(products[index].title),
onTap: (){
Navigator.push(context, MaterialPageRoute(
builder: (context)=>ProductDetail(product:products[index])
)
);
},
);
},
),
);
}
}
class ProductDetail extends StatelessWidget {
final Product product;
ProductDetail({Key key,@required this.product}):super(key:key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('${product.title}'),),
body: Center(child: Text('${product.description}'),),
);
}
}