Add avatar menu logout
All checks were successful
Build and deploy Flutter Web / build (push) Successful in 2m10s
All checks were successful
Build and deploy Flutter Web / build (push) Successful in 2m10s
This commit is contained in:
@@ -10,6 +10,8 @@ String telegramLoginTokenFromUrl() => '';
|
|||||||
|
|
||||||
void saveMapflowSessionToken(String token) {}
|
void saveMapflowSessionToken(String token) {}
|
||||||
|
|
||||||
|
void clearMapflowSession() {}
|
||||||
|
|
||||||
void savePendingTelegramLoginToken(String token) {}
|
void savePendingTelegramLoginToken(String token) {}
|
||||||
|
|
||||||
void clearPendingTelegramLoginToken() {}
|
void clearPendingTelegramLoginToken() {}
|
||||||
|
|||||||
@@ -37,6 +37,12 @@ void saveMapflowSessionToken(String token) {
|
|||||||
web.window.localStorage.setItem(mapflowSessionStorageKey, token);
|
web.window.localStorage.setItem(mapflowSessionStorageKey, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearMapflowSession() {
|
||||||
|
web.window.localStorage.removeItem(mapflowSessionStorageKey);
|
||||||
|
web.window.localStorage.removeItem(telegramLoginStorageKey);
|
||||||
|
clearPendingTelegramLoginToken();
|
||||||
|
}
|
||||||
|
|
||||||
void savePendingTelegramLoginToken(String token) {
|
void savePendingTelegramLoginToken(String token) {
|
||||||
web.window.localStorage.setItem(pendingTelegramLoginStorageKey, token);
|
web.window.localStorage.setItem(pendingTelegramLoginStorageKey, token);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,14 @@ class _MapContent extends ConsumerWidget {
|
|||||||
SafeArea(
|
SafeArea(
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.topLeft,
|
alignment: Alignment.topLeft,
|
||||||
child: _UserAvatar(user: state.currentUser),
|
child: _UserAvatar(
|
||||||
|
user: state.currentUser,
|
||||||
|
onLogout: () {
|
||||||
|
telegram_session.clearMapflowSession();
|
||||||
|
ref.invalidate(placeControllerProvider);
|
||||||
|
telegram_session.reloadApp();
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (availableTraits.isNotEmpty)
|
if (availableTraits.isNotEmpty)
|
||||||
@@ -140,9 +147,10 @@ class _MapContent extends ConsumerWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _UserAvatar extends StatelessWidget {
|
class _UserAvatar extends StatelessWidget {
|
||||||
const _UserAvatar({required this.user});
|
const _UserAvatar({required this.user, required this.onLogout});
|
||||||
|
|
||||||
final AppUser? user;
|
final AppUser? user;
|
||||||
|
final VoidCallback onLogout;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -151,16 +159,40 @@ class _UserAvatar extends StatelessWidget {
|
|||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(left: 12, top: 8),
|
padding: const EdgeInsets.only(left: 12, top: 8),
|
||||||
child: ClipOval(
|
child: PopupMenuButton<_AvatarAction>(
|
||||||
child: SizedBox.square(
|
tooltip: '',
|
||||||
dimension: 44,
|
offset: const Offset(0, 8),
|
||||||
child: photoUrl == null || photoUrl.isEmpty
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||||
? _AvatarFallback(text: fallback)
|
onSelected: (action) {
|
||||||
: Image.network(
|
switch (action) {
|
||||||
photoUrl,
|
case _AvatarAction.logout:
|
||||||
fit: BoxFit.cover,
|
onLogout();
|
||||||
errorBuilder: (_, _, _) => _AvatarFallback(text: fallback),
|
}
|
||||||
),
|
},
|
||||||
|
itemBuilder: (_) => const [
|
||||||
|
PopupMenuItem<_AvatarAction>(
|
||||||
|
value: _AvatarAction.logout,
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.logout, size: 18),
|
||||||
|
SizedBox(width: 10),
|
||||||
|
Text('Выйти'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
child: ClipOval(
|
||||||
|
child: SizedBox.square(
|
||||||
|
dimension: 44,
|
||||||
|
child: photoUrl == null || photoUrl.isEmpty
|
||||||
|
? _AvatarFallback(text: fallback)
|
||||||
|
: Image.network(
|
||||||
|
photoUrl,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
errorBuilder: (_, _, _) => _AvatarFallback(text: fallback),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -181,6 +213,8 @@ class _UserAvatar extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum _AvatarAction { logout }
|
||||||
|
|
||||||
class _AvatarFallback extends StatelessWidget {
|
class _AvatarFallback extends StatelessWidget {
|
||||||
const _AvatarFallback({required this.text});
|
const _AvatarFallback({required this.text});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user