profile alertbox functionality added

This commit is contained in:
venbaittech 2024-11-12 15:45:29 +05:30
parent bc8f7d7e28
commit aaffcbe362

View File

@ -149,7 +149,12 @@ class _ProfileScreenState extends State<ProfileScreen> {
}); });
} }
void _saveProfile() async { void showConfirmationDialog(BuildContext context) async {
final result = await showDialog<bool>(
context: context,
builder: (context) => const ConfirmationDialog(),
);
if (result == true) {
if (_formKey.currentState?.validate() ?? false) { if (_formKey.currentState?.validate() ?? false) {
try { try {
String userID = 'tsgehyvgy6owypj'; String userID = 'tsgehyvgy6owypj';
@ -183,8 +188,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
// Add image file if selected // Add image file if selected
if (_profileImage != null) { if (_profileImage != null) {
request.files.add( request.files.add(await http.MultipartFile.fromPath(
await http.MultipartFile.fromPath('avatar', _profileImage!.path)); 'avatar', _profileImage!.path));
} }
final adminAuth = await _pb.admins final adminAuth = await _pb.admins
.authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com'); .authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com');
@ -216,100 +221,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
} }
} }
} }
void _confirmSaveProfile() {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
// title: Text("Confirm Save"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Are you sure you want to save this page?",
style: const TextStyle(
fontSize: 14,
color: Color(0xFF898C81),
fontFamily: 'Roboto',
fontWeight: FontWeight.w400,
),
textAlign: TextAlign.center,
),
SizedBox(height: 8),
Text.rich(
TextSpan(
text: "Once saved, you will not be able to change your ",
style: TextStyle(
fontSize: 14,
color: Color(0xFF898C81),
fontFamily: 'Roboto',
fontWeight: FontWeight.w400,
),
children: [
TextSpan(
text: "name",
style: TextStyle(
fontWeight: FontWeight.w700), // Bold for "name"
),
TextSpan(
text: " or ",
),
TextSpan(
text: "date of birth",
style: TextStyle(
fontWeight:
FontWeight.w700), // Bold for "date of birth"
),
TextSpan(
text: ".",
),
],
),
textAlign: TextAlign.center,
)
],
),
actionsAlignment:
MainAxisAlignment.center, // Center-align the buttons
actions: <Widget>[
ElevatedButton(
style: ElevatedButton.styleFrom(
side: BorderSide(
color: Color(0xFF92722A)), // Set border color for "Cancel"
foregroundColor: Color(0xFF92722A), // Set text color
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(8), // Optional rounded corners
),
backgroundColor: Colors.white, // No background color
),
child: Text("Cancel"),
onPressed: () {
Navigator.of(context).pop(); // Close the dialog
},
),
SizedBox(width: 8), // Spacing between buttons
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
Color(0xFF92722A), // Set background color for "Confirm"
foregroundColor: Colors.white, // Set text color
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(8), // Optional rounded corners
),
),
child: Text("Confirm"),
onPressed: () {
Navigator.of(context).pop(); // Close the dialog
_saveProfile(); // Call save function
},
),
],
);
},
);
} }
void _resetFormFields() { void _resetFormFields() {
@ -601,7 +512,17 @@ class _ProfileScreenState extends State<ProfileScreen> {
onPressed: () { onPressed: () {
if (_formKey.currentState?.validate() ?? false) { if (_formKey.currentState?.validate() ?? false) {
_formKey.currentState?.save(); _formKey.currentState?.save();
_confirmSaveProfile(); if (_termsAccepted) {
_formKey.currentState?.save();
// _confirmSaveProfile();
showConfirmationDialog(context);
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Please accept the terms and conditions.')),
);
}
} }
}, },
icon: Icon( icon: Icon(
@ -629,3 +550,107 @@ class _ProfileScreenState extends State<ProfileScreen> {
); );
} }
} }
class ConfirmationDialog extends StatelessWidget {
const ConfirmationDialog({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return AlertDialog(
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Are you sure you want to save this page?",
style: const TextStyle(
fontSize: 14,
color: Color(0xFF898C81),
fontFamily: 'Roboto',
fontWeight: FontWeight.w400,
),
textAlign: TextAlign.center,
),
SizedBox(height: 8),
Text.rich(
TextSpan(
text: "Once saved, you will not be able to change your ",
style: TextStyle(
fontSize: 14,
color: Color(0xFF898C81),
fontFamily: 'Roboto',
fontWeight: FontWeight.w400,
),
children: [
TextSpan(
text: "name",
style:
TextStyle(fontWeight: FontWeight.w700), // Bold for "name"
),
TextSpan(
text: " or ",
),
TextSpan(
text: "date of birth",
style: TextStyle(
fontWeight: FontWeight.w700), // Bold for "date of birth"
),
TextSpan(
text: ".",
),
],
),
textAlign: TextAlign.center,
)
],
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
contentPadding: const EdgeInsets.fromLTRB(24, 20, 24, 0),
actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
actions: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
OutlinedButton(
onPressed: () {
Navigator.of(context).pop(false);
},
style: OutlinedButton.styleFrom(
side: BorderSide(color: Color(0xFF92722A)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(7)),
), // Set the border color here
),
child: Text(
"Cancel",
style: TextStyle(color: Color(0xFF92722A)),
),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(true),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF92722A), // Brown color
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text(
'Confirm',
style: TextStyle(
fontWeight: FontWeight.w500,
),
),
),
],
),
),
SizedBox(
height: 5,
)
],
);
}
}