Fix menu with auth

This commit is contained in:
Moe Poi ~ 2022-05-22 22:04:58 +07:00
parent 159acd3ef8
commit 14b068771c

View file

@ -62,11 +62,13 @@ class _MenuState extends State<Menu> {
var oldSelectedIndex = _selectedIndex;
_selectedIndex = index;
if (index == 0) {
_selectedWidget = const Sessions();
checkSessionExist().then((isLoggedIn) {
if (isLoggedIn) {
_selectedWidget = const Sessions();
} else {
if (!isLoggedIn) {
_selectedIndex = oldSelectedIndex;
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => const Menu(initialScreen: 2))
);
Navigator.pushNamed(context, '/login');
}
});
@ -80,11 +82,13 @@ class _MenuState extends State<Menu> {
html.window.history.pushState(null, '', '/#/cart');
_selectedWidget = const Cart();
} else if (index == 4) {
_selectedWidget = const Transactions();
checkSessionExist().then((isLoggedIn) {
if (isLoggedIn) {
_selectedWidget = const Transactions();
} else {
if (!isLoggedIn) {
_selectedIndex = oldSelectedIndex;
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => const Menu(initialScreen: 2))
);
Navigator.pushNamed(context, '/login');
}
});