Advertisement
rifki_cs29

LocationPage

Mar 8th, 2022
1,550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 6.48 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 StatelessWidget {
  9.   CategoryFilterLocationPage({Key? key}) : super(key: key);
  10.  
  11.   @override
  12.   Widget build(BuildContext context) {
  13.     Future.microtask(() =>
  14.         BlocProvider.of<CategoryFilterLocationBloc>(context, listen: false)
  15.             .add(OnClickFilterLocationDefault()));
  16.     return Container(
  17.       height: 475,
  18.       child: SingleChildScrollView(
  19.         child: Column(
  20.           mainAxisSize: MainAxisSize.min,
  21.           children: [
  22.             Stack(
  23.               alignment: Alignment.center,
  24.               children: [
  25.                 Container(
  26.                   height: 4,
  27.                   width: 150,
  28.                   decoration: BoxDecoration(
  29.                     color: Colors.grey[400],
  30.                     borderRadius: BorderRadius.circular(4),
  31.                   ),
  32.                 ),
  33.                 Padding(
  34.                   padding: const EdgeInsets.only(right: 8.0, top: 8),
  35.                   child: Row(
  36.                     mainAxisAlignment: MainAxisAlignment.end,
  37.                     children: [
  38.                       GestureDetector(
  39.                         onTap: () {
  40.                           Navigator.pop(context);
  41.                         },
  42.                         child: Icon(
  43.                           Icons.close,
  44.                           color: Color(0xffAEAFB2),
  45.                           size: 24,
  46.                         ),
  47.                       ),
  48.                     ],
  49.                   ),
  50.                 ),
  51.               ],
  52.             ),
  53.             SizedBox(height: 16),
  54.             Text(
  55.               'Lokasi',
  56.               textAlign: TextAlign.center,
  57.               style: GoogleFonts.poppins(
  58.                 fontSize: 16,
  59.                 fontWeight: FontWeight.w600,
  60.               ),
  61.             ),
  62.             Container(
  63.               margin: EdgeInsets.symmetric(vertical: 16),
  64.               height: 1,
  65.               width: MediaQuery.of(context).size.width,
  66.               color: Color(0xffC4C4C4),
  67.             ),
  68.             Padding(
  69.               padding:
  70.                   const EdgeInsets.symmetric(horizontal: 20.0, vertical: 8.0),
  71.               child: TextField(
  72.                 onChanged: (query) {
  73.                   context
  74.                       .read<CategoryFilterLocationBloc>()
  75.                       .add(OnChangeFilterLocationSearch(query));
  76.                 },
  77.                 decoration: InputDecoration(
  78.                     filled: true,
  79.                     fillColor: Color(0xffC6E4EC).withOpacity(0.5),
  80.                     hintText: 'Cari Lokasi...',
  81.                     labelStyle: TextStyle(
  82.                       fontFamily: GoogleFonts.poppins().fontFamily,
  83.                       color: Colors.grey[400],
  84.                     ),
  85.                     prefixIcon:
  86.                         Icon(Icons.search_sharp, color: AppColors.grueMedium),
  87.                     border: OutlineInputBorder(
  88.                         borderSide: BorderSide(
  89.                             color: Color(0xffC6E4EC).withOpacity(0.5)),
  90.                         borderRadius: BorderRadius.circular(24)),
  91.                     enabledBorder: OutlineInputBorder(
  92.                         borderSide: BorderSide(
  93.                             color: Color(0xffC6E4EC).withOpacity(0.5)),
  94.                         borderRadius: BorderRadius.circular(24)),
  95.                     focusedBorder: OutlineInputBorder(
  96.                         borderSide: BorderSide(
  97.                             color: Color(0xffC6E4EC).withOpacity(0.5)),
  98.                         borderRadius: BorderRadius.circular(24)),
  99.                     contentPadding: EdgeInsets.all(12)),
  100.                 textInputAction: TextInputAction.search,
  101.               ),
  102.             ),
  103.             BlocBuilder<CategoryFilterLocationBloc,
  104.                 CategoryFilterLocationState>(builder: (context, state) {
  105.               if (state.state == RequestState.Loading) {
  106.                 return Center(
  107.                   child: CircularProgressIndicator(),
  108.                 );
  109.               } else if (state.state == RequestState.Loaded) {
  110.                 return Container(
  111.                   margin: EdgeInsets.symmetric(horizontal: 20, vertical: 14),
  112.                   height: 325,
  113.                   child: ListView.builder(
  114.                     itemCount: state.dataDefault?.response.data.province
  115.                         ?.asMap()
  116.                         .length,
  117.                     itemBuilder: (context, index) {
  118.                       return Container(
  119.                           margin: EdgeInsets.symmetric(vertical: 8),
  120.                           child: Column(
  121.                             children: [
  122.                               Row(
  123.                                 children: [
  124.                                   Text(
  125.                                     state.dataDefault?.response.data.province
  126.                                             ?.asMap()[index]
  127.                                             .toString() ??
  128.                                         'Location Name',
  129.                                     style: GoogleFonts.roboto(
  130.                                         fontSize: 12,
  131.                                         fontWeight: FontWeight.w400),
  132.                                   ),
  133.                                 ],
  134.                               ),
  135.                               SizedBox(height: 12),
  136.                               Container(
  137.                                 height: 1,
  138.                                 color: Color(0xffC4C4C4),
  139.                               ),
  140.                             ],
  141.                           ));
  142.                     },
  143.                   ),
  144.                 );
  145.               } else if (state.state == RequestState.Empty) {
  146.                 return Center(
  147.                   child: Text('Data Kosong'),
  148.                 );
  149.               } else if (state.state == RequestState.Error) {
  150.                 return Center(
  151.                   child: Text('Error'),
  152.                 );
  153.               } else {
  154.                 return Container();
  155.               }
  156.             })
  157.           ],
  158.         ),
  159.       ),
  160.     );
  161.   }
  162. }
  163.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement