Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

fix: add token expired message and fix navigation and title text #119

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/screens/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ class _HomeScreenState extends State<HomeScreen> {
],
),
bottomNavigationBar: BottomNavyBar(
selectedIndex: _currentIndex,
onItemSelected: (index) {
setState(() => _currentIndex = index);
pageController.jumpToPage(index);
},
onItemSelected:
(index) => // This triggers when the user clicks item on BottomNavyBar
BlocProvider.of<HomeBloc>(context).add(HomeEvent.fromIndex(index)),
selectedIndex: state.index,
items: [
BottomNavyBarItem(
icon: Icon(Icons.home),
Expand Down
33 changes: 31 additions & 2 deletions lib/screens/home/pages/stats/stats_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mentorship_client/remote/models/task.dart';
import 'package:mentorship_client/remote/repositories/user_repository.dart';
import 'package:mentorship_client/screens/home/pages/stats/bloc/bloc.dart';
import 'package:mentorship_client/widgets/loading_indicator.dart';
import 'dart:async';

import 'package:mentorship_client/auth/bloc.dart';

/// First page from the left on the HomeScreen. Displays welcome message to the user
/// and provides some information on latest achievements.
///
Expand Down Expand Up @@ -94,7 +95,12 @@ class _StatsPageState extends State<StatsPage> {
);
}
if (state is StatsPageFailure) {
return Text(state.message);
if (state.message == "The token has expired! Please, login again or refresh it.") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to think of a better way to do this, comparing the message will cause this feature to break if we decide later to change the message returned by the API. Perhaps now makes sense to return something else added to the message. Can you create an issue on Flutter repo to address this change, please? If not changed now perhaps later, but with an issue, we won't forget about this problem. @techno-disaster

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anitab-org/mentorship-android-maintainers any idea how this is done on the android side? Not sure if there is any other alternative right now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but you can ask on #mentorship-system stream on Zulip. I don't remember now 🤔

Future.delayed(Duration.zero, () => _showTokenExpiredDialog(context));
return Text(state.message);
} else {
return Text(state.message);
}
}

if (state is StatsPageLoading) {
Expand Down Expand Up @@ -125,3 +131,26 @@ class _StatsPageState extends State<StatsPage> {
);
}
}

void _showTokenExpiredDialog(BuildContext context) {
showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return AlertDialog(
title: Text("Token expired"),
content: Text("Relogin to refresh the jwt token"),
techno-disaster marked this conversation as resolved.
Show resolved Hide resolved
actions: <Widget>[
FlatButton(
child: Text('Relogin'),
onPressed: () {
BlocProvider.of<AuthBloc>(context).add(JustLoggedOut());

Navigator.of(context).pop();
},
),
],
);
},
);
}