Aleksei
Committed by David PHAM-VAN

Update `scrollToPage`

@@ -174,16 +174,17 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> @@ -174,16 +174,17 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom>
174 super.didChangeDependencies(); 174 super.didChangeDependencies();
175 } 175 }
176 176
177 - void scrollToPage( 177 + Future<void> scrollToPage(
178 int index, { 178 int index, {
179 - Duration duration = Duration.zero, 179 + Duration duration = const Duration(milliseconds: 300),
180 Curve curve = Curves.ease, 180 Curve curve = Curves.ease,
181 ScrollPositionAlignmentPolicy alignmentPolicy = 181 ScrollPositionAlignmentPolicy alignmentPolicy =
182 ScrollPositionAlignmentPolicy.explicit, 182 ScrollPositionAlignmentPolicy.explicit,
183 }) { 183 }) {
184 - assert(index >= 0);  
185 - final pageKey = _pageGlobalKeys[index];  
186 - Scrollable.ensureVisible(pageKey.currentContext!, 184 + assert(index >= 0, 'Index of page cannot be negative');
  185 + final pageContext = _pageGlobalKeys[index].currentContext;
  186 + assert(pageContext != null, 'Context of GlobalKey cannot be null');
  187 + return Scrollable.ensureVisible(pageContext!,
187 duration: duration, curve: curve, alignmentPolicy: alignmentPolicy); 188 duration: duration, curve: curve, alignmentPolicy: alignmentPolicy);
188 } 189 }
189 190