BladeMechanics

DefaultsSample

Nov 1st, 2020 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.44 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(MyApp());
  5. }
  6.  
  7. class MyApp extends StatelessWidget {
  8.   // This widget is the root of your application.
  9.   @override
  10.   Widget build(BuildContext context) {
  11.     return MaterialApp(
  12.       debugShowCheckedModeBanner: false,
  13.       title: 'Flutter Demo',
  14.       theme: ThemeData(
  15.         primarySwatch: Colors.blue,
  16.       ),
  17.       home: NoStateHomePage('Zodiac Thingy', secondTitle: "basta naa ni"),
  18.     );
  19.   }
  20. }
  21.  
  22. class NoStateHomePage extends StatelessWidget {
  23.   final String title;
  24.   final String secondTitle;
  25.   NoStateHomePage(this.title, {this.secondTitle});
  26.   // NoStateHomePage(this.title, this.secondTitle);
  27.   Widget build(BuildContext context) {
  28.     return Scaffold(
  29.         appBar: AppBar(
  30.           title: Text(title + " " + secondTitle),
  31.         ),
  32.         body: ContentZodiac());
  33.   }
  34. }
  35.  
  36. class ContentZodiac extends StatefulWidget {
  37.   @override
  38.   _ContentZodiacState createState() => _ContentZodiacState();
  39. }
  40.  
  41. class _ContentZodiacState extends State<ContentZodiac> {
  42.   int _value = 0;
  43.  
  44.   List<Map<String, dynamic>> information = [
  45.     {},
  46.     {
  47.       "name": "Aries",
  48.       "dates": "19 April – 13 May",
  49.       "stay": "25 days",
  50.       "brightest_star": "Hamal",
  51.       "image":
  52.           "https://cdn.discordapp.com/attachments/753905152796131328/770286814517919774/scorpio.jpg"
  53.     },
  54.     {
  55.       "name": "Taurus",
  56.       "dates": "14 May – 19 June",
  57.       "stay": "37 days",
  58.       "brightest_star": "Aldebaran",
  59.       "image":
  60.           "https://media.discordapp.net/attachments/753905152796131328/770286818314027048/taurus.jpg?width=789&height=789"
  61.     },
  62.     {
  63.       "name": "Gemini",
  64.       "dates": "20 June – 20 July",
  65.       "stay": "31 days",
  66.       "brightest_star": "Pollux",
  67.       "image": "https://via.placeholder.com/400"
  68.     },
  69.     {
  70.       "name": "Cancer",
  71.       "dates": "21 July – 9 August",
  72.       "stay": "20 days",
  73.       "brightest_star": "Al Tarf",
  74.       "image": "https://via.placeholder.com/400"
  75.     },
  76.     {
  77.       "name": "Leo",
  78.       "dates": "10 August – 15 September",
  79.       "stay": "37 days",
  80.       "brightest_star": "Regulus",
  81.       "image": "https://via.placeholder.com/400"
  82.     },
  83.     {
  84.       "name": "Virgo",
  85.       "dates": "16 September – 30 October",
  86.       "stay": "45 days",
  87.       "brightest_star": "Spica",
  88.       "image": "https://via.placeholder.com/400"
  89.     },
  90.     {
  91.       "name": "Libra",
  92.       "dates": "31 October – 22 November",
  93.       "stay": "23 days",
  94.       "brightest_star": "Zubeneschamali",
  95.       "image": "https://via.placeholder.com/400"
  96.     },
  97.     {
  98.       "name": "Scorpius",
  99.       "dates": "23 November – 29 November",
  100.       "stay": "7 days",
  101.       "brightest_star": "Antares",
  102.       "image":
  103.           "https://cdn.discordapp.com/attachments/753905152796131328/770286814517919774/scorpio.jpg"
  104.     },
  105.     {
  106.       "name": "Ophiuchus",
  107.       "dates": "30 November – 17 December",
  108.       "stay": "18 days",
  109.       "brightest_star": "Rasalhague",
  110.       "image": "https://via.placeholder.com/400"
  111.     },
  112.     {
  113.       "name": "Sagittarius",
  114.       "dates": "18 December – 18 January",
  115.       "stay": "32 days",
  116.       "brightest_star": "Kaus Australis",
  117.       "image": "https://via.placeholder.com/400"
  118.     },
  119.     {
  120.       "name": "Capricornus",
  121.       "dates": "19 January – 15 February",
  122.       "stay": "28 days",
  123.       "brightest_star": "Deneb Algedi",
  124.       "image": "https://via.placeholder.com/400"
  125.     },
  126.     {
  127.       "name": "Aquarius",
  128.       "dates": "16 February – 11 March",
  129.       "stay": "24 days",
  130.       "brightest_star": "Sadalsuud",
  131.       "image":
  132.           "https://cdn.discordapp.com/attachments/753905152796131328/770286395473264660/aquarius.jpg"
  133.     },
  134.     {
  135.       "name": "Pisces",
  136.       "dates": "12 March – 18 April",
  137.       "stay": "38 days",
  138.       "brightest_star": "Eta Piscium",
  139.       "image": "https://via.placeholder.com/400"
  140.     }
  141.   ];
  142.  
  143.   @override
  144.   Widget build(BuildContext context) {
  145.     return Container(
  146.       padding: EdgeInsets.all(25),
  147.       child: Column(
  148.         children: [
  149.           DropdownButton(
  150.               value: _value,
  151.               items: generateOptions(),
  152.               onChanged: (value) {
  153.                 print(value);
  154.                 setState(() {
  155.                   _value = value;
  156.                 });
  157.               }),
  158.           _value == 0
  159.               ? Container()
  160.               : Column(
  161.                   children: [
  162.                     Image.network(information[_value]["image"]),
  163.                     Text("Name of zodiac: ${information[_value]["name"]}",
  164.                         style: TextStyle(fontSize: 24)),
  165.                     Text("Dates represented: " + information[_value]["dates"]),
  166.                     Text(
  167.                         "How long it is visible: ${information[_value]["stay"]}"),
  168.                     Text(
  169.                         "The brightest star: ${information[_value]["brightest_star"]}"),
  170.                   ],
  171.                 ),
  172.         ],
  173.       ),
  174.     );
  175.   }
  176.  
  177.   List<DropdownMenuItem<int>> generateOptions() {
  178.     List<DropdownMenuItem<int>> result = [
  179.       DropdownMenuItem(
  180.         child: Text("Select an item"),
  181.         value: 0,
  182.       ),
  183.     ];
  184.  
  185.     for (int i = 1; i < information.length; i++) {
  186.       result.add(
  187.         DropdownMenuItem(
  188.           child: Text(information[i]["name"]),
  189.           value: i,
  190.         ),
  191.       );
  192.     }
  193.     return result;
  194.   }
  195. }
  196.  
Add Comment
Please, Sign In to add comment