Advertisement
mactech24

Prince rewritten code

Apr 28th, 2023
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.33 KB | None | 0 0
  1. // ignore_for_file: public_member_api_docs, sort_constructors_first
  2. import 'package:flutter/material.dart';
  3.  
  4. void main() {
  5.   runApp(const MyApp());
  6. }
  7.  
  8. class MyApp extends StatelessWidget {
  9.   const MyApp({super.key});
  10.  
  11.   @override
  12.   Widget build(BuildContext context) {
  13.     return MaterialApp(
  14.       debugShowCheckedModeBanner: false,
  15.       theme: ThemeData(
  16.         primarySwatch: Colors.purple,
  17.       ),
  18.       home: Home(),
  19.     );
  20.   }
  21. }
  22.  
  23. // This is a home Page, you don't need to congest it with many codes
  24. class Home extends StatelessWidget {
  25.   Home({super.key});
  26.   var title = "Nice Quotes";
  27.   @override
  28.   Widget build(BuildContext context) {
  29.     return Scaffold(
  30.       backgroundColor: Colors.grey[200],
  31.       appBar: AppBar(
  32.         centerTitle: true,
  33.         title: Text(title),
  34.       ),
  35.       body: Column(
  36.         children: [
  37.           Expanded(
  38.             child: MyCard(),
  39.           ),
  40.         ],
  41.       ),
  42.     );
  43.   }
  44. }
  45.  
  46. // This is a Quote class that could be placed in its own separate dart file
  47.  
  48. class Quotes {
  49.   String title;
  50.   String subTitle;
  51.   Quotes({
  52.     required this.title,
  53.     required this.subTitle,
  54.   });
  55. // The reason for writing it this way is for maintainabily , in case you want to add more quotes to the list in future
  56.   static List<Quotes> quotesList = [
  57.     Quotes(
  58.       title: "He looks Handsome",
  59.       subTitle: "James",
  60.     ),
  61.     Quotes(
  62.       title: "She looks Sick",
  63.       subTitle: "Joan",
  64.     ),
  65.     Quotes(
  66.       title: "What a nice family",
  67.       subTitle: "Kame",
  68.     ),
  69.  
  70. // you can uncommnent these three remaining qoutes to make the list to be up to six in number
  71.     //  Quotes(
  72.     //   title: "He looks Hungry",
  73.     //   subTitle: "John",
  74.     // ),
  75.     // Quotes(
  76.     //   title: "She looks Sad",
  77.     //   subTitle: "Mercy",
  78.     // ),
  79.     // Quotes(
  80.     //   title: "What a wicked family",
  81.     //   subTitle: "Tom",
  82.     // ),
  83.   ];
  84. }
  85.  
  86. // This myCard widget can be placed in a widget folder
  87.  
  88. class MyCard extends StatelessWidget {
  89.   const MyCard() : super();
  90.  
  91.   @override
  92.   Widget build(BuildContext context) {
  93.     return Padding(
  94.         padding: const EdgeInsets.symmetric(
  95.           horizontal: 10.0,
  96.           vertical: 10,
  97.         ),
  98.         child: ListView.builder(
  99.             itemCount: Quotes.quotesList.length,
  100.             itemBuilder: (context, index) {
  101.               return Card(
  102.                 elevation: 0,
  103.                 child: Container(
  104.                   padding: const EdgeInsets.symmetric(
  105.                     horizontal: 20.0,
  106.                     vertical: 20,
  107.                   ),
  108.                   height: 90,
  109.                   width: double.infinity,
  110.                   child: Column(
  111.                     crossAxisAlignment: CrossAxisAlignment.start,
  112.                     children: [
  113.                       Text(
  114.                         Quotes.quotesList[index].title,
  115.                         style: TextStyle(fontSize: 20),
  116.                       ),
  117.                       SizedBox(
  118.                         height: 5,
  119.                       ),
  120.                       Text(
  121.                         Quotes.quotesList[index].subTitle,
  122.                         style: TextStyle(fontSize: 18),
  123.                       ),
  124.                     ],
  125.                   ),
  126.                 ),
  127.               );
  128.             }));
  129.   }
  130. }
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement