feat: bugfix

This commit is contained in:
2025-12-01 06:54:18 -08:00
parent 1b1b38aba5
commit 86687cac58
22 changed files with 827 additions and 493 deletions
+34 -25
View File
@@ -9,12 +9,16 @@ class HiFixedScrollbar extends StatefulWidget {
/// 距离右边的间距(默认 18
final double right;
/// 滚动条宽度
final double thickness;
/// 滚动条颜色(默认白色 30%)
final Color thumbColor;
/// 背景轨道颜色(默认白色 15%)
final Color trackColor;
/// 滚动条固定高度(默认 50
final double thumbHeight;
@@ -36,6 +40,7 @@ class HiFixedScrollbar extends StatefulWidget {
class _HiFixedScrollbarState extends State<HiFixedScrollbar> {
double _thumbOffset = 0.0;
bool _hasScrolled = false;
@override
void initState() {
@@ -58,6 +63,7 @@ class _HiFixedScrollbarState extends State<HiFixedScrollbar> {
setState(() {
_thumbOffset = (trackHeight * scrollRatio).clamp(0, trackHeight);
_hasScrolled = offset > 0;
});
}
@@ -71,41 +77,44 @@ class _HiFixedScrollbarState extends State<HiFixedScrollbar> {
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (_, constraints) {
final showScrollbar = widget.isShowScrollbar &&
widget.controller.hasClients &&
widget.controller.position.maxScrollExtent > 0 &&
_hasScrolled;
return Stack(
children: [
// 滚动内容
widget.child,
if(widget.isShowScrollbar)
...[
// 滚动条轨道
Positioned(
right: widget.right.w,
top: 0,
bottom: 0,
child: Container(
width: widget.thickness.w,
decoration: BoxDecoration(
color: widget.trackColor,
borderRadius: BorderRadius.circular(4),
),
if (showScrollbar) ...[
// 滚动条轨道
Positioned(
right: widget.right.w,
top: 0,
bottom: 0,
child: Container(
width: widget.thickness.w,
decoration: BoxDecoration(
color: widget.trackColor,
borderRadius: BorderRadius.circular(4),
),
),
),
// 滚动条拇指
Positioned(
right: widget.right.w,
top: _thumbOffset,
child: Container(
width: widget.thickness.w,
height: widget.thumbHeight,
decoration: BoxDecoration(
color: widget.thumbColor,
borderRadius: BorderRadius.circular(4),
),
// 滚动条拇指
Positioned(
right: widget.right.w,
top: _thumbOffset,
child: Container(
width: widget.thickness.w,
height: widget.thumbHeight,
decoration: BoxDecoration(
color: widget.thumbColor,
borderRadius: BorderRadius.circular(4),
),
),
]
),
]
],
);
},