Advertisement
rifki_cs29

DetailPageDart

Aug 7th, 2021
1,352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 17.63 KB | None | 0 0
  1. part of 'pages.dart';
  2.  
  3. class DetailRestaurant extends StatefulWidget {
  4.   static const routeName = '/detail_restaurant_page';
  5.   final String id;
  6.  
  7.   DetailRestaurant({required this.id});
  8.  
  9.   @override
  10.   _DetailRestaurantState createState() => _DetailRestaurantState();
  11. }
  12.  
  13. class _DetailRestaurantState extends State<DetailRestaurant> {
  14.   TextEditingController _nameController = TextEditingController();
  15.   TextEditingController _reviewController = TextEditingController();
  16.   late Future<void> postReview;
  17.  
  18.   @override
  19.   Widget build(BuildContext context) {
  20.     return Scaffold(
  21.       body: _buildContentDetail(),
  22.     );
  23.   }
  24.  
  25.   Widget _buildContentDetail() {
  26.     return ChangeNotifierProvider<DetailRestaurantProvider>(
  27.         create: (_) =>
  28.             DetailRestaurantProvider(apiService: ApiService(), id: widget.id),
  29.         child: Consumer<DetailRestaurantProvider>(
  30.           builder: (context, state, _) {
  31.           if (state.state == ResultState.Loading) {
  32.             return Loading();
  33.           } else if (state.state == ResultState.HasData) {
  34.             var detail = state.detailRestaurant.restaurant;
  35.             return Stack(
  36.               children: [
  37.                 Container(
  38.                   color: Colors.white,
  39.                 ),
  40.                 SafeArea(
  41.                     child: Container(
  42.                   color: Colors.white,
  43.                 )),
  44.                 SafeArea(
  45.                     child: Container(
  46.                   height: 300,
  47.                   width: double.infinity,
  48.                   decoration: BoxDecoration(
  49.                       image: DecorationImage(
  50.                           image: NetworkImage(
  51.                               ApiService.baseUrlImage + detail!.pictureId),
  52.                           fit: BoxFit.cover)),
  53.                 )),
  54.                 SafeArea(
  55.                     child: ListView(
  56.                   children: [
  57.                     Column(
  58.                       children: [
  59.                         Container(
  60.                           height: 80,
  61.                           child: Align(
  62.                             alignment: Alignment.centerLeft,
  63.                             child: Row(
  64.                                 mainAxisAlignment:
  65.                                     MainAxisAlignment.spaceBetween,
  66.                                 children: <Widget>[
  67.                                   MaterialButton(
  68.                                     color: Colors.white,
  69.                                     shape: CircleBorder(),
  70.                                     onPressed: () {
  71.                                       Navigator.pop(context);
  72.                                     },
  73.                                     child: Padding(
  74.                                       padding: const EdgeInsets.all(2),
  75.                                       child: Icon(Icons.arrow_back,
  76.                                           color: mainColor),
  77.                                     ),
  78.                                   ),
  79.                                   MaterialButton(
  80.                                     color: Colors.white,
  81.                                     shape: CircleBorder(),
  82.                                     onPressed: () {
  83.                                       Share.share(
  84.                                         "${detail.name}\nLocation: ${detail.city}\n${ApiService.baseUrlImage}${detail.pictureId}" );
  85.                                     },
  86.                                     child: Padding(
  87.                                       padding: const EdgeInsets.all(2),
  88.                                       child: Icon(Icons.share,
  89.                                           color: mainColor),
  90.                                     ),
  91.                                   ),
  92.                                 ]),
  93.                           ),
  94.                         ),
  95.                         Container(
  96.                           margin: EdgeInsets.only(top: 200),
  97.                           padding: EdgeInsets.symmetric(
  98.                               vertical: 26, horizontal: defaultMargin),
  99.                           decoration: BoxDecoration(
  100.                               borderRadius: BorderRadius.only(
  101.                                   topLeft: Radius.circular(24),
  102.                                   topRight: Radius.circular(24)),
  103.                               color: Colors.white),
  104.                           child: Column(
  105.                             crossAxisAlignment: CrossAxisAlignment.start,
  106.                             children: [
  107.                               Container(
  108.                                 child: Row(
  109.                                   mainAxisAlignment:
  110.                                       MainAxisAlignment.spaceBetween,
  111.                                   children: [
  112.                                     Text(
  113.                                       detail.name,
  114.                                       maxLines: 1,
  115.                                       overflow: TextOverflow.ellipsis,
  116.                                       style: textFontStyle2.copyWith(
  117.                                           fontWeight: FontWeight.bold),
  118.                                     ),
  119.                                     Rating(detail.rating),
  120.                                   ],
  121.                                 ),
  122.                               ),
  123.                               Container(
  124.                                   margin: EdgeInsets.only(top: 8),
  125.                                   child: Row(
  126.                                       mainAxisSize: MainAxisSize.min,
  127.                                       children: <Widget>[
  128.                                         Icon(Icons.place,
  129.                                             size: 16, color: mainColor),
  130.                                         SizedBox(
  131.                                           width: 3,
  132.                                         ),
  133.                                         Expanded(
  134.                                           child: Text(
  135.                                             detail.city,
  136.                                             maxLines: 2,
  137.                                             overflow: TextOverflow.ellipsis,
  138.                                             style: subTextFontStyle.copyWith(
  139.                                                 fontSize: 13),
  140.                                           ),
  141.                                         )
  142.                                       ])),
  143.                               Container(
  144.                                   height: 40,
  145.                                   margin: EdgeInsets.only(top: 6),
  146.                                   width: double.infinity,
  147.                                   child: ListCategories(
  148.                                       categories: detail.categories)),
  149.                               Container(
  150.                                 margin: EdgeInsets.only(top: 8, bottom: 10),
  151.                                 child: Text(
  152.                                   detail.description,
  153.                                   style:
  154.                                       subTextFontStyle.copyWith(fontSize: 13),
  155.                                 ),
  156.                               ),
  157.                               Container(
  158.                                   margin: EdgeInsets.only(top: 4, bottom: 4),
  159.                                   child: Row(children: [
  160.                                     Column(
  161.                                         crossAxisAlignment:
  162.                                             CrossAxisAlignment.start,
  163.                                         children: [
  164.                                           Text(
  165.                                             'Foods Menu',
  166.                                             style: textFontStyle3.copyWith(
  167.                                                 fontSize: 13,
  168.                                                 fontWeight: FontWeight.w500),
  169.                                           ),
  170.                                         ])
  171.                                   ])),
  172.                               Container(
  173.                                   height: 130,
  174.                                   width: double.infinity,
  175.                                   child: ListMenus.food(
  176.                                       foods: detail.menus?.foods)),
  177.                               Container(
  178.                                   margin: EdgeInsets.only(top: 4, bottom: 4),
  179.                                   child: Row(children: [
  180.                                     Column(
  181.                                         crossAxisAlignment:
  182.                                             CrossAxisAlignment.start,
  183.                                         children: [
  184.                                           Text(
  185.                                             'Drinks Menu',
  186.                                             style: textFontStyle3.copyWith(
  187.                                                 fontSize: 13,
  188.                                                 fontWeight: FontWeight.w500),
  189.                                           ),
  190.                                         ])
  191.                                   ])),
  192.                               Container(
  193.                                   height: 130,
  194.                                   width: double.infinity,
  195.                                   child: ListMenus.drink(
  196.                                       drinks: detail.menus?.drinks)),
  197.                               Container(
  198.                                   margin: EdgeInsets.only(top: 4, bottom: 4),
  199.                                   child: Row(children: [
  200.                                     Column(
  201.                                         crossAxisAlignment:
  202.                                             CrossAxisAlignment.start,
  203.                                         children: [
  204.                                           Text(
  205.                                             'Customer Reviews',
  206.                                             style: textFontStyle3.copyWith(
  207.                                                 fontSize: 13,
  208.                                                 fontWeight: FontWeight.w500),
  209.                                           ),
  210.                                         ])
  211.                                   ])),
  212.                               Container(
  213.                                   height: (detail.consumerReviews?.length == 1)
  214.                                       ? 60
  215.                                       : 120,
  216.                                   width: double.infinity,
  217.                                   child: (detail.consumerReviews?.length != 0)
  218.                                       ? ListReviews(
  219.                                           reviews: detail.consumerReviews)
  220.                                       : Column(
  221.                                           mainAxisAlignment:
  222.                                               MainAxisAlignment.center,
  223.                                           crossAxisAlignment:
  224.                                               CrossAxisAlignment.center,
  225.                                           children: [
  226.                                             Container(
  227.                                                 child: Text('No Review',
  228.                                                     style: subTextFontStyle
  229.                                                         .copyWith(
  230.                                                             fontSize: 12)))
  231.                                           ],
  232.                                         )),
  233.                               Container(
  234.                                 height: 65,
  235.                                 padding: EdgeInsets.fromLTRB(0, 12, 0, 8),
  236.                                 child:
  237.                                   TextField(
  238.                                     style: textFontStyle3.copyWith(fontSize: 14),
  239.                                     controller: _nameController,
  240.                                     decoration: InputDecoration(
  241.                                       labelText: 'Name',
  242.                                       hintText: 'Name',
  243.                                       labelStyle: TextStyle(
  244.                                         color: mainColor,
  245.                                       ),
  246.                                       border: OutlineInputBorder(
  247.                                         borderSide: BorderSide(color: mainColor),
  248.                                       ),
  249.                                       focusedBorder: OutlineInputBorder(
  250.                                         borderSide: BorderSide(color: mainColor),
  251.                                       ),
  252.                                       suffixIcon: Icon(
  253.                                         Icons.person,
  254.                                         color: mainColor,
  255.                                       ),
  256.                                       contentPadding: EdgeInsets.fromLTRB(12, 8, 12, 2)
  257.                                     ),
  258.                                   )
  259.                               ),
  260.                               Container(
  261.                                 height: 70,
  262.                                 padding: EdgeInsets.fromLTRB(0, 2, 0, 2),
  263.                                 child:
  264.                                   TextField(
  265.                                     style: textFontStyle3.copyWith(fontSize: 14),
  266.                                     controller: _reviewController,
  267.                                     maxLines: 2,
  268.                                     decoration: InputDecoration(
  269.                                       labelText: 'Review',
  270.                                       hintText: 'Review',
  271.                                       labelStyle: TextStyle(
  272.                                         color: mainColor,
  273.                                       ),
  274.                                       border: OutlineInputBorder(
  275.                                         borderSide: BorderSide(color: mainColor),
  276.                                       ),
  277.                                       focusedBorder: OutlineInputBorder(
  278.                                         borderSide: BorderSide(color: mainColor),
  279.                                       ),
  280.                                       suffixIcon: Icon(
  281.                                         Icons.reviews,
  282.                                         color: mainColor,
  283.                                       ),
  284.                                       contentPadding: EdgeInsets.fromLTRB(12, 8, 12, 2)
  285.                                     ),
  286.                                   )
  287.                               ),
  288.  
  289.                               Container(
  290.                                 height: 50,
  291.                                 width: double.infinity,
  292.                                 child:
  293.                                   ElevatedButton(
  294.                                     child: Text(
  295.                                       'Submit Review',
  296.                                       style: textFontStyle3.copyWith(color: Colors.white),
  297.                                     ),
  298.                                     style: ElevatedButton.styleFrom(
  299.                                       primary: mainColor,
  300.                                       minimumSize: Size(88, 36),
  301.                                       padding: EdgeInsets.symmetric(horizontal: 16),
  302.                                       shape: const RoundedRectangleBorder(
  303.                                         borderRadius: BorderRadius.all(Radius.circular(8)),
  304.                                       ),
  305.                                     ),
  306.                                     onPressed: () {
  307.                                       setState(() {
  308.                                         ConsumerReviewPost data = ConsumerReviewPost(
  309.                                             id: widget.id,
  310.                                             name: _nameController.text,
  311.                                             review: _reviewController.text);
  312.                                             postReview = Provider.of<DetailRestaurantProvider>(context, listen: false).postReview(data);
  313.                                         _nameController.clear();
  314.                                         _reviewController.clear();
  315.                                         Navigator.pushReplacement(
  316.                                             context,
  317.                                             MaterialPageRoute(
  318.                                                 builder: (BuildContext context) => super.widget));
  319.                                         // Scaffold.of(context).showSnackBar(
  320.                                         //   SnackBar(
  321.                                         //     content: Text("Data Berhasil disimpan"),
  322.                                         //   ),
  323.                                         // );
  324.                                       });
  325.                                     },
  326.                                   ),
  327.                               ),
  328.                             ],
  329.                           ),
  330.                         )
  331.                       ],
  332.                     )
  333.                   ],
  334.                 ))
  335.               ],
  336.             );
  337.           } else if (state.state == ResultState.NoData) {
  338.             return NoData();
  339.           } else if (state.state == ResultState.Error) {
  340.             return Error(message: state.message);
  341.           } else {
  342.             return Center(child: Text(''));
  343.           }
  344.         }
  345.       )
  346.     );
  347.   }
  348.  
  349.   @override
  350.   void dispose() {
  351.     super.dispose();
  352.     _nameController.dispose();
  353.     _reviewController.dispose();
  354.   }
  355. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement