-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathcard_demo.dart
94 lines (91 loc) · 3.1 KB
/
card_demo.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import 'package:flutter/material.dart';
import 'package:pro_flutter/demo/model/post.dart';
import 'post_show.dart';
class CardDemo extends StatefulWidget {
@override
_CardDemoState createState() => _CardDemoState();
}
class _CardDemoState extends State<CardDemo> {
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(
left: 16.0,
right: 16.0,
),
child: ListView.builder(
padding: EdgeInsets.only(
top: 26.0,
),
itemCount: posts.length,
itemBuilder: (BuildContext context, int index) {
return Stack(
children: <Widget>[
Card(
elevation: 0.0,
margin: EdgeInsets.only(
bottom: 26.0,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
AspectRatio(
aspectRatio: 3 / 2,
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0),
),
child: Image.network(
posts[index].imageUrl,
fit: BoxFit.cover,
),
),
),
ListTile(
contentPadding: EdgeInsets.only(
top: 6.0,
bottom: 2.0,
left: 16.0,
),
leading: CircleAvatar(
backgroundImage: NetworkImage(posts[index].imageUrl),
),
title: Text(posts[index].title),
subtitle: Text(posts[index].author),
trailing: IconButton(
icon: Icon(
Icons.favorite,
color: posts[index].liked
? Colors.red[300]
: Colors.grey[300],
size: 20.0,
),
onPressed: () {
setState(() {
posts[index].liked
? posts[index].liked = false
: posts[index].liked = true;
});
},
),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => PostShow(
post: posts[index],
)));
},
),
],
),
),
],
);
},
),
);
}
}