Skip to content

Commit 34a56f4

Browse files
committed
lesson-18
1 parent de567af commit 34a56f4

File tree

3 files changed

+37
-35
lines changed

3 files changed

+37
-35
lines changed

quotes/lib/main.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'quote.dart';
23

34
void main() => runApp(MaterialApp(
45
home: QuoteList()
@@ -11,10 +12,16 @@ class QuoteList extends StatefulWidget {
1112

1213
class _QuoteListState extends State<QuoteList> {
1314

14-
List<String> quotes = [
15-
'Be yourself; everyone else is already taken',
16-
'I have nothing to declare except my genius',
17-
'The truth is rarely pure and never simple'
15+
// List<String> quotes = [
16+
// 'Be yourself; everyone else is already taken',
17+
// 'I have nothing to declare except my genius',
18+
// 'The truth is rarely pure and never simple'
19+
// ];
20+
21+
List<Quote> quotes = [
22+
Quote(author: 'Oscar Wilde', text: 'Be yourself; everyone else is already taken'),
23+
Quote(author: 'Oscar Wilde', text: 'I have nothing to declare except my genius'),
24+
Quote(author: 'Oscar Wilde', text: 'The truth is rarely pure and never simple')
1825
];
1926

2027
@override
@@ -27,7 +34,7 @@ class _QuoteListState extends State<QuoteList> {
2734
backgroundColor: Colors.redAccent,
2835
),
2936
body: Column(
30-
children: quotes.map((quote) => Text(quote)).toList(),
37+
children: quotes.map((quote) => Text('${quote.text} - ${quote.author}')).toList(),
3138
),
3239
);
3340
}

quotes/lib/quote.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Quote {
2+
3+
String text;
4+
String author;
5+
6+
// normal constructor, as we've already seen
7+
8+
// Quote(String author, String text){
9+
// this.text = text;
10+
// this.author = author;
11+
// }
12+
13+
// constructor with named parameters
14+
15+
// Quote({ String author, String text }){
16+
// this.text = text;
17+
// this.author = author;
18+
// }
19+
20+
// constructor with named parameters
21+
// & automatically assigns named arguments to class properties
22+
23+
Quote({ this.text, this.author });
24+
25+
}

quotes/test/widget_test.dart

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)