1

I have this error while connecting to a MySQL database in PHP, but while trying it on my Postman, it works very well.

E/flutter ( 2647): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Connection refused

import 'dart:convert';
import 'package:dartz/dartz.dart';
import 'package:ecommercegetx/core/class/statusrequest.dart';
import 'package:ecommercegetx/core/functions/checkinternet.dart';
import 'package:http/http.dart' as http;

class Crud {
  Future<Either<StatusRequest, Map>> postData(String linkurl, Map data) async {
      var check = await checkInternet();
      print("###################################$check");
      print("###################################1$linkurl");
      print("###################################2$data");
      if (await checkInternet()) {
        print("checkedf");
        var response = await http.post(Uri.parse(linkurl), body: data);
        print("########################----33333333$response");
        if (response.statusCode == 200 || response.statusCode == 201) {
          Map responsebody = jsonDecode(response.body);
          return Right(responsebody);
        } else {
          return const Left(StatusRequest.serverfailure);
        }
      } else {
        return const Left(StatusRequest.offlinefailure);
      }
    }

  }

Enter image description here

Here is the repository for full code (I couldn't add more code) https://github.com/Y7gn/ecommercegetx

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mohammed Malek
  • 164
  • 1
  • 9
  • Are you using ```http://localhost:80/...``` as ```linkurl``` parameter too? – bqubique Mar 26 '23 at 20:48
  • 1
    yes, I print it in the console – Mohammed Malek Mar 26 '23 at 21:17
  • Please review *[Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/)* (e.g., *"Images should only be used to illustrate problems that* ***can't be made clear in any other way,*** *such as to provide screenshots of a user interface."*) and [do the right thing](https://stackoverflow.com/posts/75850459/edit). Thanks in advance. – Peter Mortensen Apr 07 '23 at 06:13

1 Answers1

4

Try to get your IP address and insert that instead of localhost.

Write ipconfig into your terminal and get your IP address from there. Then instead of localhost write down your IP in there.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
bqubique
  • 678
  • 6
  • 17