TF-4075 Use Scrollable.ensureVisible replace for animateTo

(cherry picked from commit aa187c17f7952a66d237abbe1f66efb2f01fd298)
This commit is contained in:
dab246
2025-10-08 18:26:10 +07:00
committed by Dat H. Pham
parent 6c7331960f
commit e31e616192
3 changed files with 7 additions and 28 deletions
@@ -1,31 +1,6 @@
import 'package:flutter/material.dart';
extension ScrollControllerExtension on ScrollController {
void scrollToWidgetTop({
required GlobalKey key,
double padding = 70,
}) {
final context = key.currentContext;
if (context == null) return;
final renderBox = context.findRenderObject();
if (renderBox is! RenderBox) return;
final offsetY = renderBox.localToGlobal(Offset.zero).dy;
final currentScroll = offset;
final targetOffset = (currentScroll + offsetY - padding).clamp(
position.minScrollExtent,
position.maxScrollExtent,
);
animateTo(
targetOffset,
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
);
}
void scrollToBottomWithPadding({required double padding}) {
try {
final maxExtent = position.maxScrollExtent;