finilizing the alert dialog for logut

This commit is contained in:
ashrafzarkanisala
2024-10-23 02:40:44 +03:00
parent bd7651fa8c
commit 1c9943cfdb
7 changed files with 315 additions and 63 deletions

View File

@ -168,4 +168,16 @@ class Assets {
//assets/icons/2gang.svg
static const String twoGang = 'assets/icons/2gang.svg';
//assets/icons/account_setting.svg
static const String accountSetting = 'assets/icons/account_setting.svg';
//assets/icons/settings.svg
static const String settings = 'assets/icons/settings.svg';
//assets/icons/sign_out.svg
static const String signOut = 'assets/icons/sign_out.svg';
//assets/icons/logo_grey.svg
static const String logoGrey = 'assets/icons/logo-grey.svg';
}

View 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;
});
});
}
}