Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ___________________________
- //main.dart
- ___________________________
- import 'package:flutter/material.dart';
- import 'quote.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) => Text('${quote.text} - ${quote.author}')).toList(),
- ),
- );
- }
- }
- ___________________________
- //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 maintain 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