Skip to content

Commit 3207f27

Browse files
committed
lesson-20
1 parent c4035fc commit 3207f27

File tree

2 files changed

+42
-30
lines changed

2 files changed

+42
-30
lines changed

quotes/lib/main.dart

+4-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'quote.dart';
3+
import 'quote_card.dart';
34

45
void main() => runApp(MaterialApp(
56
home: QuoteList()
@@ -18,35 +19,6 @@ class _QuoteListState extends State<QuoteList> {
1819
Quote(author: 'Oscar Wilde', text: 'The truth is rarely pure and never simple')
1920
];
2021

21-
Widget quoteTemplate(quote) {
22-
return Card(
23-
margin: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0),
24-
child: Padding(
25-
padding: const EdgeInsets.all(12.0),
26-
child: Column(
27-
crossAxisAlignment: CrossAxisAlignment.stretch,
28-
children: <Widget>[
29-
Text(
30-
quote.text,
31-
style: TextStyle(
32-
fontSize: 18.0,
33-
color: Colors.grey[600],
34-
),
35-
),
36-
SizedBox(height: 6.0),
37-
Text(
38-
quote.author,
39-
style: TextStyle(
40-
fontSize: 14.0,
41-
color: Colors.grey[800],
42-
),
43-
),
44-
],
45-
),
46-
)
47-
);
48-
}
49-
5022
@override
5123
Widget build(BuildContext context) {
5224
return Scaffold(
@@ -57,11 +29,13 @@ class _QuoteListState extends State<QuoteList> {
5729
backgroundColor: Colors.redAccent,
5830
),
5931
body: Column(
60-
children: quotes.map((quote) => quoteTemplate(quote)).toList(),
32+
children: quotes.map((quote) => QuoteCard(quote: quote)).toList(),
6133
),
6234
);
6335
}
6436
}
6537

6638

6739

40+
41+

quotes/lib/quote_card.dart

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'package:flutter/material.dart';
2+
import 'quote.dart';
3+
4+
class QuoteCard extends StatelessWidget {
5+
6+
final Quote quote;
7+
QuoteCard({ this.quote });
8+
9+
@override
10+
Widget build(BuildContext context) {
11+
return Card(
12+
margin: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0),
13+
child: Padding(
14+
padding: const EdgeInsets.all(12.0),
15+
child: Column(
16+
crossAxisAlignment: CrossAxisAlignment.stretch,
17+
children: <Widget>[
18+
Text(
19+
quote.text,
20+
style: TextStyle(
21+
fontSize: 18.0,
22+
color: Colors.grey[600],
23+
),
24+
),
25+
SizedBox(height: 6.0),
26+
Text(
27+
quote.author,
28+
style: TextStyle(
29+
fontSize: 14.0,
30+
color: Colors.grey[800],
31+
),
32+
),
33+
],
34+
),
35+
)
36+
);
37+
}
38+
}

0 commit comments

Comments
 (0)