Advertisement
theritz

ChoiceChip

Nov 8th, 2020
2,457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 6.60 KB | None | 0 0
  1.   Widget appBarWidget(BuildContext context) {
  2.     return PreferredSize(
  3.       preferredSize: Size.fromHeight(80),
  4.       child: Column(
  5.         mainAxisAlignment: MainAxisAlignment.center,
  6.         children: [
  7.           AppBar(
  8.             elevation: 0.0,
  9.             centerTitle: true,
  10.             iconTheme: IconThemeData(color: HexColor("#49516D")),
  11.             titleSpacing: 0,
  12.             actions: [
  13.               IconButton(
  14.                 splashColor: Colors.transparent,
  15.                 enableFeedback: true,
  16.                 icon: SvgPicture.asset(
  17.                   "assets/image/icons/filter.svg",
  18.                   color: HexColor("#49516D"),
  19.                 ),
  20.                 onPressed: () => {
  21.                   showModalBottomSheet(
  22.                     enableDrag: true,
  23.                     isScrollControlled: true,
  24.                     shape: RoundedRectangleBorder(
  25.                       borderRadius: BorderRadius.only(
  26.                         topRight: Radius.circular(10),
  27.                         topLeft: Radius.circular(10),
  28.                       ),
  29.                     ),
  30.                     context: context,
  31.                     builder: (context) => SingleChildScrollView(
  32.                       child: modalFilter(context) // Buka modal filter,
  33.                     ),
  34.                   )
  35.                 },
  36.               ),
  37.               IconButton(
  38.                 splashColor: Colors.transparent,
  39.                 icon: Stack(
  40.                   children: <Widget>[
  41.                     SvgPicture.asset("assets/image/icons/notification.svg"),
  42.                     Positioned(
  43.                       top: 0.0,
  44.                       right: -1.0,
  45.                       child: Icon(
  46.                         Icons.brightness_1,
  47.                         size: 8.0,
  48.                         color: Colors.redAccent,
  49.                       ),
  50.                     ),
  51.                   ],
  52.                 ),
  53.                 onPressed: null,
  54.               )
  55.             ],
  56.             backgroundColor: HexColor("#F9F9F9"),
  57.           )
  58.         ],
  59.       ),
  60.     );
  61.   }
  62.  
  63.   Widget modalFilter(BuildContext context) {
  64.     void filterListener(BuildContext context, FilterState state) {
  65.       state.maybeMap(
  66.         orElse: () {},
  67.         onLoading: (value) {
  68.           _isLoadingLocation = false;
  69.           _isLoadingPrice = false;
  70.         },
  71.         onResponseLocation: (value) {
  72.           _isLoadingLocation = true;
  73.           _listDataLocation = value.list;
  74.         },
  75.         typePrice: (value) {
  76.           _isLoadingPrice = true;
  77.           _listPriceType = value.list;
  78.         },
  79.       );
  80.     }
  81.  
  82.     if (_networkStatus) {
  83.       return BlocProvider(
  84.         create: (context) => getIt<FilterCubit>()
  85.           ..getListLocation()
  86.           ..getTypePrice(),
  87.         child: BlocConsumer<FilterCubit, FilterState>(
  88.           listener: filterListener,
  89.           builder: (context, state) {
  90.             return (_isLoadingLocation == true && _isLoadingPrice == true)
  91.                 ? Container(
  92.                     child: Padding(
  93.                       padding: EdgeInsets.only(
  94.                         top: 20,
  95.                         left: 10,
  96.                         right: 10,
  97.                         bottom: MediaQuery.of(context).viewInsets.bottom,
  98.                       ),
  99.                       child: Column(
  100.                         crossAxisAlignment: CrossAxisAlignment.start,
  101.                         mainAxisSize: MainAxisSize.min,
  102.                         children: [
  103.                           Container(
  104.                             margin: const EdgeInsets.only(bottom: 20),
  105.                             child: Text(
  106.                               "Filter Pencarian",
  107.                               style: TextStyle(
  108.                                 fontSize: 18,
  109.                                 fontWeight: FontWeight.bold,
  110.                               ),
  111.                             ),
  112.                           ),
  113.                           priceType(context, _listPriceType), // Widget ChoiceChip
  114.                           Container(
  115.                             margin: const EdgeInsets.only(
  116.                               bottom: 20,
  117.                             ),
  118.                             child: Center(
  119.                               child: ButtonWidget(
  120.                                 onTap: () {
  121.                                   print(_priceTypeSelected);
  122.                                   _listCubit.getListAds(
  123.                                     typePrice: _priceTypeSelected.id,
  124.                                   );
  125.                                 },
  126.                                 width: 200,
  127.                                 splashColor: "#dde3f7",
  128.                                 textColor: "#ffffff",
  129.                                 label: "Terapkan Filter",
  130.                                 backgroundColor: "#4F69C7",
  131.                               ),
  132.                             ),
  133.                           ),
  134.                         ],
  135.                       ),
  136.                     ),
  137.                   )
  138.                 : SizedBox(
  139.                     height: 200,
  140.                     child: Center(
  141.                       child: CircularProgressIndicator(),
  142.                     ),
  143.                   );
  144.           },
  145.         ),
  146.       );
  147.     } else {
  148.       return SizedBox(
  149.         height: 200,
  150.         child: Center(child: Text("Periksa Koneksi Internet")),
  151.       );
  152.     }
  153.   }
  154.  
  155.  
  156.  
  157.   Widget priceType(BuildContext context, List<PriceType> _listPriceType) {
  158.     return Container(
  159.       margin: EdgeInsets.only(bottom: 15),
  160.       child: Column(
  161.         mainAxisAlignment: MainAxisAlignment.start,
  162.         crossAxisAlignment: CrossAxisAlignment.start,
  163.         children: [
  164.           Container(
  165.             margin: EdgeInsets.only(bottom: 5),
  166.             child: Text(
  167.               "Harga yang ditawarkan",
  168.               style: TextStyle(fontSize: 15.0, color: HexColor("#49516D")),
  169.             ),
  170.           ),
  171.           Wrap(
  172.             children: _buildTypePrice(_listPriceType), // Build item
  173.           )
  174.         ],
  175.       ),
  176.     );
  177.   }
  178.  
  179.   _buildTypePrice(List<PriceType> _listPriceType) {
  180.     List<Widget> choices = List();
  181.     _listPriceType.forEach((item) {
  182.       choices.add(Container(
  183.         padding: EdgeInsets.symmetric(horizontal: 5),
  184.         child: ChoiceChip(
  185.           label: Text(item.type),
  186.           selected: _priceTypeSelected == item,
  187.           onSelected: (selected) {
  188.             setState(() {
  189.               _priceTypeSelected = item;
  190.             });
  191.           },
  192.         ),
  193.       ));
  194.     });
  195.     return choices;
  196.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement