flutter:Unhandled Exception: Connection refused,address = 127.0.0.1, port = 8000

545 阅读1分钟

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

solution

In Android operating system, map the local computer addres to 10.0.2.2. So change 127.0.0.1, to 10.0.2.2

import 'package:http/http.dart' as http;
import 'dart:io';
var request =
    http.Request('GET', Uri.parse('http://127.0.0.1:8000/api/register'));
if(Platform.isAndroid){
  request =
      http.Request('GET', Uri.parse('http://10.0.2.2:8000/api/register'));
}