import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/pages/mine_page/mine_page.dart';

class NormalNavDelegate extends SliverPersistentHeaderDelegate {
  double _height;

  NormalNavDelegate() : super() {
    _height = MediaQueryData.fromWindow(window).padding.top + 44;
  }

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    print('${shrinkOffset.toString()}');
    double percent = shrinkOffset / _height;
    print('${percent.toString()}');
    return NormalNav(Colors.red.withOpacity(percent));
  }

  @override
  double get maxExtent => _height;

  @override
  double get minExtent => _height;

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) =>
      false; // 如果内容需要更新，设置为true
}

class NormalNav extends StatelessWidget {
  final Color color;

  NormalNav(this.color);

  @override
  Widget build(BuildContext context) {
    return Container(
        color: color,
        child: Column(
          children: <Widget>[
            Expanded(child: Container()),
            Container(
              width: double.infinity,
              height: 44,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Navigator.of(context).canPop()
                      ? GestureDetector(
                          child: Container(
                            width: 44,
                            height: 44,
                            child: Icon(
                              Icons.arrow_back_ios,
                              color: Colors.white,
                            ),
                          ),
                          onTap: () {
                            if (Navigator.canPop(context)) {
                              Navigator.pop(context);
                            }
                          },
                        )
                      : Container(
                          width: 44,
                          height: 44,
                        ),
                  Expanded(
                    child: Container(
                      child: Center(
                        child: Text(
                          '我的钱包',
                          style: TextStyle(fontSize: 18, color: Colors.white),
                        ),
                      ),
                    ),
                  ),
                  GestureDetector(
                    child: Container(
                      width: 44,
                      height: 44,
                      child: Icon(
                        Icons.settings,
                        color: Colors.white,
                      ),
                    ),
                    onTap: () {
                      Navigator.push(context,
                          MaterialPageRoute(builder: (context) {
                        return MinePage();
                      }));
                    },
                  ),
                ],
              ),
            )
          ],
        ));
  }
}
