基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

91 lines
2.4 KiB

  1. import 'dart:convert' as convert;
  2. import 'dart:ui';
  3. import 'package:cached_network_image/cached_network_image.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:zhiying_comm/zhiying_comm.dart';
  7. class MineNavDelegate extends SliverPersistentHeaderDelegate {
  8. final Map<String, dynamic> data;
  9. double _height;
  10. Color _color;
  11. List<Widget> _icons = List();
  12. MineNavDelegate(this.data) : super() {
  13. _height = MediaQueryData.fromWindow(window).padding.top + 44;
  14. String d = data['data'];
  15. Map<String, dynamic> json = convert.jsonDecode(d);
  16. if (json.containsKey('app_bar_bg_color')) {
  17. _color = HexColor.fromHex(json['app_bar_bg_color']);
  18. } else {
  19. _color = Colors.amber;
  20. }
  21. if (json.containsKey('app_bar_icons')) {
  22. List icons = json['app_bar_icons'];
  23. _icons = icons.map((icon) {
  24. SkipModel model = SkipModel.fromJson(Map<String, dynamic>.from(icon));
  25. return GestureDetector(
  26. child: Container(
  27. width: 24,
  28. height: 24,
  29. margin: EdgeInsets.only(left: 6),
  30. child: CachedNetworkImage(
  31. imageUrl: model.icon,
  32. ),
  33. ),
  34. onTap: () {
  35. print('页面跳转 ${model.skipIdentifier}');
  36. },
  37. );
  38. }).toList();
  39. }
  40. }
  41. @override
  42. Widget build(
  43. BuildContext context, double shrinkOffset, bool overlapsContent) {
  44. double percent = shrinkOffset / _height;
  45. return MineNav(_color.withOpacity(percent), _icons);
  46. }
  47. @override
  48. double get maxExtent => _height;
  49. @override
  50. double get minExtent => _height;
  51. @override
  52. bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) =>
  53. false; // 如果内容需要更新,设置为true
  54. }
  55. class MineNav extends StatelessWidget {
  56. final Color color;
  57. final List<Widget> widgets;
  58. MineNav(this.color, this.widgets);
  59. @override
  60. Widget build(BuildContext context) {
  61. return Container(
  62. padding: EdgeInsets.only(left: 12, right: 12),
  63. color: color,
  64. child: Column(
  65. children: <Widget>[
  66. Expanded(child: Container()),
  67. Container(
  68. width: double.infinity,
  69. height: 44,
  70. child: Row(
  71. mainAxisAlignment: MainAxisAlignment.end,
  72. crossAxisAlignment: CrossAxisAlignment.center,
  73. children: this.widgets,
  74. ),
  75. )
  76. ],
  77. ));
  78. }
  79. }