|
1 | 1 | // SPDX-License-Identifier: ice License 1.0 |
2 | 2 |
|
| 3 | +import 'dart:async'; |
| 4 | + |
3 | 5 | import 'package:decimal/decimal.dart'; |
4 | 6 | import 'package:flutter/material.dart'; |
5 | 7 | import 'package:flutter/rendering.dart'; |
@@ -112,19 +114,42 @@ class TokenizedCommunityPage extends HookConsumerWidget { |
112 | 114 | final targetCtx = sectionKeys[index].currentContext; |
113 | 115 | if (targetCtx == null) return; |
114 | 116 |
|
| 117 | + double outerOffsetDy = 0; |
| 118 | + |
115 | 119 | final nestedState = targetCtx.findAncestorStateOfType<NestedScrollViewState>(); |
116 | 120 | final inner = nestedState?.innerController ?? innerScrollController.value; |
117 | 121 | if (inner == null || !inner.hasClients) return; |
118 | 122 |
|
119 | | - final ro = targetCtx.findRenderObject(); |
| 123 | + final outer = nestedState?.outerController; |
| 124 | + if (outer != null && outer.hasClients) { |
| 125 | + outerOffsetDy = outer.position.pixels; |
| 126 | + final outerTarget = outer.position.maxScrollExtent - (index == 0 ? 40 : 0); |
| 127 | + |
| 128 | + unawaited( |
| 129 | + outer.animateTo( |
| 130 | + outerTarget, |
| 131 | + duration: const Duration(milliseconds: 300), |
| 132 | + curve: Curves.easeInOut, |
| 133 | + ), |
| 134 | + ); |
| 135 | + if (index == 0) { |
| 136 | + return; |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + final updatedCtx = sectionKeys[index].currentContext; |
| 141 | + if (updatedCtx == null) return; |
| 142 | + |
| 143 | + final ro = updatedCtx.findRenderObject(); |
120 | 144 | if (ro == null) return; |
121 | 145 |
|
122 | 146 | final viewport = RenderAbstractViewport.of(ro); |
123 | 147 |
|
124 | 148 | // Align the section to the TOP of the inner viewport. |
125 | 149 | final desired = viewport.getOffsetToReveal(ro, 0).offset; |
126 | 150 | final pos = inner.position; |
127 | | - final target = (desired - 110.0).clamp(pos.minScrollExtent, pos.maxScrollExtent); |
| 151 | + final target = (desired - (outerOffsetDy == 0 ? 40 : 160)) |
| 152 | + .clamp(pos.minScrollExtent, pos.maxScrollExtent); |
128 | 153 |
|
129 | 154 | await inner.animateTo( |
130 | 155 | target, |
|
0 commit comments