Advertisement
rifki_cs29

CategoryFilterLocationPage

Mar 8th, 2022
1,401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 7.63 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_bloc/flutter_bloc.dart';
  3. import 'package:google_fonts/google_fonts.dart';
  4. import 'package:module_category/presentation/bloc/category_filter_location_bloc/category_filter_location_bloc.dart';
  5. import 'package:module_core/common/state_enum.dart';
  6. import 'package:module_core/utils/app_colors.dart';
  7.  
  8. class CategoryFilterLocationPage extends StatefulWidget {
  9.   CategoryFilterLocationPage({Key? key}) : super(key: key);
  10.  
  11.   @override
  12.   State<CategoryFilterLocationPage> createState() =>
  13.       _CategoryFilterLocationPageState();
  14. }
  15.  
  16. class _CategoryFilterLocationPageState
  17.     extends State<CategoryFilterLocationPage> {
  18.   var _fieldController = TextEditingController();
  19.  
  20.   @override
  21.   void initState() {
  22.     Future.microtask(
  23.       () => BlocProvider.of<CategoryFilterLocationBloc>(context, listen: false)
  24.           .add(
  25.         OnClickFilterLocationDefault(),
  26.       ),
  27.     );
  28.     super.initState();
  29.   }
  30.  
  31.   @override
  32.   Widget build(BuildContext context) {
  33.     return Container(
  34.       height: 475,
  35.       child: SingleChildScrollView(
  36.         child: Column(
  37.           mainAxisSize: MainAxisSize.min,
  38.           children: [
  39.             Stack(
  40.               alignment: Alignment.center,
  41.               children: [
  42.                 Container(
  43.                   height: 4,
  44.                   width: 150,
  45.                   decoration: BoxDecoration(
  46.                     color: Colors.grey[400],
  47.                     borderRadius: BorderRadius.circular(4),
  48.                   ),
  49.                 ),
  50.                 Padding(
  51.                   padding: const EdgeInsets.only(right: 8.0, top: 8),
  52.                   child: Row(
  53.                     mainAxisAlignment: MainAxisAlignment.end,
  54.                     children: [
  55.                       GestureDetector(
  56.                         onTap: () {
  57.                           Navigator.pop(context);
  58.                         },
  59.                         child: Icon(
  60.                           Icons.close,
  61.                           color: Color(0xffAEAFB2),
  62.                           size: 24,
  63.                         ),
  64.                       ),
  65.                     ],
  66.                   ),
  67.                 ),
  68.               ],
  69.             ),
  70.             SizedBox(height: 16),
  71.             Text(
  72.               'Lokasi',
  73.               textAlign: TextAlign.center,
  74.               style: GoogleFonts.poppins(
  75.                 fontSize: 16,
  76.                 fontWeight: FontWeight.w600,
  77.               ),
  78.             ),
  79.             Container(
  80.               margin: EdgeInsets.symmetric(vertical: 16),
  81.               height: 1,
  82.               width: MediaQuery.of(context).size.width,
  83.               color: Color(0xffC4C4C4),
  84.             ),
  85.             Padding(
  86.               padding:
  87.                   const EdgeInsets.symmetric(horizontal: 20.0, vertical: 8.0),
  88.               child: TextField(
  89.                 onChanged: (query) {
  90.                   if (query.isEmpty || query == '') {
  91.                     context
  92.                         .read<CategoryFilterLocationBloc>()
  93.                         .add(OnClickFilterLocationDefault());
  94.                   } else {
  95.                     context
  96.                         .read<CategoryFilterLocationBloc>()
  97.                         .add(OnChangeFilterLocationSearch(query));
  98.                   }
  99.                 },
  100.                 controller: _fieldController,
  101.                 decoration: InputDecoration(
  102.                     filled: true,
  103.                     fillColor: Color(0xffC6E4EC).withOpacity(0.5),
  104.                     hintText: 'Cari Lokasi...',
  105.                     labelStyle: TextStyle(
  106.                       fontFamily: GoogleFonts.poppins().fontFamily,
  107.                       color: Colors.grey[400],
  108.                     ),
  109.                     prefixIcon:
  110.                         Icon(Icons.search_sharp, color: AppColors.grueMedium),
  111.                     border: OutlineInputBorder(
  112.                         borderSide: BorderSide(
  113.                             color: Color(0xffC6E4EC).withOpacity(0.5)),
  114.                         borderRadius: BorderRadius.circular(24)),
  115.                     enabledBorder: OutlineInputBorder(
  116.                         borderSide: BorderSide(
  117.                             color: Color(0xffC6E4EC).withOpacity(0.5)),
  118.                         borderRadius: BorderRadius.circular(24)),
  119.                     focusedBorder: OutlineInputBorder(
  120.                         borderSide: BorderSide(
  121.                             color: Color(0xffC6E4EC).withOpacity(0.5)),
  122.                         borderRadius: BorderRadius.circular(24)),
  123.                     contentPadding: EdgeInsets.all(12)),
  124.                 textInputAction: TextInputAction.search,
  125.               ),
  126.             ),
  127.             BlocBuilder<CategoryFilterLocationBloc,
  128.                 CategoryFilterLocationState>(builder: (context, state) {
  129.               if (state.state == RequestState.Loading) {
  130.                 return Center(
  131.                   child: CircularProgressIndicator(),
  132.                 );
  133.               } else if (state.state == RequestState.Loaded) {
  134.                 return Container(
  135.                   margin: EdgeInsets.symmetric(horizontal: 20, vertical: 14),
  136.                   height: 325,
  137.                   child: ListView.builder(
  138.                     itemCount: state.dataSearch != null
  139.                         ? state.dataSearch?.response.data.length
  140.                         : state.dataDefault?.response.data.province
  141.                             ?.asMap()
  142.                             .length,
  143.                     itemBuilder: (context, index) {
  144.                       return Container(
  145.                           margin: EdgeInsets.symmetric(vertical: 8),
  146.                           child: Column(
  147.                             children: [
  148.                               Row(
  149.                                 children: [
  150.                                   Text(
  151.                                     state.dataSearch != null
  152.                                         ? state.dataSearch?.response.data[index]
  153.                                                 .id ??
  154.                                             ''
  155.                                         : state.dataDefault?.response.data
  156.                                                 .province
  157.                                                 ?.asMap()[index]
  158.                                                 .toString() ??
  159.                                             '',
  160.                                     style: GoogleFonts.roboto(
  161.                                         fontSize: 12,
  162.                                         fontWeight: FontWeight.w400),
  163.                                   ),
  164.                                 ],
  165.                               ),
  166.                               SizedBox(height: 12),
  167.                               Container(
  168.                                 height: 1,
  169.                                 color: Color(0xffC4C4C4),
  170.                               ),
  171.                             ],
  172.                           ));
  173.                     },
  174.                   ),
  175.                 );
  176.               } else if (state.state == RequestState.Empty) {
  177.                 return Center(
  178.                   child: Text('Data Kosong'),
  179.                 );
  180.               } else if (state.state == RequestState.Error) {
  181.                 return Center(
  182.                   child: Text('Error'),
  183.                 );
  184.               } else {
  185.                 return Container();
  186.               }
  187.             })
  188.           ],
  189.         ),
  190.       ),
  191.     );
  192.   }
  193.  
  194.   @override
  195.   void dispose() {
  196.     _fieldController.dispose();
  197.     super.dispose();
  198.   }
  199. }
  200.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement