fix(libraries): stabilize alpha and sort controls

This commit is contained in:
edde746
2026-05-17 22:36:15 +02:00
parent c855dba3be
commit 3e0f7b4f86
16 changed files with 393 additions and 112 deletions
+20 -14
View File
@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/widgets.dart';
/// Scroll the nearest scrollable ancestor so [context] is centered.
@@ -7,13 +9,15 @@ import 'package:flutter/widgets.dart';
void scrollContextToCenter(BuildContext? context) {
if (context == null) return;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!context.mounted) return;
Scrollable.ensureVisible(
context,
alignment: 0.5,
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
);
Timer.run(() {
if (!context.mounted) return;
Scrollable.ensureVisible(
context,
alignment: 0.5,
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
);
});
});
}
@@ -25,13 +29,15 @@ void scrollContextToCenter(BuildContext? context) {
/// controller aren't ready yet.
void scrollToCurrentItem(ScrollController controller, GlobalKey firstItemKey, int currentIndex) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!controller.hasClients) return;
final itemHeight = (firstItemKey.currentContext?.findRenderObject() as RenderBox?)?.size.height;
if (itemHeight == null) return;
final maxExtent = controller.position.maxScrollExtent;
if (!maxExtent.isFinite) return;
final target = (currentIndex * itemHeight).clamp(0.0, maxExtent);
controller.jumpTo(target);
Timer.run(() {
if (!controller.hasClients) return;
final itemHeight = (firstItemKey.currentContext?.findRenderObject() as RenderBox?)?.size.height;
if (itemHeight == null) return;
final maxExtent = controller.position.maxScrollExtent;
if (!maxExtent.isFinite) return;
final target = (currentIndex * itemHeight).clamp(0.0, maxExtent);
controller.jumpTo(target);
});
});
}