diff --git a/lib/models/base/widget_model.dart b/lib/models/base/widget_model.dart index 6f806dc..8b12f3a 100644 --- a/lib/models/base/widget_model.dart +++ b/lib/models/base/widget_model.dart @@ -45,7 +45,7 @@ class WidgetModel { this.isGlobal}); WidgetModel.fromJson(Map json) { - modId = json['mod_id']; + modId = json['mod_id'] is int ? json['mod_id'] as int : int.parse(json['mod_id']?.toString()); modPid = json['mod_pid']; modName = json['mod_name']; position = json['position']; diff --git a/lib/util/custom_sliver_persistent_header_delegate.dart b/lib/util/custom_sliver_persistent_header_delegate.dart new file mode 100644 index 0000000..8aaebf3 --- /dev/null +++ b/lib/util/custom_sliver_persistent_header_delegate.dart @@ -0,0 +1,32 @@ +// 自定义 SliverPersistentHeaderDelegate +import 'package:flutter/material.dart'; + +class CustomSliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate { + final double max; // 最大高度 + final double min; // 最小高度 + final Widget child; // 需要展示的内容 + + CustomSliverPersistentHeaderDelegate({@required this.max, @required this.min, @required this.child}) + // 如果 assert 内部条件不成立,会报错 + : assert(max != null), + assert(min != null), + assert(child != null), + assert(min <= max), + super(); + + // 返回展示的内容,如果内容固定可以直接在这定义,如果需要可扩展,这边通过传入值来定义 + @override + Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) => child; + + @override + double get maxExtent => max; // 返回最大高度 + + @override + double get minExtent => min; // 返回最小高度 + + @override + bool shouldRebuild(CustomSliverPersistentHeaderDelegate oldDelegate) { + // 是否需要更新,这里我们定义当高度范围和展示内容被替换的时候进行刷新界面 + return max != oldDelegate.max || min != oldDelegate.min || child != oldDelegate.child; + } +} diff --git a/lib/util/shimmer_util.dart b/lib/util/shimmer_util.dart new file mode 100644 index 0000000..fe548c2 --- /dev/null +++ b/lib/util/shimmer_util.dart @@ -0,0 +1,16 @@ +import 'package:flutter/material.dart'; +import 'package:shimmer/shimmer.dart'; + +class ShimmerUtil { + static Widget getShimmerWidget({double width, double height, double radius = 0}) { + return Shimmer.fromColors( + baseColor: Colors.grey[300], + highlightColor: Colors.grey[100], + child: Container( + width: width, + height: height, + decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(radius)), + ), + ); + } +} diff --git a/lib/util/sliver_tab_bar_delegate.dart b/lib/util/sliver_tab_bar_delegate.dart new file mode 100644 index 0000000..874e76d --- /dev/null +++ b/lib/util/sliver_tab_bar_delegate.dart @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; + +class SliverTabBarDelegate extends SliverPersistentHeaderDelegate { + final TabBar widget; + + const SliverTabBarDelegate(this.widget) : assert(widget != null); + + @override + Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) { + return this.widget; + } + + @override + bool shouldRebuild(SliverTabBarDelegate oldDelegate) { + return false; + } + + @override + double get maxExtent => widget.preferredSize.height; + + @override + double get minExtent => widget.preferredSize.height; +}