Advertisement
rifki_cs29

SortingPage

Mar 9th, 2022
1,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.62 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_product_list/category_product_list_bloc.dart';
  5. import 'package:module_core/utils/app_colors.dart';
  6.  
  7. class CategorySortingPage extends StatefulWidget {
  8.   final String? slug;
  9.   const CategorySortingPage(this.slug);
  10.  
  11.   @override
  12.   State<CategorySortingPage> createState() => _CategorySortingPageState();
  13. }
  14.  
  15. class _CategorySortingPageState extends State<CategorySortingPage>
  16.     with AutomaticKeepAliveClientMixin {
  17.   int _isSelected = 0;
  18.  
  19.   @override
  20.   // ignore: must_call_super
  21.   Widget build(BuildContext context) {
  22.     List<Map<String, dynamic>> _value = [
  23.       {
  24.         'name': 'Paling Sesuai',
  25.         'value': '',
  26.       },
  27.       {
  28.         'name': 'Terbaru',
  29.         'value': 'newest',
  30.       },
  31.       {
  32.         'name': 'Terlaris',
  33.         'value': 'review',
  34.       },
  35.       {
  36.         'name': 'Termurah',
  37.         'value': 'min_price',
  38.       },
  39.       {
  40.         'name': 'Termahal',
  41.         'value': 'max_price',
  42.       },
  43.       {
  44.         'name': 'Dilihat Terbanyak',
  45.         'value': 'view',
  46.       },
  47.     ];
  48.  
  49.     return Container(
  50.       height: 475,
  51.       decoration: BoxDecoration(
  52.         color: Colors.white,
  53.         borderRadius: BorderRadius.only(
  54.           topLeft: Radius.circular(20),
  55.           topRight: Radius.circular(20),
  56.         ),
  57.       ),
  58.       child: SingleChildScrollView(
  59.         child: Column(
  60.           mainAxisSize: MainAxisSize.min,
  61.           children: [
  62.             Stack(
  63.               alignment: Alignment.center,
  64.               children: [
  65.                 Container(
  66.                   height: 4,
  67.                   width: 150,
  68.                   decoration: BoxDecoration(
  69.                     color: Colors.grey[400],
  70.                     borderRadius: BorderRadius.circular(4),
  71.                   ),
  72.                 ),
  73.                 Padding(
  74.                   padding: const EdgeInsets.only(right: 8.0, top: 8),
  75.                   child: Row(
  76.                     mainAxisAlignment: MainAxisAlignment.end,
  77.                     children: [
  78.                       GestureDetector(
  79.                         onTap: () {
  80.                           Navigator.pop(context);
  81.                         },
  82.                         child: Icon(
  83.                           Icons.close,
  84.                           color: Color(0xffAEAFB2),
  85.                           size: 24,
  86.                         ),
  87.                       ),
  88.                     ],
  89.                   ),
  90.                 ),
  91.               ],
  92.             ),
  93.             SizedBox(height: 16),
  94.             Text(
  95.               'Urutkan',
  96.               textAlign: TextAlign.center,
  97.               style: GoogleFonts.poppins(
  98.                 fontSize: 16,
  99.                 fontWeight: FontWeight.w600,
  100.               ),
  101.             ),
  102.             Container(
  103.               margin: EdgeInsets.only(top: 16, bottom: 8),
  104.               height: 1,
  105.               width: MediaQuery.of(context).size.width,
  106.               color: Color(0xffC4C4C4),
  107.             ),
  108.             Container(
  109.               margin: EdgeInsets.symmetric(horizontal: 20, vertical: 4),
  110.               height: 325,
  111.               child: ListView.builder(
  112.                 itemCount: _value.length,
  113.                 itemBuilder: (context, index) {
  114.                   return ElevatedButton(
  115.                     style: ElevatedButton.styleFrom(
  116.                       primary: _isSelected == index
  117.                           ? AppColors.orangeLight
  118.                           : Colors.white,
  119.                       onPrimary: AppColors.orangeLight,
  120.                       elevation: 0,
  121.                       shape: RoundedRectangleBorder(
  122.                         borderRadius: new BorderRadius.circular(30.0),
  123.                       ),
  124.                     ),
  125.                     onPressed: () => {
  126.                       if (index == 0)
  127.                         {
  128.                           Navigator.pop(context),
  129.                         }
  130.                       else
  131.                         {
  132.                           setState(() {
  133.                             _isSelected = index;
  134.                           }),
  135.                           context.read<CategoryProductListBloc>().add(
  136.                                 FetchCategoryProductListSorting(
  137.                                   widget.slug ?? 'slug-category',
  138.                                   _value[index]['value'],
  139.                                 ),
  140.                               ),
  141.                           Navigator.pop(context)
  142.                         }
  143.                     },
  144.                     child: Padding(
  145.                       padding: const EdgeInsets.fromLTRB(0.0, 8.0, 0.0, 8.0),
  146.                       child: Row(
  147.                         mainAxisAlignment: MainAxisAlignment.start,
  148.                         children: [
  149.                           Text(
  150.                             _value[index]['name'],
  151.                             textAlign: TextAlign.start,
  152.                             style: GoogleFonts.roboto(
  153.                                 color: const Color(0xFF2D2F2E),
  154.                                 fontWeight: FontWeight.w400,
  155.                                 fontSize: 14),
  156.                           ),
  157.                         ],
  158.                       ),
  159.                     ),
  160.                   );
  161.                 },
  162.               ),
  163.             )
  164.           ],
  165.         ),
  166.       ),
  167.     );
  168.   }
  169.  
  170.   @override
  171.   bool get wantKeepAlive => true;
  172.  
  173.   @override
  174.   void dispose() {
  175.     super.dispose();
  176.   }
  177. }
  178.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement