mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-18 08:45:05 +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:flutter_mobx/flutter_mobx.dart';
|
||||||
import 'package:cake_wallet/router.dart' as Router;
|
import 'package:cake_wallet/router.dart' as Router;
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
|
|
||||||
class DesktopSidebarWrapper extends BasePage {
|
class DesktopSidebarWrapper extends BasePage {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
final DesktopSidebarViewModel desktopSidebarViewModel;
|
final DesktopSidebarViewModel desktopSidebarViewModel;
|
||||||
|
@ -25,6 +24,8 @@ class DesktopSidebarWrapper extends BasePage {
|
||||||
required this.dashboardViewModel,
|
required this.dashboardViewModel,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static Key _pageViewKey = GlobalKey();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color get backgroundLightColor =>
|
Color get backgroundLightColor =>
|
||||||
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
|
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';
|
final unselectedIconPath = 'assets/images/desktop_transactions_outline_icon.png';
|
||||||
double get sideMenuWidth => 76.0;
|
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
|
@override
|
||||||
Widget? leading(BuildContext context) => Padding(
|
Widget? leading(BuildContext context) => Padding(
|
||||||
padding: EdgeInsets.only(left: sideMenuWidth),
|
padding: EdgeInsets.only(left: sideMenuWidth),
|
||||||
|
@ -105,24 +89,8 @@ class DesktopSidebarWrapper extends BasePage {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget body(BuildContext context) {
|
Widget body(BuildContext context) {
|
||||||
reaction<SidebarItem>((_) => desktopSidebarViewModel.currentPage, (page) {
|
_setEffects();
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
return Row(
|
return Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
@ -151,6 +119,7 @@ class DesktopSidebarWrapper extends BasePage {
|
||||||
}),
|
}),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: PageView(
|
child: PageView(
|
||||||
|
key: _pageViewKey,
|
||||||
controller: pageController,
|
controller: pageController,
|
||||||
physics: NeverScrollableScrollPhysics(),
|
physics: NeverScrollableScrollPhysics(),
|
||||||
children: [
|
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