flutter-QuoteCard
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home:quote(),
));
}
class quote extends StatefulWidget {
@override
_quoteState createState() => _quoteState();
}
class _quoteState extends State<quote> {
List<Quote> quotes = [
Quote(text: 'Be yourself; everyone else is already taken.', author: ' Oscar Wilde'),
Quote(text: 'So many books, so little time.',author: 'Frank Zappa'),
Quote(text: 'A room without books is like a body without a soul.',author: 'Marcus Tullius Cicero'),
];
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[100],
appBar: AppBar(
title: Text(
'Awesome Quote Card',
style: TextStyle(
color: Colors.grey[100],
fontSize: 20,
),
),
centerTitle: true,
backgroundColor: Colors.blue[400],
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: quotes.map((v) => QuoteCard(
q: v, //(paramNamed: valueOftheList[])
delete: (){
setState(() {
quotes.remove(v);
});
},
)).toList(),
),
);
}
}
class Quote {
String text,author;
Quote({this.text, this.author});
}
class QuoteCard extends StatelessWidget {
final Quote q;
final Function delete;
QuoteCard({this.q, this.delete});
@override
Widget build(BuildContext context) {
return Card(
margin: EdgeInsets.fromLTRB(16, 16, 16, 0),
child: Padding(
padding: EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
q.text,
style: TextStyle(
fontSize: 18,
) ,
),
SizedBox(height: 6,),
Text(
q.author,
),
SizedBox(height: 5,),
FlatButton.icon(
onPressed: delete,
icon: Icon(Icons.delete),
label: Text('Delete'))
],
),
),
);
}
}
body: Column(
children: quotes.map((q)=> QuoteCard(q: q)).toList(), //function(paramName: value)
),
);
}
}
class QuoteCard extends StatelessWidget {
final Quote q;
QuoteCard({this.q});
@override
Widget build(BuildContext context) {
return Card(
margin: EdgeInsets.fromLTRB(16, 16, 16, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
q.text,
style: TextStyle(
fontSize: 18.0,
color: Colors.grey[800],
),
),
SizedBox(height: 5,),
Text(
q.author,
style: TextStyle(
fontSize: 15.0,
color: Colors.grey[800],
),
),
],
),
);
}
}
Comments
Post a Comment