|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import 'dart:convert' as convert;
- import 'dart:ui';
-
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:zhiying_comm/zhiying_comm.dart';
-
- class MineNavDelegate extends SliverPersistentHeaderDelegate {
- final Map<String, dynamic> data;
- double _height;
- Color _color;
-
- List<Widget> _icons = List();
- double marginTop;
- double marginLeftRight;
-
- MineNavDelegate(this.data) : super() {
- _height = MediaQueryData.fromWindow(window).padding.top + 44;
- String d = data['data'];
- Map<String, dynamic> json = convert.jsonDecode(d);
- if (json.containsKey('app_bar_bg_color')) {
- _color = HexColor.fromHex(json['app_bar_bg_color']);
- } else {
- _color = Colors.amber;
- }
- if (json.containsKey('list_style')) {
- List icons = json['list_style'];
- _icons = icons.map((icon) {
- SkipModel model = SkipModel.fromJson(Map<String, dynamic>.from(icon));
- return MineNavIcon(icon['icon'], model);
- }).toList();
- }
- marginTop = 0;
- if (json.containsKey("is_top_margin") && json.containsKey("top_margin")) {
- marginTop = json['is_top_margin'] == "1" ? double.parse(json['top_margin']) : 0;
- }
- marginLeftRight = 0;
- if (json.containsKey("is_left_right_margin") && json.containsKey("left_right_margin")) {
- marginLeftRight = json['is_left_right_margin'] == "1" ? double.parse(json['left_right_margin']) : 0;
- }
- }
-
- @override
- Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
- double percent = shrinkOffset / _height;
- return MineNav(_color.withOpacity(percent), _icons, marginTop, marginLeftRight);
- }
-
- @override
- double get maxExtent => _height;
-
- @override
- double get minExtent => _height;
-
- @override
- bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => false; // 如果内容需要更新,设置为true
- }
-
- class MineNav extends StatelessWidget {
- final Color color;
- final List<Widget> widgets;
- double marginLeftRight;
- double marginTop;
-
- MineNav(this.color, this.widgets, this.marginTop, this.marginLeftRight);
-
- @override
- Widget build(BuildContext context) {
- return Container(
- margin: EdgeInsets.only(top: marginTop, left: marginLeftRight, right: marginLeftRight),
- padding: EdgeInsets.only(left: 12, right: 12),
- color: color,
- child: Column(
- children: <Widget>[
- Expanded(child: Container()),
- Container(
- width: double.infinity,
- height: 44,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: this.widgets,
- ),
- )
- ],
- ));
- }
- }
-
- class MineNavIcon extends StatelessWidget {
- final String imgUrl;
- final SkipModel skipModel;
-
- const MineNavIcon(this.imgUrl, this.skipModel, {Key key}) : super(key: key);
-
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- child: Container(
- width: 24,
- height: 24,
- margin: EdgeInsets.only(left: 6),
- child: CachedNetworkImage(
- imageUrl: imgUrl,
- ),
- ),
- onTap: () {
- RouterUtil.route(skipModel, skipModel.toJson(), context);
- });
- }
- }
|