TF-4075 Jump to attachments list position on web responsive mobile
This commit is contained in:
@@ -17,6 +17,7 @@ export 'presentation/extensions/tap_down_details_extension.dart';
|
||||
export 'presentation/extensions/map_extensions.dart';
|
||||
export 'presentation/extensions/either_view_state_extension.dart';
|
||||
export 'presentation/extensions/media_type_extension.dart';
|
||||
export 'presentation/extensions/scroll_controller_extension.dart';
|
||||
|
||||
// Exceptions
|
||||
export 'domain/exceptions/download_file_exception.dart';
|
||||
|
||||
@@ -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