107 lines
3.2 KiB
Dart
107 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:taxglide/consts/app_asstes.dart';
|
|
import 'package:taxglide/consts/app_colors.dart';
|
|
|
|
class ValidationPopup {
|
|
// Show SnackBar
|
|
void _showSnackBar(BuildContext context, String msg, {bool isError = false}) {
|
|
print("Mageshwaran $msg");
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
duration: const Duration(seconds: 1),
|
|
backgroundColor: isError
|
|
? Colors.red
|
|
: AppColors.commanbutton, // 🔴 Error red
|
|
behavior: SnackBarBehavior.floating,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
elevation: 6,
|
|
margin: const EdgeInsets.symmetric(horizontal: 70, vertical: 25),
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
|
content: SizedBox(
|
|
width: 200,
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Image.asset(AppAssets.taxgildelogoauth, height: 18, width: 18),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
msg,
|
|
style: const TextStyle(color: Colors.white, fontSize: 12),
|
|
overflow: TextOverflow.ellipsis,
|
|
maxLines: 2,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Validate Mobile Number
|
|
bool validateMobileNumber(BuildContext context, String mobileNumber) {
|
|
// Check if empty
|
|
if (mobileNumber.isEmpty) {
|
|
_showSnackBar(context, "Please enter mobile number", isError: true);
|
|
return false;
|
|
}
|
|
|
|
// Remove spaces and special characters
|
|
String cleanNumber = mobileNumber.replaceAll(RegExp(r'[^\d]'), '');
|
|
|
|
// Check if contains only digits
|
|
if (!RegExp(r'^[0-9]+$').hasMatch(cleanNumber)) {
|
|
_showSnackBar(
|
|
context,
|
|
"Mobile number must contain only digits",
|
|
isError: true,
|
|
);
|
|
return false;
|
|
}
|
|
|
|
// Check length (Indian mobile numbers are 10 digits)
|
|
if (cleanNumber.length != 10) {
|
|
_showSnackBar(context, "Mobile number must be 10 digits", isError: true);
|
|
return false;
|
|
}
|
|
|
|
// Check if starts with valid digit (6-9 for Indian numbers)
|
|
if (!RegExp(r'^[6-9]').hasMatch(cleanNumber)) {
|
|
_showSnackBar(
|
|
context,
|
|
"Mobile number must start with 6, 7, 8, or 9",
|
|
isError: true,
|
|
);
|
|
return false;
|
|
}
|
|
|
|
// All validations passed
|
|
return true;
|
|
}
|
|
|
|
// Add this method to your ValidationPopup class
|
|
bool validateEmail(BuildContext context, String email) {
|
|
// Email regex pattern
|
|
final emailRegex = RegExp(
|
|
r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
|
|
);
|
|
|
|
if (!emailRegex.hasMatch(email)) {
|
|
showErrorMessage(context, "Please enter a valid email address");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Show success message
|
|
void showSuccessMessage(BuildContext context, String msg) {
|
|
_showSnackBar(context, msg, isError: false);
|
|
}
|
|
|
|
// Show error message
|
|
void showErrorMessage(BuildContext context, String msg) {
|
|
_showSnackBar(context, msg, isError: true);
|
|
}
|
|
}
|