abhi_diablo

DashboardItemListScreen class

Oct 8th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 18.98 KB | None | 0 0
  1. import 'dart:convert';
  2.  
  3. import 'package:custom_progress_dialog/custom_progress_dialog.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_svg/svg.dart';
  6. import 'package:flyerbin_flutter/Utils/Urls.dart';
  7. import 'package:http/http.dart' as http;
  8.  
  9. import 'Model/CategoryItemModel.dart';
  10. import 'SideDrawerScreen.dart';
  11. import 'Utils/Constants.dart';
  12. import 'Utils/CustomDialogs.dart';
  13. import 'Utils/SharedPrefrence.dart';
  14. CategoryItemModel categoryItemModelFromJson(String str) => CategoryItemModel.fromJson(json.decode(str));
  15.  
  16. String categoryItemModelToJson(CategoryItemModel data) => json.encode(data.toJson());
  17. class DashboardItemListScreen extends StatefulWidget {
  18.   @override
  19.   _DashboardItemListScreenState createState() =>
  20.       _DashboardItemListScreenState();
  21. }
  22.  
  23. class _DashboardItemListScreenState extends State<DashboardItemListScreen> {
  24.   bool _isChecked = false;
  25.   List<bool> inputs = new List<bool>();
  26.   String userToken;
  27.   final _scaffoldKey = GlobalKey<ScaffoldState>();
  28.   List<CategoryItemModel> category_item_list = [];
  29.   CategoryItemModel categoryItemModel;
  30.   @override
  31.   void initState() {
  32.     // TODO: implement initState
  33.     super.initState();
  34.     Future token = SharedPrefrence().getToken();
  35.     token.then((data) async {
  36.       userToken = data;
  37.       getCategoryLists();
  38.     });
  39.  
  40.     setState(() {
  41.       for (int i = 0; i < 4; i++) {
  42.         inputs.add(false);
  43.       }
  44.     });
  45.   }
  46.   void ItemChange(bool val, int index) {
  47.     setState(() {
  48.       inputs[index] = val;
  49.     });
  50.   }
  51.  
  52.   @override
  53.   Widget build(BuildContext context) {
  54.     return Scaffold(
  55.       key: _scaffoldKey,
  56.       resizeToAvoidBottomInset: false,
  57.       drawer: SideDraweScreen(),
  58.       appBar: AppBar(
  59.         iconTheme: new IconThemeData(color: Color.fromRGBO(34, 83, 148, 1)),
  60.         title: appbarLogo(),
  61.         backgroundColor: Colors.white,
  62.         actions: [
  63.           Padding(
  64.             padding: const EdgeInsets.all(8.0),
  65.             child: Icon(
  66.               Icons.shopping_cart,
  67.               color: Colors.blue[800],
  68.             ),
  69.           )
  70.         ],
  71.       ),
  72.       body: SingleChildScrollView(
  73.         child: Column(
  74.           crossAxisAlignment: CrossAxisAlignment.start,
  75.           children: [
  76.             Expanded(
  77.               flex: 0,
  78.               child: Container(
  79.                 height: 30,
  80.                 child: Row(
  81.                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
  82.                   children: [
  83.                     Padding(
  84.                       padding: const EdgeInsets.all(8.0),
  85.                       child: Text(
  86.                         "Select All",
  87.                         softWrap: true,
  88.                         style: TextStyle(color: Colors.blue[500], fontSize: 15),
  89.                       ),
  90.                     ),
  91.                     Padding(
  92.                       padding: const EdgeInsets.all(8.0),
  93.                       child: Icon(
  94.                         Icons.delete,
  95.                         color: Colors.blue[500],
  96.                         size: 20,
  97.                       ),
  98.                     ),
  99.                   ],
  100.                 ),
  101.               ),
  102.             ),
  103.             Expanded(
  104.               flex: 0,
  105.               child: Padding(
  106.                 padding: const EdgeInsets.all(8.0),
  107.                 child: Text(
  108.                   "Shopping List",
  109.                   softWrap: true,
  110.                   style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
  111.                 ),
  112.               ),
  113.             ),
  114.             Expanded(
  115.               flex: 0,
  116.               child: Padding(
  117.                 padding: const EdgeInsets.all(2),
  118.                 child: Card(
  119.                   child: Row(
  120.                     mainAxisAlignment: MainAxisAlignment.spaceBetween,
  121.                     children: [
  122.                       Expanded(
  123.                         flex: 0,
  124.                         child: Container(
  125.                           width: 220,
  126.                           child: CheckboxListTile(
  127.                             controlAffinity: ListTileControlAffinity.leading,
  128.                             title: Text('Tee'),
  129.                             value: _isChecked,
  130.                             onChanged: (bool value) {
  131.                               setState(() {
  132.                                 _isChecked = value;
  133.                               });
  134.                             },
  135.                           ),
  136.                         ),
  137.                       ),
  138.                       Expanded(
  139.                           flex: 0,
  140.                           child: Padding(
  141.                             padding: const EdgeInsets.all(8.0),
  142.                             child: Icon(
  143.                               Icons.cancel,
  144.                               size: 20,
  145.                               color: Colors.blueGrey,
  146.                             ),
  147.                           ))
  148.                     ],
  149.                   ),
  150.                 ),
  151.               ),
  152.             ),
  153.             Expanded(flex: 0, child: Categories()),
  154.           ],
  155.         ),
  156.       ),
  157.       floatingActionButton: new FloatingActionButton(
  158.         onPressed: () {
  159.           PopupCategory(context);
  160.         },
  161.         child: const Icon(
  162.           Icons.add,
  163.         ),
  164.       ),
  165.     );
  166.   }
  167.  
  168.   Widget appbarLogo() {
  169.     return SvgPicture.asset(
  170.       "assets/images/flyerbin_logo.svg",
  171.       height: 40,
  172.     );
  173.   }
  174.   Widget Categories() {
  175.     Size size = MediaQuery.of(context).size;
  176.     return categoryItemModel.data.userTags.length!= 0 ? Container(
  177.       child: ListView.builder(
  178.         shrinkWrap: true,
  179.         physics: NeverScrollableScrollPhysics(),
  180.         itemBuilder: (context, index) {
  181.           return Padding(
  182.             padding: EdgeInsets.all(2),
  183.             child: Column(
  184.               crossAxisAlignment: CrossAxisAlignment.start,
  185.               children: <Widget>[
  186.                 Padding(
  187.                   padding: const EdgeInsets.all(8.0),
  188.                   child: Text(
  189.                     '${categoryItemModel.data.userTags[index].name}',
  190.                     style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
  191.                   ),
  192.                 ),
  193.                 ListView.builder(
  194.                   shrinkWrap: true,
  195.                   physics: ClampingScrollPhysics(),
  196.                   itemBuilder: (context, index1) {
  197.                     return Card(
  198.                       child: Row(
  199.                         mainAxisAlignment: MainAxisAlignment.spaceBetween,
  200.                         children: [
  201.                           Expanded(
  202.                             flex: 0,
  203.                             child: Container(
  204.                               width: 220,
  205.                               child: CheckboxListTile(
  206.                                 controlAffinity:
  207.                                 ListTileControlAffinity.leading,
  208.                                 title: Text(
  209.                                   '${categoryItemModel.data.userTags[index].tags[index1].name}',
  210.                                   style: TextStyle(fontSize: 13),
  211.                                 ),
  212.                                 value: inputs[index1],
  213.                                 onChanged: (bool value) {
  214.                                   ItemChange(value, index1);
  215.                                   setState(() {
  216.                                     _isChecked = value;
  217.                                   });
  218.                                 },
  219.                               ),
  220.                             ),
  221.                           ),
  222.                           Expanded(
  223.                             flex: 0,
  224.                             child: Row(
  225.                               crossAxisAlignment: CrossAxisAlignment.center,
  226.                               mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  227.                               children: [
  228.                                 Expanded(
  229.                                     flex: 0,
  230.                                     child: Padding(
  231.                                       padding: const EdgeInsets.all(8.0),
  232.                                       child: Text(
  233.                                         "13" + "Deals",
  234.                                         softWrap: true,
  235.                                         style: TextStyle(color: Colors.blue),
  236.                                       ),
  237.                                     )),
  238.                                 Expanded(
  239.                                     flex: 0,
  240.                                     child: Padding(
  241.                                       padding: const EdgeInsets.all(8.0),
  242.                                       child: Icon(
  243.                                         Icons.arrow_forward_ios,
  244.                                         size: 20,
  245.                                         color: Colors.blueGrey,
  246.                                       ),
  247.                                     )),
  248.                               ],
  249.                             ),
  250.                           )
  251.                         ],
  252.                       ),
  253.                     );
  254.                   },
  255.                   itemCount: categoryItemModel.data.userTags[index].tags.length, // this is a hardcoded value
  256.                 ),
  257.               ],
  258.             ),
  259.           );
  260.         },
  261.         itemCount: categoryItemModel.data.userTags.length, // this is a hardcoded value
  262.       ),
  263.     ):Center(child: CircularProgressIndicator(),);
  264.   }
  265.  
  266.  
  267.   Future<void> PopupCategory(BuildContext context) async {
  268.     await showDialog(
  269.         context: context,
  270.         builder: (BuildContext context) {
  271.           return Dialog(
  272.             shape: RoundedRectangleBorder(
  273.                 borderRadius: BorderRadius.circular(8.0)), //this right here
  274.             child: Container(
  275.               height: 365,
  276.               child: Padding(
  277.                 padding: const EdgeInsets.all(12.0),
  278.                 child: Column(
  279.                   mainAxisSize: MainAxisSize.max,
  280.                   children: [
  281.                     Row(
  282.                       mainAxisAlignment: MainAxisAlignment.spaceBetween,
  283.                       crossAxisAlignment: CrossAxisAlignment.start,
  284.                       children: [
  285.                         Row(
  286.                           mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  287.                           children: [
  288.                             Icon(
  289.                               Icons.cancel,
  290.                               color: Colors.blueGrey,
  291.                               size: 20,
  292.                             ),
  293.                             Text(
  294.                               "Recommended",
  295.                               style: TextStyle(fontSize: 15),
  296.                             )
  297.                           ],
  298.                         ),
  299.                         Row(
  300.                           mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  301.                           children: [
  302.                             Icon(
  303.                               Icons.check_circle,
  304.                               color: Colors.blue,
  305.                               size: 20,
  306.                             ),
  307.                             Text(
  308.                               "Done",
  309.                               style: TextStyle(fontSize: 14),
  310.                             )
  311.                           ],
  312.                         ),
  313.                       ],
  314.                     ),
  315.                     Divider(
  316.                       thickness: 0.8,
  317.                     ),
  318.                     Container(
  319.                       child: GridView.count(
  320.                         crossAxisCount: 4,
  321.                         childAspectRatio: MediaQuery.of(context).size.width /
  322.                             (MediaQuery.of(context).size.height / 1.2),
  323.                         crossAxisSpacing: 5.0,
  324.                         mainAxisSpacing: 5.0,
  325.                         shrinkWrap: true,
  326.                         physics: ScrollPhysics(),
  327.                         children: List.generate(10, (index) {
  328.                           return SingleChildScrollView(
  329.                             child: Column(
  330.                               children: [
  331.                                 Expanded(
  332.                                   flex: 0,
  333.                                   child: GestureDetector(
  334.                                     onTap: () {},
  335.                                     child: Container(
  336.                                       height: 90,
  337.                                       child: Column(
  338.                                         mainAxisAlignment:
  339.                                             MainAxisAlignment.spaceEvenly,
  340.                                         crossAxisAlignment:
  341.                                             CrossAxisAlignment.start,
  342.                                         children: <Widget>[
  343.                                           Expanded(
  344.                                             flex: 0,
  345.                                             child: CircleAvatar(
  346.                                               radius: 23,
  347.                                               backgroundImage: NetworkImage(
  348.                                                   'https://images.unsplash.com/photo-1523205771623-e0faa4d2813d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=89719a0d55dd05e2deae4120227e6efc&auto=format&fit=crop&w=1953&q=80'),
  349.                                             ),
  350.                                           ),
  351.                                           Expanded(
  352.                                             flex: 0,
  353.                                             child: Padding(
  354.                                               padding:
  355.                                                   const EdgeInsets.all(4.0),
  356.                                               child: Text(
  357.                                                 "product $index",
  358.                                                 style: TextStyle(
  359.                                                     fontWeight: FontWeight.w400,
  360.                                                     fontSize: 12),
  361.                                               ),
  362.                                             ),
  363.                                           ),
  364.                                         ],
  365.                                       ),
  366.                                     ),
  367.                                   ),
  368.                                 ),
  369.                               ],
  370.                             ),
  371.                           );
  372.                         }),
  373.                       ),
  374.                     ),
  375.                     Expanded(
  376.                       flex: 0,
  377.                       child: Padding(
  378.                         padding: const EdgeInsets.all(2),
  379.                         child: Container(
  380.                           height: 35,
  381.                           width: 300,
  382.                           child: TextField(
  383.                             decoration: InputDecoration(
  384.                                 border: OutlineInputBorder(),
  385.                                 fillColor: Colors.blueGrey[200],
  386.                                 labelStyle: TextStyle(fontSize: 12),
  387.                                 contentPadding: EdgeInsets.all(5),
  388.                                 hintText: 'Search Here',
  389.                                 prefixIcon: Icon(
  390.                                   Icons.search,
  391.                                   color: Colors.blueGrey,
  392.                                 )),
  393.                           ),
  394.                         ),
  395.                       ),
  396.                     ),
  397.                   ],
  398.                 ),
  399.               ),
  400.             ),
  401.           );
  402.         });
  403.   }
  404.  
  405.   Future<void> getCategoryLists() async {
  406.     //ProgressDialog dialog = CustomDialogs().showLoadingProgressDialog(context);
  407.     var response = await http.get(
  408.         "${Urls.baseUrl}${Urls.userList}?latitude=${Constants.latitude}&longitude=${Constants.longitude}&radius=100&locale=en",
  409.         headers: {
  410.           "Content-Type": "application/json",
  411.           "Authorization": "Bearer ${userToken}",
  412.           "Accept": "application/json"
  413.         });
  414.     print("getCategoryLists response " + response.body.toString());
  415.  
  416.     if (response.statusCode == 200) {
  417.  
  418.       categoryItemModel = categoryItemModelFromJson(response.body);
  419.       print(categoryItemModel);
  420.     }
  421.     else
  422.       {
  423.         final snackBar = SnackBar(content: Text("Error,Try again"));
  424.               _scaffoldKey.currentState.showSnackBar(snackBar);
  425.       }
  426.   }
  427. }
  428. //   Future<void> getCategoryLists() async {
  429. //     ProgressDialog dialog = CustomDialogs().showLoadingProgressDialog(context);
  430. //     var response = await http.get(
  431. //         "${Urls.baseUrl}${Urls.userList}?latitude=${Constants.latitude}&longitude=${Constants.longitude}&radius=100&locale=en",
  432. //         headers: {
  433. //           "Content-Type": "application/json",
  434. //           "Authorization": "Bearer ${userToken}",
  435. //           "Accept": "application/json"
  436. //         });
  437. //
  438. //     Map<String, dynamic> value = json.decode(response.body);
  439. //     if (response.statusCode == 200) {
  440. //       // dialog.dismissProgressDialog(context);
  441. //       try {
  442. //         print("getCategoryLists response " + response.body.toString());
  443. //         Map<String, dynamic> value = json.decode(response.body);
  444. //
  445. //         var status = value['success'];
  446. //         var message = value['message'];
  447. //         print(status);
  448. //         if (status == true) {
  449. //           try {
  450. //             var rest = value["data"];
  451. //             if (rest.length > 0) {
  452. //               category_item_list = rest.map<CategoryItemModel>((json) => CategoryItemModel.fromJson(json)).toList();
  453. //               print("List Size: ${category_item_list.length}");
  454. //
  455. //               setState(() {
  456. //                 return category_item_list;
  457. //                 // print(category_item_list.length);
  458. //               });
  459. //             } else {
  460. //               final snackBar = SnackBar(content: Text("No Data Available"));
  461. //               _scaffoldKey.currentState.showSnackBar(snackBar);
  462. //             }
  463. //           } catch (e) {
  464. //             e.toString();
  465. //           }
  466. //         } else {
  467. //           print("Error...");
  468. //           final snackBar = SnackBar(content: Text(message));
  469. //           _scaffoldKey.currentState.showSnackBar(snackBar);
  470. //         }
  471. //       } catch (e) {
  472. //         print(e.toString());
  473. //       }
  474. //     } else if (response.statusCode == 404) {
  475. //       dialog.dismissProgressDialog(context);
  476. //       var message = value['message'];
  477. //       final snackBar = SnackBar(content: Text(message));
  478. //       _scaffoldKey.currentState.showSnackBar(snackBar);
  479. //     } else if (response.statusCode == 208) {
  480. //       dialog.dismissProgressDialog(context);
  481. //     } else {
  482. //       var message = value['message'];
  483. //       dialog.dismissProgressDialog(context);
  484. //       final snackBar = SnackBar(content: Text(message));
  485. //       _scaffoldKey.currentState.showSnackBar(snackBar);
  486. //     }
  487. //   }
  488. // }
  489.  
Add Comment
Please, Sign In to add comment