Advertisement
FahimHoque

new

Dec 24th, 2021
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.04 KB | None | 0 0
  1.   List<String> categories = [
  2.     'All',
  3.     'Food',
  4.     'Drink',
  5.     'Clothes',
  6.     'Electronics',
  7.     'Others'
  8.   ];
  9.   @override
  10.   Widget build(BuildContext context) {
  11.     return SafeArea(
  12.       child: Scaffold(
  13.         backgroundColor: CustomColors.white,
  14.         body: DefaultTabController(
  15.           length: categories.length,
  16.           child: NestedScrollView(
  17.             controller: _scrollController,
  18.             headerSliverBuilder:
  19.                 (BuildContext context, bool innerBoxIsScrolled) {
  20.               _tabController.addListener(() {
  21.                 if (!_tabController.indexIsChanging) {
  22.                   int index = _tabController.index;
  23.                   print('this is the index: $index');
  24.                   setState(() {});
  25.                   // Your code goes here.
  26.                   // To get index of current tab use tabController.index
  27.                 }
  28.               });
  29.               return [
  30.                 MerchantSliverAppbar(merchant: widget.merchant!),
  31.                 SliverPersistentHeader(
  32.                   pinned: true,
  33.                   delegate: SliverAppBarDelegate(
  34.                     TabBar(
  35.                       labelColor: Colors.white,
  36.                       indicatorColor: Colors.transparent,
  37.                       isScrollable: true,
  38.                       padding: const EdgeInsets.all(3),
  39.                       tabs: categories
  40.                           .map(
  41.                             (category) => Tab(
  42.                               icon: Container(
  43.                                 width: MediaQuery.of(context).size.width * 0.3,
  44.                                 height:
  45.                                     MediaQuery.of(context).size.height * 0.06,
  46.                                 decoration: _tabController.index ==
  47.                                         categories.indexOf(category)
  48.                                     ? BoxDecoration(
  49.                                         color: Colors.white,
  50.                                         borderRadius: BorderRadius.circular(10),
  51.                                         boxShadow: const [
  52.                                           BoxShadow(
  53.                                             color: Colors.black12,
  54.                                             blurRadius: 10,
  55.                                             // offset: Offset(3, 6),
  56.                                           )
  57.                                         ],
  58.                                       )
  59.                                     : const BoxDecoration(),
  60.                                 child: Row(
  61.                                   mainAxisAlignment: MainAxisAlignment.center,
  62.                                   children: const [
  63.                                     Icon(
  64.                                       Icons.ac_unit,
  65.                                       color: Colors.black54,
  66.                                     ),
  67.                                     Text(
  68.                                       'category',
  69.                                       style: TextStyle(
  70.                                         color: Colors.black54,
  71.                                         fontSize: 18,
  72.                                       ),
  73.                                     )
  74.                                   ],
  75.                                 ),
  76.                               ),
  77.                             ),
  78.                           )
  79.                           .toList(),
  80.                       controller: _tabController,
  81.                     ),
  82.                   ),
  83.                 ),
  84.               ];
  85.             },
  86.             body: TabBarView(
  87.               controller: _tabController,
  88.               children: [
  89.                 _buildProductFeed(),
  90.                 _buildProductFeed(),
  91.                 _buildProductFeed(),
  92.                 _buildProductFeed(),
  93.                 _buildProductFeed(),
  94.                 _buildProductFeed(),
  95.               ],
  96.             ),
  97.           ),
  98.         ),
  99.         floatingActionButton: ChatButton(),
  100.       ),
  101.     );
  102.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement