mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
fix pageview controller reset index
This commit is contained in:
parent
2496a6574a
commit
e0970fa182
1 changed files with 26 additions and 36 deletions
|
@ -13,7 +13,6 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:cake_wallet/router.dart' as Router;
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
class DesktopSidebarWrapper extends BasePage {
|
||||
final Widget child;
|
||||
final DesktopSidebarViewModel desktopSidebarViewModel;
|
||||
|
@ -25,6 +24,8 @@ class DesktopSidebarWrapper extends BasePage {
|
|||
required this.dashboardViewModel,
|
||||
});
|
||||
|
||||
static Key _pageViewKey = GlobalKey();
|
||||
|
||||
@override
|
||||
Color get backgroundLightColor =>
|
||||
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
|
||||
|
@ -38,23 +39,6 @@ class DesktopSidebarWrapper extends BasePage {
|
|||
final unselectedIconPath = 'assets/images/desktop_transactions_outline_icon.png';
|
||||
double get sideMenuWidth => 76.0;
|
||||
|
||||
@override
|
||||
Widget Function(BuildContext, Widget) get rootWrapper =>
|
||||
(BuildContext context, Widget scaffold) => Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Theme.of(context).accentColor,
|
||||
Theme.of(context).scaffoldBackgroundColor,
|
||||
Theme.of(context).primaryColor,
|
||||
],
|
||||
begin: Alignment.topRight,
|
||||
end: Alignment.bottomLeft,
|
||||
),
|
||||
),
|
||||
child: scaffold,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget? leading(BuildContext context) => Padding(
|
||||
padding: EdgeInsets.only(left: sideMenuWidth),
|
||||
|
@ -105,24 +89,8 @@ class DesktopSidebarWrapper extends BasePage {
|
|||
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
reaction<SidebarItem>((_) => desktopSidebarViewModel.currentPage, (page) {
|
||||
String? currentPath;
|
||||
|
||||
desktopKey.currentState?.popUntil((route) {
|
||||
currentPath = route.settings.name;
|
||||
return true;
|
||||
});
|
||||
if (page == SidebarItem.transactions) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentPath == Routes.transactionsPage) {
|
||||
Navigator.of(desktopKey.currentContext!).pop();
|
||||
}
|
||||
|
||||
pageController.jumpToPage(page.index);
|
||||
});
|
||||
|
||||
_setEffects();
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
@ -151,6 +119,7 @@ class DesktopSidebarWrapper extends BasePage {
|
|||
}),
|
||||
Expanded(
|
||||
child: PageView(
|
||||
key: _pageViewKey,
|
||||
controller: pageController,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
children: [
|
||||
|
@ -182,4 +151,25 @@ class DesktopSidebarWrapper extends BasePage {
|
|||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _setEffects() async {
|
||||
|
||||
reaction<SidebarItem>((_) => desktopSidebarViewModel.currentPage, (page) {
|
||||
|
||||
String? currentPath;
|
||||
|
||||
desktopKey.currentState?.popUntil((route) {
|
||||
currentPath = route.settings.name;
|
||||
return true;
|
||||
});
|
||||
if (page == SidebarItem.transactions) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentPath == Routes.transactionsPage) {
|
||||
Navigator.of(desktopKey.currentContext!).pop();
|
||||
}
|
||||
pageController.jumpToPage(page.index);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue