mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
finilizing the alert dialog for logut
This commit is contained in:
224
lib/utils/user_drop_down_menu.dart
Normal file
224
lib/utils/user_drop_down_menu.dart
Normal file
@ -0,0 +1,224 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
||||
import 'package:syncrow_web/pages/auth/model/user_model.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/constants/routes_const.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
|
||||
class UserDropdownMenu extends StatefulWidget {
|
||||
const UserDropdownMenu({super.key, required this.user});
|
||||
final UserModel? user;
|
||||
|
||||
@override
|
||||
_UserDropdownMenuState createState() => _UserDropdownMenuState();
|
||||
}
|
||||
|
||||
class _UserDropdownMenuState extends State<UserDropdownMenu> {
|
||||
bool _isDropdownOpen = false;
|
||||
|
||||
void _toggleDropdown() {
|
||||
setState(() {
|
||||
_isDropdownOpen = !_isDropdownOpen;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
_toggleDropdown();
|
||||
await _showPopupMenu(context);
|
||||
setState(() {
|
||||
_isDropdownOpen = false;
|
||||
});
|
||||
},
|
||||
child: Transform.rotate(
|
||||
angle: _isDropdownOpen ? -1.5708 : 1.5708,
|
||||
child: const Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
color: Colors.white,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showPopupMenu(BuildContext context) async {
|
||||
final RenderBox overlay = Overlay.of(context).context.findRenderObject() as RenderBox;
|
||||
final RelativeRect position = RelativeRect.fromRect(
|
||||
Rect.fromLTRB(
|
||||
overlay.size.width,
|
||||
75,
|
||||
0,
|
||||
overlay.size.height,
|
||||
),
|
||||
Offset.zero & overlay.size,
|
||||
);
|
||||
|
||||
await showMenu(
|
||||
context: context,
|
||||
position: position,
|
||||
color: ColorsManager.whiteColors,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomRight: Radius.circular(10),
|
||||
bottomLeft: Radius.circular(10),
|
||||
),
|
||||
),
|
||||
items: <PopupMenuEntry>[
|
||||
PopupMenuItem(
|
||||
onTap: () {},
|
||||
child: ListTile(
|
||||
leading: SvgPicture.asset(Assets.accountSetting),
|
||||
title: Text(
|
||||
"Account Settings",
|
||||
style: context.textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () {},
|
||||
child: ListTile(
|
||||
leading: SvgPicture.asset(Assets.settings),
|
||||
title: Text(
|
||||
"Settings",
|
||||
style: context.textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
final size = MediaQuery.of(context).size;
|
||||
return AlertDialog(
|
||||
alignment: Alignment.center,
|
||||
content: SizedBox(
|
||||
height: 250,
|
||||
width: 500,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(40),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
Assets.blackLogo,
|
||||
height: 40,
|
||||
width: 200,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(
|
||||
'Log out of your Syncrow account',
|
||||
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: SizedBox.square(
|
||||
dimension: 80,
|
||||
child: CircleAvatar(
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
child: SizedBox.square(
|
||||
dimension: 78,
|
||||
child: SvgPicture.asset(
|
||||
Assets.logoGrey,
|
||||
fit: BoxFit.fitHeight,
|
||||
height: 80,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
'${widget.user?.firstName ?? ''} ${widget.user?.lastName}',
|
||||
style: Theme.of(context).textTheme.titleMedium!.copyWith(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
' ${widget.user?.email}',
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actionsAlignment: MainAxisAlignment.center,
|
||||
actions: [
|
||||
SizedBox(
|
||||
width: 200,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
context.pop();
|
||||
},
|
||||
child: DefaultButton(
|
||||
backgroundColor: ColorsManager.boxColor,
|
||||
elevation: 1,
|
||||
child: Text(
|
||||
'Cancel',
|
||||
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||
fontSize: 12,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
AuthBloc.logout();
|
||||
context.go(RoutesConst.auth);
|
||||
},
|
||||
child: SizedBox(
|
||||
width: 200,
|
||||
child: DefaultButton(
|
||||
elevation: 1,
|
||||
child: Text(
|
||||
'Logout',
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium!.copyWith(fontSize: 12, color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
]);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: ListTile(
|
||||
leading: SvgPicture.asset(Assets.signOut),
|
||||
title: Text(
|
||||
"Log Out",
|
||||
style: context.textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
).then((value) {
|
||||
setState(() {
|
||||
_isDropdownOpen = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user