Browse Source

1、添加骨架图工具类

2、添加sliver delegate工具类
tags/0.0.1
PH2 4 years ago
parent
commit
f2620ed22b
4 changed files with 72 additions and 1 deletions
  1. +1
    -1
      lib/models/base/widget_model.dart
  2. +32
    -0
      lib/util/custom_sliver_persistent_header_delegate.dart
  3. +16
    -0
      lib/util/shimmer_util.dart
  4. +23
    -0
      lib/util/sliver_tab_bar_delegate.dart

+ 1
- 1
lib/models/base/widget_model.dart View File

@@ -45,7 +45,7 @@ class WidgetModel {
this.isGlobal}); this.isGlobal});


WidgetModel.fromJson(Map<String, dynamic> json) { WidgetModel.fromJson(Map<String, dynamic> 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']; modPid = json['mod_pid'];
modName = json['mod_name']; modName = json['mod_name'];
position = json['position']; position = json['position'];


+ 32
- 0
lib/util/custom_sliver_persistent_header_delegate.dart View File

@@ -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;
}
}

+ 16
- 0
lib/util/shimmer_util.dart View File

@@ -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)),
),
);
}
}

+ 23
- 0
lib/util/sliver_tab_bar_delegate.dart View File

@@ -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;
}

Loading…
Cancel
Save