Advertisement
FahimHoque

MerchantSliverAppbar

Dec 22nd, 2021
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.12 KB | None | 0 0
  1. import 'package:app/router.dart';
  2. import 'package:app/src/components/buttons/about_merchant_button.dart';
  3. import 'package:app/src/components/buttons/back_button.dart';
  4. import 'package:app/src/components/buttons/follow_button.dart';
  5. import 'package:app/src/components/buttons/search_button.dart';
  6. import 'package:app/src/components/cards/merchant_thumbnail_card.dart';
  7. import 'package:app/src/components/icons/follower_count_icon.dart';
  8. import 'package:app/src/constants/custom_colors.dart';
  9. import 'package:app/src/models/merchant_model.dart';
  10. import 'package:flutter/material.dart';
  11.  
  12. class MerchantSliverAppbar extends StatefulWidget {
  13.   final Merchant merchant;
  14.   const MerchantSliverAppbar({
  15.     Key? key,
  16.     required this.merchant,
  17.   }) : super(key: key);
  18.  
  19.   @override
  20.   _MerchantSliverAppbarState createState() => _MerchantSliverAppbarState();
  21. }
  22.  
  23. class _MerchantSliverAppbarState extends State<MerchantSliverAppbar> {
  24.   @override
  25.   Widget build(BuildContext context) {
  26.     final size = MediaQuery.of(context).size;
  27.     // final maxHeightAppbar = 80;
  28.     return SliverAppBar(
  29.       expandedHeight: 200.0,
  30.       pinned: true,
  31.       floating: false,
  32.       snap: false,
  33.       backgroundColor: CustomColors.white,
  34.       leading: CustomBackButton(greyBackground: false),
  35.       flexibleSpace: merchantExpandedView(size),
  36.       actions: [
  37.         CustomSearchButton(
  38.           greyBackground: false,
  39.           onPressed: () {
  40.             openSearchPage(context);
  41.           },
  42.         ),
  43.       ],
  44.     );
  45.   }
  46.  
  47.   Widget merchantExpandedView(size) {
  48.     return Container(
  49.       child: LayoutBuilder(
  50.         builder: (BuildContext context, BoxConstraints constraints) {
  51.           double scrollPosition = constraints.biggest.height;
  52.           return FlexibleSpaceBar(
  53.             centerTitle: true,
  54.             title: scrollPosition < 80
  55.                 ? buildTitle(scrollPosition, CustomColors.primary)
  56.                 : null,
  57.             background: Stack(
  58.               children: <Widget>[
  59.                 _buildBackgroundImage(),
  60.                 Positioned(
  61.                   bottom: 30.0,
  62.                   left: 15.0,
  63.                   child: _buildMerchantInfo(scrollPosition),
  64.                 ),
  65.               ],
  66.             ),
  67.           );
  68.         },
  69.       ),
  70.     );
  71.   }
  72.  
  73.   Widget _buildBackgroundImage() {
  74.     return ClipRRect(
  75.       borderRadius: BorderRadius.only(
  76.         bottomLeft: Radius.circular(20),
  77.         bottomRight: Radius.circular(20),
  78.       ),
  79.       child: Container(
  80.         decoration: BoxDecoration(
  81.           borderRadius: BorderRadius.only(
  82.             bottomRight: Radius.circular(20.0),
  83.             bottomLeft: Radius.circular(20.0),
  84.           ),
  85.           image: DecorationImage(
  86.             image: AssetImage('assets/images/mock_background.png'),
  87.             fit: BoxFit.cover,
  88.           ),
  89.         ),
  90.       ),
  91.     );
  92.   }
  93.  
  94.   Widget _buildMerchantInfo(double scrollPosition) {
  95.     return Container(
  96.       padding: EdgeInsets.all(20),
  97.       child: Column(
  98.         crossAxisAlignment: CrossAxisAlignment.start,
  99.         children: [
  100.           Row(
  101.             crossAxisAlignment: CrossAxisAlignment.start,
  102.             children: <Widget>[
  103.               MerchantThumbnailCard(
  104.                 imageUrl: "assets/images/aarong_logo_small.png",
  105.               ),
  106.               SizedBox(width: 15),
  107.               Column(
  108.                 crossAxisAlignment: CrossAxisAlignment.start,
  109.                 children: [
  110.                   Row(
  111.                     children: [
  112.                       buildTitle(scrollPosition, CustomColors.white),
  113.                       SizedBox(width: 40),
  114.                       _buildRadting(),
  115.                     ],
  116.                   ),
  117.                   SizedBox(
  118.                     height: 15,
  119.                   ),
  120.                   _buildButtonRow(),
  121.                 ],
  122.               ),
  123.             ],
  124.           ),
  125.         ],
  126.       ),
  127.     );
  128.   }
  129.  
  130.   Widget buildTitle(double scrollPosition, Color color) {
  131.     return Text(
  132.       widget.merchant.merchantName!.toUpperCase(),
  133.       maxLines: 1,
  134.       style: TextStyle(
  135.         color: color,
  136.         fontSize: 20.0,
  137.         fontWeight: FontWeight.w500,
  138.       ),
  139.     );
  140.   }
  141.  
  142.   Widget _buildRadting() {
  143.     return Container(
  144.       child: Row(
  145.         children: [
  146.           Icon(
  147.             Icons.star,
  148.             color: Colors.amber,
  149.             size: 18,
  150.           ),
  151.           Text(
  152.             "4.5",
  153.             style: TextStyle(
  154.               color: CustomColors.primary,
  155.               fontSize: 18,
  156.             ),
  157.           ),
  158.         ],
  159.       ),
  160.     );
  161.   }
  162.  
  163.   Widget _buildButtonRow() {
  164.     return Row(
  165.       children: [
  166.         FollowButton(
  167.           isFollowing: false,
  168.           blackBackground: false,
  169.           onPressed: () {},
  170.         ),
  171.         SizedBox(width: 20),
  172.         FollowerCountIcon(
  173.           followerCount: widget.merchant.merchantFollowers!.toInt(),
  174.         ),
  175.         SizedBox(width: 20),
  176.         AboutMerchantButton(
  177.           onPressed: () {
  178.             openMerchantProfilePage(context);
  179.           },
  180.         ),
  181.       ],
  182.     );
  183.   }
  184. }
  185.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement