Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ___________________________
- //main.dart
- ___________________________
- import 'package:flutter/material.dart';
- import 'quote.dart';
- import 'quote_card.dart';
- void main() => runApp(MaterialApp(
- home: QuoteList(),
- ));
- class QuoteList extends StatefulWidget {
- @override
- _QuoteListCardState createState() => _QuoteListCardState();
- }
- class _QuoteListCardState extends State<QuoteList> {
- List<Quote> quotes = [
- Quote(author: 'Pai', text: 'Hello world'),
- Quote(author: 'Raj', text: 'Hello there'),
- Quote(author: 'Jordan', text: 'It became personal with me')
- ];
- Widget build(BuildContext context) {
- return Scaffold(
- backgroundColor: Colors.grey[200],
- appBar: AppBar(
- title: Text('Quote'),
- centerTitle: true,
- backgroundColor: Colors.redAccent,
- ),
- body : Column(
- children : quotes.map((quote) => QuoteCard(quote : quote)).toList(),
- ),
- );
- }
- }
- ___________________________
- //quote_card.dart
- ___________________________
- import 'package:flutter/material.dart';
- import 'quote.dart';
- class QuoteCard extends StatelessWidget {
- final Quote quote;
- QuoteCard({ required this.quote });
- @override
- Widget build(BuildContext context) {
- return Card(
- margin : const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0.0),
- child : Padding(
- padding: const EdgeInsets.all(12.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: <Widget>[
- Text(
- quote.text,
- style: TextStyle(
- fontSize: 18.0,
- color : Colors.grey[600],
- ),
- ),
- SizedBox(height: 6.0),
- Text(
- quote.author,
- style : TextStyle(
- fontSize : 14.0,
- color : Colors.grey[800],
- )
- ),
- ],
- ),
- ),
- );
- }
- }
- ___________________________
- //quote.dart
- ___________________________
- class Quote{
- String text;
- String author;
- Quote( { required this.text, required this.author });
- }
- //This is one way to do it
- // Quote(String text, String author){
- // this.text = text;
- // this.author = author;
- // }
- //The instance for this class would look like
- // so here you'll have to maintian the same order that is
- // have the quote first and then the author
- //The second way to do it is by parameterising it
- // Quote( { String text, String author } ){ .... }
- // when does this help? => When creating an instance of the class
- // the order in which you input the values wont matter
- // Quote myquote = Quote(text : 'Dont get mad, get even', author : 'Jesus')
- // This can also be jumbled and written as
- // Quote myquote = Quote(author : 'Jesus' , text : 'Dont get mad, get even')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement