Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ignore_for_file: public_member_api_docs, sort_constructors_first
- import 'package:flutter/material.dart';
- void main() {
- runApp(const MyApp());
- }
- class MyApp extends StatelessWidget {
- const MyApp({super.key});
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- debugShowCheckedModeBanner: false,
- theme: ThemeData(
- primarySwatch: Colors.purple,
- ),
- home: Home(),
- );
- }
- }
- // This is a home Page, you don't need to congest it with many codes
- class Home extends StatelessWidget {
- Home({super.key});
- var title = "Nice Quotes";
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- backgroundColor: Colors.grey[200],
- appBar: AppBar(
- centerTitle: true,
- title: Text(title),
- ),
- body: Column(
- children: [
- Expanded(
- child: MyCard(),
- ),
- ],
- ),
- );
- }
- }
- // This is a Quote class that could be placed in its own separate dart file
- class Quotes {
- String title;
- String subTitle;
- Quotes({
- required this.title,
- required this.subTitle,
- });
- // The reason for writing it this way is for maintainabily , in case you want to add more quotes to the list in future
- static List<Quotes> quotesList = [
- Quotes(
- title: "He looks Handsome",
- subTitle: "James",
- ),
- Quotes(
- title: "She looks Sick",
- subTitle: "Joan",
- ),
- Quotes(
- title: "What a nice family",
- subTitle: "Kame",
- ),
- // you can uncommnent these three remaining qoutes to make the list to be up to six in number
- // Quotes(
- // title: "He looks Hungry",
- // subTitle: "John",
- // ),
- // Quotes(
- // title: "She looks Sad",
- // subTitle: "Mercy",
- // ),
- // Quotes(
- // title: "What a wicked family",
- // subTitle: "Tom",
- // ),
- ];
- }
- // This myCard widget can be placed in a widget folder
- class MyCard extends StatelessWidget {
- const MyCard() : super();
- @override
- Widget build(BuildContext context) {
- return Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 10.0,
- vertical: 10,
- ),
- child: ListView.builder(
- itemCount: Quotes.quotesList.length,
- itemBuilder: (context, index) {
- return Card(
- elevation: 0,
- child: Container(
- padding: const EdgeInsets.symmetric(
- horizontal: 20.0,
- vertical: 20,
- ),
- height: 90,
- width: double.infinity,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- Quotes.quotesList[index].title,
- style: TextStyle(fontSize: 20),
- ),
- SizedBox(
- height: 5,
- ),
- Text(
- Quotes.quotesList[index].subTitle,
- style: TextStyle(fontSize: 18),
- ),
- ],
- ),
- ),
- );
- }));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement