基础组件库
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.
 
 
 
 
 

113 lines
3.3 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. double marginTop;
  13. double marginLeftRight;
  14. MineNavDelegate(this.data) : super() {
  15. _height = MediaQueryData.fromWindow(window).padding.top + 44;
  16. String d = data['data'];
  17. Map<String, dynamic> json = convert.jsonDecode(d);
  18. if (json.containsKey('app_bar_bg_color')) {
  19. _color = HexColor.fromHex(json['app_bar_bg_color']);
  20. } else {
  21. _color = Colors.amber;
  22. }
  23. if (json.containsKey('list_style')) {
  24. List icons = json['list_style'];
  25. _icons = icons.map((icon) {
  26. SkipModel model = SkipModel.fromJson(Map<String, dynamic>.from(icon));
  27. return MineNavIcon(icon['icon'], model);
  28. }).toList();
  29. }
  30. marginTop = 0;
  31. if (json.containsKey("is_top_margin") && json.containsKey("top_margin")) {
  32. marginTop = json['is_top_margin'] == "1" ? double.parse(json['top_margin']) : 0;
  33. }
  34. marginLeftRight = 0;
  35. if (json.containsKey("is_left_right_margin") && json.containsKey("left_right_margin")) {
  36. marginLeftRight = json['is_left_right_margin'] == "1" ? double.parse(json['left_right_margin']) : 0;
  37. }
  38. }
  39. @override
  40. Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
  41. double percent = shrinkOffset / _height;
  42. return MineNav(_color.withOpacity(percent), _icons, marginTop, marginLeftRight);
  43. }
  44. @override
  45. double get maxExtent => _height;
  46. @override
  47. double get minExtent => _height;
  48. @override
  49. bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => false; // 如果内容需要更新,设置为true
  50. }
  51. class MineNav extends StatelessWidget {
  52. final Color color;
  53. final List<Widget> widgets;
  54. double marginLeftRight;
  55. double marginTop;
  56. MineNav(this.color, this.widgets, this.marginTop, this.marginLeftRight);
  57. @override
  58. Widget build(BuildContext context) {
  59. return Container(
  60. margin: EdgeInsets.only(top: marginTop, left: marginLeftRight, right: marginLeftRight),
  61. padding: EdgeInsets.only(left: 12, right: 12),
  62. color: color,
  63. child: Column(
  64. children: <Widget>[
  65. Expanded(child: Container()),
  66. Container(
  67. width: double.infinity,
  68. height: 44,
  69. child: Row(
  70. mainAxisAlignment: MainAxisAlignment.end,
  71. crossAxisAlignment: CrossAxisAlignment.center,
  72. children: this.widgets,
  73. ),
  74. )
  75. ],
  76. ));
  77. }
  78. }
  79. class MineNavIcon extends StatelessWidget {
  80. final String imgUrl;
  81. final SkipModel skipModel;
  82. const MineNavIcon(this.imgUrl, this.skipModel, {Key key}) : super(key: key);
  83. @override
  84. Widget build(BuildContext context) {
  85. return GestureDetector(
  86. child: Container(
  87. width: 24,
  88. height: 24,
  89. margin: EdgeInsets.only(left: 6),
  90. child: CachedNetworkImage(
  91. imageUrl: imgUrl,
  92. ),
  93. ),
  94. onTap: () {
  95. RouterUtil.route(skipModel, skipModel.toJson(), context);
  96. });
  97. }
  98. }