Skip to content

Commit b0541b6

Browse files
committed
Learnt on funcitons and passing them in
1 parent 1aa7c73 commit b0541b6

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

lib/main.dart

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import 'package:flutter/material.dart';
2+
import 'package:ninja_app/quote.dart';
3+
4+
import 'quote_card.dart';
25

36
void main() {
47
runApp(MaterialApp(
@@ -12,11 +15,16 @@ class QuoteList extends StatefulWidget {
1215
}
1316

1417
class _QuoteListState extends State<QuoteList> {
15-
List<String> quotes = [
16-
'To be or not to be, that is the question',
17-
'There is no one better that you at being you, don\'t mess it up',
18-
'Dogs also think, don\' discredit yourself so quickly'
18+
List<Quote> quotes = [
19+
Quote(text: 'To be or not to be, that is the question', author: 'Hamlet'),
20+
Quote(
21+
text: 'There is no one better that you at being you, don\'t mess it up',
22+
author: 'Humphrey'),
23+
Quote(
24+
text: 'Dogs also think, don\' discredit yourself so quickly',
25+
author: 'Dirty Bag')
1926
];
27+
2028
@override
2129
Widget build(BuildContext context) {
2230
return Scaffold(
@@ -28,7 +36,13 @@ class _QuoteListState extends State<QuoteList> {
2836
),
2937
body: Column(
3038
children: quotes.map((quote) {
31-
return Text(quote);
39+
return QuoteCard(
40+
quote: quote,
41+
delete: () {
42+
setState(() {
43+
quotes.remove(quote);
44+
});
45+
});
3246
}).toList(),
3347
));
3448
}

lib/quote.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Quote {
2+
String author, text;
3+
4+
// Quote(String auth, String tex) {
5+
// this.author = auth;
6+
// this.text = tex;
7+
// }
8+
9+
Quote({this.author, this.text});
10+
}

lib/quote_card.dart

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

0 commit comments

Comments
 (0)