generated from dellevin/template
优化漫步界面
This commit is contained in:
@@ -27,6 +27,7 @@ class _MainContentPageState extends State<MainContentPage> {
|
||||
|
||||
late PageController _pageController;
|
||||
bool _isTabTap = false;
|
||||
bool _syncScheduled = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -310,6 +311,19 @@ class _MainContentPageState extends State<MainContentPage> {
|
||||
final tabs = _enabledTabs;
|
||||
final safeIndex = _mapToEnabledTabIndex(provider.mainTabIndex).clamp(0, tabs.length - 1);
|
||||
|
||||
// 从其他页面返回时,修正 PageView 页面与 tab 的一致性
|
||||
if (!_syncScheduled) {
|
||||
_syncScheduled = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_syncScheduled = false;
|
||||
if (!mounted || !_pageController.hasClients) return;
|
||||
final currentPage = _pageController.page?.round() ?? 0;
|
||||
if (currentPage != safeIndex) {
|
||||
_pageController.jumpToPage(safeIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (_isTabTap && _pageController.hasClients) {
|
||||
_pageController.animateToPage(safeIndex, duration: const Duration(milliseconds: 350), curve: Curves.easeInOut);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user