import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:http/http.dart' as http; import '../../customAppBar/toastHelper.dart'; import '../../models/environment.dart'; import '../postEnrollment/service/api_service.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'dart:convert'; import 'package:http/http.dart' as http; Future showUpdateMobileDialog( BuildContext context, ApiService apiService, String clientId, String emailId, String? currentMobile, ) { final controller = TextEditingController(text: currentMobile ?? ''); bool isLoading = false; return showDialog( context: context, barrierDismissible: false, builder: (context) { return StatefulBuilder( builder: (context, setState) { return AlertDialog( title: Text( "Update Mobile Number", style: GoogleFonts.poppins(fontWeight: FontWeight.w600), ), content: TextField( controller: controller, keyboardType: TextInputType.phone, decoration: const InputDecoration( labelText: "Enter Mobile Number", border: OutlineInputBorder(), ), ), actions: [ // Cancel Button ElevatedButton( onPressed: () => Navigator.pop(context, null), child: Text("Cancel", style: GoogleFonts.poppins(color: Colors.white)), style: ElevatedButton.styleFrom(backgroundColor: Color(0xFFE26728)), ), const SizedBox(width: 10), // Save Button ElevatedButton( onPressed: isLoading ? null : () async { final newMobile = controller.text.trim(); if (newMobile.isEmpty) { ToastHelper.showErrorToast(context, "Enter mobile number"); return; } setState(() => isLoading = true); final updateParam = { "email_id": emailId, "client_id": clientId, "new_mobile_number": newMobile, }; // ✅ Call API using apiService bool success = await apiService.updateMobileNumber(updateParam); if (success) { ToastHelper.showSuccessToast(context, "Mobile Number Updated"); Navigator.pop(context, newMobile); } else { ToastHelper.showErrorToast(context, "Failed to update number"); } }, child: isLoading ? const SizedBox( width: 18, height: 18, child: CircularProgressIndicator( color: Colors.white, strokeWidth: 2, ), ) : Text("Save", style: GoogleFonts.poppins(color: Colors.white)), style: ElevatedButton.styleFrom(backgroundColor: Color(0xFFE26728)), ), ], ); }, ); }, ); }