Untitled

mail@pastecode.io avatar
unknown
dart
4 years ago
4.9 kB
17
Indexable
Never
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

class TripDetailHeader implements SliverPersistentHeaderDelegate {
//  NetworkingPageHeader({
//    this.minExtent,
//    @required this.maxExtent,
//  });
//  final double minExtent;
//  final double maxExtent;
  TripDetailHeader();

  @override
  double get maxExtent => 300.0;

  @override
  double get minExtent => 100.0;

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return Stack(
      fit: StackFit.expand,
      children: [
        Image.asset(
          'assets/login-background.jpg',
          fit: BoxFit.cover,
          color: Colors.black.withOpacity(titleDarkOpacity(shrinkOffset)),
          colorBlendMode: BlendMode.srcOver,
        ),
        Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [Colors.transparent, Colors.black54],
              stops: [0.5, 1.0],
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              tileMode: TileMode.repeated,
            ),
          ),
        ),
        Positioned(
          left: 0.0,
          top: 0.0,
          child: SafeArea(
            top: true,
            child: InkWell(
              splashColor: Colors.white,
              onTap: () => {},
              child: Container(
                padding: EdgeInsets.all(14.0),
                child: Icon(
                  Icons.arrow_back,
                  color: Colors.white,
                ),
              ),
            ),
          ),
        ),
        Positioned(
          left: titleIndent(shrinkOffset),
          right: 16.0,
          bottom: titleBottom(shrinkOffset),
          child: Text(
            'Lorem ipsum dolor sit amet panjang banget',
            overflow: TextOverflow.fade,
            softWrap: false,
            style: TextStyle(
              fontSize: titleFontSize(shrinkOffset),
              fontWeight: FontWeight.bold,
              fontFamily: "Baloo 2",
              color: Colors.white
            ),
          ),
        ),
        Positioned(
          bottom: 0.0,
          left: 0.0,
          right: 0.0,
          child: ClipRRect(
            borderRadius: BorderRadius.vertical(top: Radius.circular(10.0)),
            child: Container(
              color: Colors.white,
              padding: EdgeInsets.all(5.0),
              height: 16.0,
              child: Align(
                alignment: Alignment.center,
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(10.0)),
                  child: Container(
                    color: Colors.grey.shade300,
                    width: 100.0,
                  ),
                ),
              )
            ),
          )
        )
      ],
    );
  }

  double titleIndent(double shrinkOffset) {
    double middleExtent = minExtent + ((maxExtent - minExtent) / 2);
    double extent = maxExtent - shrinkOffset;
    extent = max(minExtent, extent);
    extent = min(middleExtent, extent);
    double factor = 1.0 - ((extent - minExtent) / (middleExtent - minExtent));
    return 16.0 + factor * 32.0;
  }
  
  double titleBottom(double shrinkOffset) {
    double middleExtent = minExtent + ((maxExtent - minExtent) / 2);
    double extent = maxExtent - shrinkOffset;
    extent = max(minExtent, extent);
    extent = min(middleExtent, extent);
    double factor = 1.0 - ((extent - minExtent) / (middleExtent - minExtent));
    return 22.0 + factor * 8.0;
  }

  double titleFontSize(double shrinkOffset) {
    double middleExtent = minExtent + ((maxExtent - minExtent) / 2);
    double extent = maxExtent - shrinkOffset;
    extent = max(minExtent, extent);
    extent = min(middleExtent, extent);
    double factor = ((extent - minExtent) / (middleExtent - minExtent));
    return 24.0 + factor * 4.0;
  }

  double titleDarkOpacity(double shrinkOffset) {
    double middleExtent = minExtent + ((maxExtent - minExtent) / 2);
    double extent = maxExtent - shrinkOffset;
    extent = max(minExtent, extent);
    extent = min(middleExtent, extent);
    double factor = 1.0 - ((extent - minExtent) / (middleExtent - minExtent));
    return factor * 0.5;
  }

  double titleOpacity(double shrinkOffset) {
    double middleExtent = minExtent + ((maxExtent - minExtent) / 2);
    double extent = maxExtent - shrinkOffset;
    extent = max(minExtent, extent);
    extent = min(middleExtent, extent);
    return (extent - minExtent) / (middleExtent - minExtent);
  }

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
    return true;
  }

  @override
  // TODO: implement stretchConfiguration
  OverScrollHeaderStretchConfiguration get stretchConfiguration => null;

  @override
  FloatingHeaderSnapConfiguration get snapConfiguration => null;
}