How to check if Email already exists in Flutter

To check if an email already exists in Flutter, you can make an HTTP request to your server or API endpoint and handle the response accordingly. Here’s an example of how you can implement it:

1. First, import the necessary dependencies:

import 'package:http/http.dart' as http;
import 'dart:convert';

2. Create a function to check if the email exists:

registerPress() async {
    bool emailValid = RegExp(

    if (_name.isEmpty || _email.isEmpty || _phone.isEmpty) {
      errorSnackBar(context, 'Please fill in all fields');
    } else if (dropdownvalue == 'Select Country of Residence' ||
        dropdownvalue1 == 'Select Your Treatment Category') {
      errorSnackBar(context, 'Please select country and category');
    } else if (!emailValid) {
      errorSnackBar(context, 'Email is not valid');
    else {
    // Check if email already exists
    bool emailExists = await checkEmailExists(_email);
    if (emailExists) {
      errorSnackBar(context, 'Email already exists');
     else {
      http.Response response = await authServices.register(
        // context,

3. Now you can use the checkEmailExists function in your registerPress function:

 Future<bool> checkEmailExists(String email) async {
    var response = await http.get(Uri.parse(
    var resBody = json.decode(response.body);
    return resBody['exists'];

4. Go to laravel ApI

Route::get('/check-email-exists', 'Auth\RegisterController@checkEmailExists');

5. Go to Laravel RegisterController

  public function checkEmailExists(Request $request)
        Log::info('yaha tak aa raha hai');
        $email = $request->query('email');
        $exists = User::where('email', $email)->exists();
        return response()->json(['exists' => $exists]);
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x