esiribiz

hello world

Apr 7th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 15.33 KB | None | 0 0
  1. import 'package:food_app/api/place_api.dart';
  2. import 'package:food_app/model/place.dart';
  3. import 'package:food_app/notifier/place_notifier.dart';
  4. import 'package:food_app/screens/place_form.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:provider/provider.dart';
  7.  
  8. class FoodDetail extends StatelessWidget {
  9.   @override
  10.   Widget build(BuildContext context) {
  11.     FoodNotifier foodNotifier = Provider.of<FoodNotifier>(context);
  12.  
  13.     _onFoodDeleted(Food food) {
  14.       Navigator.pop(context);
  15.       foodNotifier.deleteFood(food);
  16.     }
  17.  
  18.     List allImgs = [
  19.       Image.network(foodNotifier.currentFood.image != null
  20.           ? foodNotifier.currentFood.image
  21.           : 'https://www.testingxperts.com/wp-content/uploads/2019/02/placeholder-img.jpg')
  22.     ];
  23.  
  24.     return Scaffold(
  25.       appBar: AppBar(title: Text(foodNotifier.currentFood.name)),
  26.       body: Stack(
  27.         children: <Widget>[
  28.           Align(
  29.             alignment: Alignment.topCenter,
  30.             child: Container(
  31.               height: 300.0,
  32.               child: PageView.builder(
  33.                   itemCount: allImgs.length,
  34.                   pageSnapping: true,
  35.                   itemBuilder: (BuildContext context, int i) {
  36.                     return Container(
  37.                       child: Image.network(allImgs[i], fit: BoxFit.cover),
  38.                     );
  39.                   }),
  40.             ),
  41.           ),
  42.           Align(
  43.             alignment: Alignment.topCenter,
  44.             child: Container(
  45.               height: 75.0,
  46.               child: AppBar(
  47.                 actions: <Widget>[
  48.                   IconButton(
  49.                     icon: Icon(
  50.                       Icons.share,
  51.                       color: Colors.white,
  52.                       size: 16.0,
  53.                     ),
  54.                     onPressed: () {
  55.                       Navigator.of(context).pop();
  56.                     },
  57.                   )
  58.                 ],
  59.                 leading: IconButton(
  60.                   icon: Icon(
  61.                     Icons.arrow_back_ios,
  62.                     color: Colors.white,
  63.                     size: 20.0,
  64.                   ),
  65.                   onPressed: () {
  66.                     Navigator.of(context).pop();
  67.                   },
  68.                 ),
  69.                 backgroundColor: Colors.transparent,
  70.                 elevation: 0.0,
  71.               ),
  72.             ),
  73.           ),
  74.           Align(
  75.             alignment: Alignment.bottomCenter,
  76.             child: Container(
  77.               height: MediaQuery.of(context).size.height - 280,
  78.               decoration: BoxDecoration(
  79.                   color: Colors.white, borderRadius: BorderRadius.circular(20)),
  80.               child: Stack(
  81.                 children: <Widget>[
  82.                   Container(
  83.                     width: double.infinity,
  84.                     margin: EdgeInsets.only(bottom: 60),
  85.                     child: SingleChildScrollView(
  86.                         padding: EdgeInsets.all(30),
  87.                         child: Column(
  88.                           crossAxisAlignment: CrossAxisAlignment.start,
  89.                           mainAxisAlignment: MainAxisAlignment.start,
  90.                           children: <Widget>[
  91.                             Text(
  92.                               foodNotifier.currentFood.name,
  93.                               style: TextStyle(
  94.                                   fontSize: 19.0, fontWeight: FontWeight.bold),
  95.                             ),
  96.                             SizedBox(height: 10),
  97.                             Row(
  98.                               children: <Widget>[
  99.                                 Icon(Icons.star,
  100.                                     color: Colors.orange, size: 20),
  101.                                 Icon(Icons.star,
  102.                                     color: Colors.orange, size: 20),
  103.                                 Icon(Icons.star,
  104.                                     color: Colors.orange, size: 20),
  105.                                 Icon(Icons.star,
  106.                                     color: Colors.orange, size: 20),
  107.                                 Icon(Icons.star,
  108.                                     color: Colors.orange, size: 20),
  109.                                 SizedBox(width: 10),
  110.                                 Text(
  111.                                   "4.9",
  112.                                   style: TextStyle(
  113.                                       fontSize: 14.0,
  114.                                       color: Colors.orange,
  115.                                       fontWeight: FontWeight.bold),
  116.                                 ),
  117.                               ],
  118.                             ),
  119.                             SizedBox(height: 20),
  120.                             Row(
  121.                               crossAxisAlignment: CrossAxisAlignment.center,
  122.                               mainAxisAlignment: MainAxisAlignment.spaceBetween,
  123.                               children: <Widget>[
  124.                                 Column(
  125.                                   crossAxisAlignment: CrossAxisAlignment.start,
  126.                                   children: <Widget>[
  127.                                     Row(
  128.                                       children: <Widget>[
  129.                                         Text("\$ ",
  130.                                             style: TextStyle(
  131.                                                 fontSize: 15.0,
  132.                                                 color: Colors.orange,
  133.                                                 fontWeight: FontWeight.bold)),
  134.                                         Text(foodNotifier.currentFood.price,
  135.                                             style: TextStyle(
  136.                                                 fontSize: 20.0,
  137.                                                 color: Colors.orange,
  138.                                                 fontWeight: FontWeight.bold)),
  139.                                       ],
  140.                                     ),
  141.                                     Text("Price",
  142.                                         style: TextStyle(
  143.                                             fontSize: 15.0,
  144.                                             color: Colors.grey,
  145.                                             fontWeight: FontWeight.bold)),
  146.                                   ],
  147.                                 ),
  148.                                 Column(
  149.                                   crossAxisAlignment: CrossAxisAlignment.start,
  150.                                   children: <Widget>[
  151.                                     Row(
  152.                                       children: <Widget>[
  153.                                         Text("1",
  154.                                             style: TextStyle(
  155.                                                 fontSize: 20.0,
  156.                                                 color: Colors.orange,
  157.                                                 fontWeight: FontWeight.bold)),
  158.                                         Text(" room ",
  159.                                             style: TextStyle(
  160.                                                 fontSize: 15.0,
  161.                                                 color: Colors.orange,
  162.                                                 fontWeight: FontWeight.bold)),
  163.                                         Text("2",
  164.                                             style: TextStyle(
  165.                                                 fontSize: 20.0,
  166.                                                 color: Colors.orange,
  167.                                                 fontWeight: FontWeight.bold)),
  168.                                         Text(" hall",
  169.                                             style: TextStyle(
  170.                                                 fontSize: 15.0,
  171.                                                 color: Colors.orange,
  172.                                                 fontWeight: FontWeight.bold)),
  173.                                       ],
  174.                                     ),
  175.                                     Text("Room",
  176.                                         style: TextStyle(
  177.                                             fontSize: 15.0,
  178.                                             color: Colors.grey,
  179.                                             fontWeight: FontWeight.bold)),
  180.                                   ],
  181.                                 ),
  182.                                 Column(
  183.                                   crossAxisAlignment: CrossAxisAlignment.start,
  184.                                   children: <Widget>[
  185.                                     Row(
  186.                                       children: <Widget>[
  187.                                         Text(foodNotifier.currentFood.size,
  188.                                             style: TextStyle(
  189.                                                 fontSize: 20.0,
  190.                                                 color: Colors.orange,
  191.                                                 fontWeight: FontWeight.bold)),
  192.                                         Text(" m²",
  193.                                             style: TextStyle(
  194.                                                 fontSize: 14.0,
  195.                                                 color: Colors.orange,
  196.                                                 fontWeight: FontWeight.bold)),
  197.                                       ],
  198.                                     ),
  199.                                     Text("Area",
  200.                                         style: TextStyle(
  201.                                             fontSize: 15.0,
  202.                                             color: Colors.grey,
  203.                                             fontWeight: FontWeight.bold)),
  204.                                   ],
  205.                                 ),
  206.                               ],
  207.                             ),
  208.                             SizedBox(height: 30),
  209.                             Column(
  210.                               children: <Widget>[
  211.                                 GridView.count(
  212.                                   shrinkWrap: true,
  213.                                   scrollDirection: Axis.vertical,
  214.                                   padding: EdgeInsets.all(8),
  215.                                   crossAxisCount: 5,
  216.                                   crossAxisSpacing: 4,
  217.                                   mainAxisSpacing: 4,
  218.                                   children: foodNotifier.currentFood.features
  219.                                       .map(
  220.                                         (features) => Card(
  221.                                           color: Colors.black54,
  222.                                           child: Center(
  223.                                             child: Text(
  224.                                               features,
  225.                                               style: TextStyle(
  226.                                                   color: Colors.white,
  227.                                                   fontSize: 16),
  228.                                             ),
  229.                                           ),
  230.                                         ),
  231.                                       )
  232.                                       .toList(),
  233.                                 ),
  234.                               ],
  235.                             ),
  236.                             SizedBox(height: 30),
  237.                             Row(
  238.                               mainAxisAlignment: MainAxisAlignment.spaceBetween,
  239.                               children: <Widget>[
  240.                                 Text(
  241.                                   "Description",
  242.                                   style: TextStyle(
  243.                                       fontSize: 18.0,
  244.                                       fontWeight: FontWeight.bold),
  245.                                 ),
  246.                               ],
  247.                             ),
  248.                             SizedBox(height: 10),
  249.                             Text(foodNotifier.currentFood.description,
  250.                                 textAlign: TextAlign.justify,
  251.                                 style: TextStyle(fontSize: 14.0)),
  252.                           ],
  253.                         )),
  254.                   ),
  255.                   Align(
  256.                     alignment: Alignment.bottomCenter,
  257.                     child: Container(
  258.                       decoration: BoxDecoration(boxShadow: [
  259.                         BoxShadow(
  260.                             blurRadius: 3.0,
  261.                             color: Colors.grey.withOpacity(0.1),
  262.                             spreadRadius: 2.0)
  263.                       ]),
  264.                       height: 60,
  265.                       child: Row(
  266.                         mainAxisAlignment: MainAxisAlignment.spaceBetween,
  267.                         crossAxisAlignment: CrossAxisAlignment.center,
  268.                         children: <Widget>[
  269.                           Container(
  270.                             height: 60,
  271.                             width: MediaQuery.of(context).size.width / 2 - 30,
  272.                             alignment: Alignment(0, 0),
  273.                             child: Icon(Icons.chat, color: Colors.deepOrange),
  274.                           ),
  275.                           Container(
  276.                             height: 60,
  277.                             width: MediaQuery.of(context).size.width / 2 + 30,
  278.                             alignment: Alignment(0, 0),
  279.                             color: Colors.blue[600],
  280.                             child: Text(
  281.                               "Contact",
  282.                               style: TextStyle(
  283.                                   fontSize: 17.0, color: Colors.white),
  284.                             ),
  285.                           )
  286.                         ],
  287.                       ),
  288.                     ),
  289.                   ),
  290.                   Align(
  291.                     alignment: Alignment(0.7, -1.25),
  292.                     child: ClipRRect(
  293.                       borderRadius: BorderRadius.circular(20),
  294.                       child: SizedBox(
  295.                           height: 80,
  296.                           width: 80,
  297.                           child: Image.network(
  298.                               'https://www.testingxperts.com/wp-content/uploads/2019/02/placeholder-img.jpg',
  299.                               fit: BoxFit.cover)),
  300.                     ),
  301.                   ),
  302.                 ],
  303.               ),
  304.             ),
  305.           ),
  306.         ],
  307.       ),
  308.       floatingActionButton: Column(
  309.         mainAxisAlignment: MainAxisAlignment.end,
  310.         children: <Widget>[
  311.           FloatingActionButton(
  312.             heroTag: 'button1',
  313.             onPressed: () {
  314.               Navigator.of(context).push(
  315.                 MaterialPageRoute(builder: (BuildContext context) {
  316.                   return FoodForm(
  317.                     isUpdating: true,
  318.                   );
  319.                 }),
  320.               );
  321.             },
  322.             child: Icon(Icons.edit),
  323.             foregroundColor: Colors.white,
  324.           ),
  325.           SizedBox(height: 20),
  326.           FloatingActionButton(
  327.             heroTag: 'button2',
  328.             onPressed: () =>
  329.                 deleteFood(foodNotifier.currentFood, _onFoodDeleted),
  330.             child: Icon(Icons.delete),
  331.             backgroundColor: Colors.red,
  332.             foregroundColor: Colors.white,
  333.           ),
  334.         ],
  335.       ),
  336.     );
  337.   }
  338. }
Add Comment
Please, Sign In to add comment