mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 04:49:21 +00:00
Can sign out of the application
This commit is contained in:
parent
07d668eb59
commit
d10df9dd7a
@ -10,7 +10,6 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
/// @author Pierre HUBERT
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
class AccountCredentialsHelper {
|
class AccountCredentialsHelper {
|
||||||
|
|
||||||
/// Checkout whether current user is signed in or not
|
/// Checkout whether current user is signed in or not
|
||||||
Future<bool> signedIn() async {
|
Future<bool> signedIn() async {
|
||||||
return await get() != null;
|
return await get() != null;
|
||||||
@ -19,21 +18,20 @@ class AccountCredentialsHelper {
|
|||||||
/// Set new login tokens
|
/// Set new login tokens
|
||||||
Future<void> set(LoginTokens tokens) async {
|
Future<void> set(LoginTokens tokens) async {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
await prefs.setString("login_tokens", tokens.toString());
|
await prefs.setString(
|
||||||
|
"login_tokens", tokens == null ? "null" : tokens.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get current [LoginTokens]. Returns null if none or in case of failure
|
/// Get current [LoginTokens]. Returns null if none or in case of failure
|
||||||
Future<LoginTokens> get() async {
|
Future<LoginTokens> get() async {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
final string = prefs.getString("login_tokens");
|
final string = prefs.getString("login_tokens");
|
||||||
if(string == null) return null;
|
if (string == null || string == "null") return null;
|
||||||
return LoginTokens.fromJSON(jsonDecode(string));
|
return LoginTokens.fromJSON(jsonDecode(string));
|
||||||
|
} on Exception catch (e) {
|
||||||
} on Exception catch(e){
|
|
||||||
print(e.toString());
|
print(e.toString());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,4 +38,10 @@ class AccountHelper {
|
|||||||
|
|
||||||
return AuthResult.SUCCESS;
|
return AuthResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sign out user
|
||||||
|
Future<void> signOut() async {
|
||||||
|
await AccountCredentialsHelper().set(null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:comunic/ui/screens/menus_screen.dart';
|
||||||
import 'package:comunic/ui/tiles/CustomBottomNavigationBarItem.dart';
|
import 'package:comunic/ui/tiles/CustomBottomNavigationBarItem.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ class _HomeRouteState extends State<HomeRoute> {
|
|||||||
return Text("Conversations");
|
return Text("Conversations");
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
return Text("Menu");
|
return MenuScreen();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw "Invalid tab number : " + _currTab.toString();
|
throw "Invalid tab number : " + _currTab.toString();
|
||||||
|
66
lib/ui/screens/menus_screen.dart
Normal file
66
lib/ui/screens/menus_screen.dart
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import 'package:comunic/helpers/account_helper.dart';
|
||||||
|
import 'package:comunic/ui/routes/login_route.dart';
|
||||||
|
import 'package:comunic/ui/tiles/menu_tile.dart';
|
||||||
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// Menu screen
|
||||||
|
///
|
||||||
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
|
class MenuScreen extends StatelessWidget {
|
||||||
|
/// Ask the user if he really wants to sign out from the application
|
||||||
|
Future<void> _confirmSignOut(BuildContext context) async {
|
||||||
|
final result = await showDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
builder: (c) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(tr("Confirm sign out")),
|
||||||
|
content: Text(
|
||||||
|
tr("Do your really want to sign out from the application ?")),
|
||||||
|
actions: <Widget>[
|
||||||
|
FlatButton(
|
||||||
|
child: Text(tr("Cancel").toUpperCase()),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context, false);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
FlatButton(
|
||||||
|
child: Text(
|
||||||
|
tr("Sign out").toUpperCase(),
|
||||||
|
style: TextStyle(color: Colors.red),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if(result == null || !result)
|
||||||
|
return;
|
||||||
|
|
||||||
|
await AccountHelper().signOut();
|
||||||
|
|
||||||
|
Navigator.pushReplacement(context, MaterialPageRoute(builder: (c){
|
||||||
|
return LoginRoute();
|
||||||
|
}));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ListView(
|
||||||
|
children: <Widget>[
|
||||||
|
MenuTile(
|
||||||
|
title: tr("Sign out"),
|
||||||
|
onTap: () {
|
||||||
|
_confirmSignOut(context);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
29
lib/ui/tiles/menu_tile.dart
Normal file
29
lib/ui/tiles/menu_tile.dart
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// Menu tile
|
||||||
|
///
|
||||||
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
|
class MenuTile extends StatelessWidget {
|
||||||
|
final String title;
|
||||||
|
final GestureTapCallback onTap;
|
||||||
|
|
||||||
|
const MenuTile({@required this.title, this.onTap}) : assert(title != null);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: <Widget>[
|
||||||
|
Divider(),
|
||||||
|
InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Text(title),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user