TF-4075 Jump to attachments list position on web responsive mobile
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user