Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 13.09 KB | None | 0 0
  1. import 'package:flight/CustomShapeClipper.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:intl/intl.dart';
  4.  
  5. void main() => runApp(
  6.       MaterialApp(
  7.         title: 'Flight List Mock Up',
  8.         debugShowCheckedModeBanner: false,
  9.         home: HomeScreen(),
  10.         theme: appTheme,
  11.       ),
  12.     );
  13.  
  14. Color firstColor = Color(0xFFF47D15);
  15. Color secondColor = Color(0xFFEF772C);
  16.  
  17. List<String> locations = ['Boston (BOS)', 'New York (JFK)', ''];
  18.  
  19. const TextStyle dropDownLabelStyle =
  20.     TextStyle(color: Colors.white, fontSize: 16.0);
  21.  
  22. const TextStyle dropDownMenuItemStyle =
  23.     TextStyle(color: Colors.black, fontSize: 16.0);
  24.  
  25. ThemeData appTheme =
  26.     ThemeData(primaryColor: Color(0xFFF3791A), fontFamily: 'Oxygen');
  27.  
  28. class HomeScreen extends StatelessWidget {
  29.   @override
  30.   Widget build(BuildContext context) {
  31.     return Scaffold(
  32.       body: Column(
  33.         children: <Widget>[
  34.           HomeScreenTopPart(),
  35.           homeScreenBottomPart,
  36.         ],
  37.       ),
  38.     );
  39.   }
  40. }
  41.  
  42. class HomeScreenTopPart extends StatefulWidget {
  43.   @override
  44.   _HomeScreenTopPartState createState() => _HomeScreenTopPartState();
  45. }
  46.  
  47. class _HomeScreenTopPartState extends State<HomeScreenTopPart> {
  48.   var selectedLocationIndex = 0;
  49.  
  50.   var isFlightSelected = true;
  51.  
  52.   @override
  53.   Widget build(BuildContext context) {
  54.     return Stack(
  55.       children: <Widget>[
  56.         ClipPath(
  57.           clipper: CustomShapeClipper(),
  58.           child: Container(
  59.             height: 400.0,
  60.             decoration: BoxDecoration(
  61.               gradient: LinearGradient(colors: [firstColor, secondColor]),
  62.             ),
  63.             child: Column(
  64.               children: <Widget>[
  65.                 SizedBox(height: 50.0),
  66.                 Padding(
  67.                   padding: const EdgeInsets.all(16.0),
  68.                   child: Row(
  69.                     children: <Widget>[
  70.                       Icon(
  71.                         Icons.location_on,
  72.                         color: Colors.white,
  73.                       ),
  74.                       SizedBox(width: 16.0),
  75.                       PopupMenuButton(
  76.                         onSelected: (index) {
  77.                           setState(() {
  78.                             selectedLocationIndex = index;
  79.                           });
  80.                         },
  81.                         child: Row(
  82.                           children: <Widget>[
  83.                             Text(
  84.                               locations[selectedLocationIndex],
  85.                               style: dropDownLabelStyle,
  86.                             ),
  87.                             Icon(Icons.keyboard_arrow_down, color: Colors.white)
  88.                           ],
  89.                         ),
  90.                         itemBuilder: (BuildContext context) =>
  91.                             <PopupMenuItem<int>>[
  92.                               PopupMenuItem(
  93.                                 child: Text(
  94.                                   locations[0],
  95.                                   style: dropDownMenuItemStyle,
  96.                                 ),
  97.                                 value: 0,
  98.                               ),
  99.                               PopupMenuItem(
  100.                                 child: Text(
  101.                                   locations[1],
  102.                                   style: dropDownMenuItemStyle,
  103.                                 ),
  104.                                 value: 1,
  105.                               )
  106.                             ],
  107.                       ),
  108.                       Spacer(),
  109.                       Icon(
  110.                         Icons.settings,
  111.                         color: Colors.white,
  112.                       )
  113.                     ],
  114.                   ),
  115.                 ),
  116.                 SizedBox(height: 35.0),
  117.                 Text(
  118.                   'Where would\nyou want to go?',
  119.                   style: TextStyle(
  120.                     fontSize: 24.0,
  121.                     color: Colors.white,
  122.                   ),
  123.                   textAlign: TextAlign.center,
  124.                 ),
  125.                 SizedBox(height: 30.0),
  126.                 Padding(
  127.                   padding: EdgeInsets.symmetric(horizontal: 32.0),
  128.                   child: Material(
  129.                     elevation: 5.0,
  130.                     borderRadius: BorderRadius.all(Radius.circular(30.0)),
  131.                     child: TextField(
  132.                       controller: TextEditingController(text: locations[1]),
  133.                       style: dropDownMenuItemStyle,
  134.                       cursorColor: appTheme.primaryColor,
  135.                       decoration: InputDecoration(
  136.                         contentPadding: EdgeInsets.symmetric(
  137.                           horizontal: 32.0,
  138.                           vertical: 14.0,
  139.                         ),
  140.                         suffixIcon: Material(
  141.                           elevation: 2.0,
  142.                           borderRadius: BorderRadius.all(Radius.circular(30.0)),
  143.                           child: Icon(
  144.                             Icons.search,
  145.                             color: Colors.black,
  146.                           ),
  147.                         ),
  148.                         border: InputBorder.none,
  149.                       ),
  150.                     ),
  151.                   ),
  152.                 ),
  153.                 SizedBox(height: 20.0),
  154.                 Row(
  155.                   mainAxisSize: MainAxisSize.min,
  156.                   mainAxisAlignment: MainAxisAlignment.spaceAround,
  157.                   children: <Widget>[
  158.                     InkWell(
  159.                       child: ChoiceChip(
  160.                         Icons.flight_takeoff,
  161.                         "Flights",
  162.                         isFlightSelected,
  163.                       ),
  164.                       onTap: () {
  165.                         setState(() {
  166.                           isFlightSelected = true;
  167.                         });
  168.                       },
  169.                     ),
  170.                     SizedBox(width: 20.0),
  171.                     InkWell(
  172.                       child: ChoiceChip(
  173.                         Icons.hotel,
  174.                         'Hotels',
  175.                         !isFlightSelected,
  176.                       ),
  177.                       onTap: () {
  178.                         setState(() {
  179.                           isFlightSelected = false;
  180.                         });
  181.                       },
  182.                     ),
  183.                   ],
  184.                 )
  185.               ],
  186.             ),
  187.           ),
  188.         )
  189.       ],
  190.     );
  191.   }
  192. }
  193.  
  194. class ChoiceChip extends StatefulWidget {
  195.   final IconData icon;
  196.   final String text;
  197.   final bool isSelected;
  198.  
  199.   ChoiceChip(this.icon, this.text, this.isSelected);
  200.  
  201.   @override
  202.   _ChoiceChipState createState() => _ChoiceChipState();
  203. }
  204.  
  205. class _ChoiceChipState extends State<ChoiceChip> {
  206.   @override
  207.   Widget build(BuildContext context) {
  208.     return Container(
  209.       padding: EdgeInsets.symmetric(horizontal: 18.0, vertical: 8.0),
  210.       decoration: widget.isSelected
  211.           ? BoxDecoration(
  212.               color: Colors.white.withOpacity(0.15),
  213.               borderRadius: BorderRadius.circular(20.0),
  214.             )
  215.           : null,
  216.       child: Row(
  217.         children: <Widget>[
  218.           Icon(
  219.             widget.icon,
  220.             color: Colors.white,
  221.           ),
  222.           SizedBox(width: 8.0),
  223.           Text(
  224.             widget.text,
  225.             style: TextStyle(
  226.               color: Colors.white,
  227.               fontSize: 16.0,
  228.             ),
  229.           ),
  230.         ],
  231.       ),
  232.     );
  233.   }
  234. }
  235.  
  236. var viewAllStyle = TextStyle(
  237.   fontSize: 14.0,
  238.   color: appTheme.primaryColor,
  239. );
  240.  
  241. var homeScreenBottomPart = Column(
  242.   children: <Widget>[
  243.     Padding(
  244.       padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
  245.       child: Row(
  246.         mainAxisSize: MainAxisSize.max,
  247.         mainAxisAlignment: MainAxisAlignment.spaceBetween,
  248.         children: <Widget>[
  249.           Text(
  250.             'Currently Watched Items',
  251.             style: dropDownMenuItemStyle,
  252.           ),
  253.           Spacer(),
  254.           Text(
  255.             'VIEW ALL(12)',
  256.             style: viewAllStyle,
  257.           )
  258.         ],
  259.       ),
  260.     ),
  261.     Container(
  262.       height: 210.0,
  263.       child: ListView(
  264.         scrollDirection: Axis.horizontal,
  265.         children: cityCards,
  266.       ),
  267.     )
  268.   ],
  269. );
  270.  
  271. List<CityCard> cityCards = [
  272.   CityCard(
  273.     'assets/images/lasvegas.jpg',
  274.     'Las Vegas',
  275.     'Feb 2019',
  276.     '45',
  277.     4229,
  278.     2250,
  279.   ),
  280.   CityCard(
  281.     'assets/images/athens.jpg',
  282.     'Athens',
  283.     'Apr 2019',
  284.     '50',
  285.     9999,
  286.     4159,
  287.   ),
  288.   CityCard(
  289.     'assets/images/sydney.jpeg',
  290.     'Sydney',
  291.     'Dec 2019',
  292.     '40',
  293.     5999,
  294.     2399,
  295.   ),
  296. ];
  297.  
  298. final formatCurrency = new NumberFormat.simpleCurrency();
  299.  
  300. class CityCard extends StatelessWidget {
  301.   final String imagePath, cityName, monthYear, discount;
  302.   final int oldPrice, newPrice;
  303.  
  304.   const CityCard(
  305.     this.imagePath,
  306.     this.cityName,
  307.     this.monthYear,
  308.     this.discount,
  309.     this.oldPrice,
  310.     this.newPrice,
  311.   );
  312.  
  313.   @override
  314.   Widget build(BuildContext context) {
  315.     return Padding(
  316.       padding: const EdgeInsets.symmetric(horizontal: 8.0),
  317.       child: Column(
  318.         children: <Widget>[
  319.           ClipRRect(
  320.             borderRadius: BorderRadius.all(
  321.               Radius.circular(10.0),
  322.             ),
  323.             child: Stack(
  324.               children: <Widget>[
  325.                 Container(
  326.                   height: 210.0,
  327.                   width: 160.0,
  328.                   child: Image.asset(
  329.                     imagePath,
  330.                     fit: BoxFit.cover,
  331.                   ),
  332.                 ),
  333.                 Positioned(
  334.                   left: 0.0,
  335.                   bottom: 0.0,
  336.                   width: 160.0,
  337.                   height: 60.0,
  338.                   child: Container(
  339.                     decoration: BoxDecoration(
  340.                       gradient: LinearGradient(
  341.                         begin: Alignment.bottomCenter,
  342.                         end: Alignment.topCenter,
  343.                         colors: [
  344.                           Colors.black,
  345.                           Colors.black12,
  346.                         ],
  347.                       ),
  348.                     ),
  349.                   ),
  350.                 ),
  351.                 Positioned(
  352.                   left: 10.0,
  353.                   bottom: 10.0,
  354.                   right: 10.0,
  355.                   child: Row(
  356.                     mainAxisSize: MainAxisSize.max,
  357.                     mainAxisAlignment: MainAxisAlignment.spaceBetween,
  358.                     children: <Widget>[
  359.                       Column(
  360.                         crossAxisAlignment: CrossAxisAlignment.start,
  361.                         children: <Widget>[
  362.                           Text(
  363.                             cityName,
  364.                             style: TextStyle(
  365.                               fontWeight: FontWeight.bold,
  366.                               color: Colors.white,
  367.                               fontSize: 18.0,
  368.                             ),
  369.                           ),
  370.                           Text(
  371.                             monthYear,
  372.                             style: TextStyle(
  373.                               fontWeight: FontWeight.normal,
  374.                               color: Colors.white,
  375.                               fontSize: 14.0,
  376.                             ),
  377.                           )
  378.                         ],
  379.                       ),
  380.                       Container(
  381.                         padding: EdgeInsets.symmetric(
  382.                             horizontal: 6.0, vertical: 2.0),
  383.                         decoration: BoxDecoration(
  384.                           color: Colors.white,
  385.                           shape: BoxShape.rectangle,
  386.                           borderRadius: BorderRadius.all(
  387.                             Radius.circular(10.0),
  388.                           ),
  389.                         ),
  390.                         child: Text(
  391.                           '$discount%',
  392.                           style: TextStyle(
  393.                             fontSize: 14.0,
  394.                             color: Colors.black,
  395.                           ),
  396.                         ),
  397.                       ),
  398.                     ],
  399.                   ),
  400.                 ),
  401.               ],
  402.             ),
  403.           ),
  404.           Row(
  405.             mainAxisSize: MainAxisSize.max,
  406.             mainAxisAlignment: MainAxisAlignment.start,
  407.             children: <Widget>[
  408.               SizedBox(width: 5.0),
  409.               Text(
  410.                 '${formatCurrency.format(newPrice)}',
  411.                 style: TextStyle(
  412.                   color: Colors.black,
  413.                   fontWeight: FontWeight.bold,
  414.                   fontSize: 14.0,
  415.                 ),
  416.               ),
  417.               SizedBox(width: 5.0),
  418.               Text(
  419.                 '${formatCurrency.format(oldPrice)}',
  420.                 style: TextStyle(
  421.                   color: Colors.grey,
  422.                   fontWeight: FontWeight.normal,
  423.                   fontSize: 12.0,
  424.                 ),
  425.               ),
  426.             ],
  427.           )
  428.         ],
  429.       ),
  430.     );
  431.   }
  432. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement