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

102 lines
2.7 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 MineNavIcon(icon['icon'], model);
  26. }).toList();
  27. }
  28. }
  29. @override
  30. Widget build(
  31. BuildContext context, double shrinkOffset, bool overlapsContent) {
  32. double percent = shrinkOffset / _height;
  33. return MineNav(_color.withOpacity(percent), _icons);
  34. }
  35. @override
  36. double get maxExtent => _height;
  37. @override
  38. double get minExtent => _height;
  39. @override
  40. bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) =>
  41. false; // 如果内容需要更新,设置为true
  42. }
  43. class MineNav extends StatelessWidget {
  44. final Color color;
  45. final List<Widget> widgets;
  46. MineNav(this.color, this.widgets);
  47. @override
  48. Widget build(BuildContext context) {
  49. return Container(
  50. padding: EdgeInsets.only(left: 12, right: 12),
  51. color: color,
  52. child: Column(
  53. children: <Widget>[
  54. Expanded(child: Container()),
  55. Container(
  56. width: double.infinity,
  57. height: 44,
  58. child: Row(
  59. mainAxisAlignment: MainAxisAlignment.end,
  60. crossAxisAlignment: CrossAxisAlignment.center,
  61. children: this.widgets,
  62. ),
  63. )
  64. ],
  65. ));
  66. }
  67. }
  68. class MineNavIcon extends StatelessWidget {
  69. final String imgUrl;
  70. final SkipModel skipModel;
  71. const MineNavIcon(this.imgUrl, this.skipModel, {Key key}) : super(key: key);
  72. @override
  73. Widget build(BuildContext context) {
  74. return GestureDetector(child: Container(
  75. width: 24,
  76. height: 24,
  77. margin: EdgeInsets.only(left: 6),
  78. child: CachedNetworkImage(
  79. imageUrl: imgUrl,
  80. ),
  81. ),
  82. onTap:() {
  83. RouterUtil.route(skipModel, skipModel.toJson(), context);
  84. });
  85. }
  86. }