Buenas Estoy con un problma en flutter...
Estoy queriendo acceder a mi base de datos y me salta este error:[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Connection refused
ya cambie las direcciones de Ip a mi IP con 10.0.2.2:8000/api y con 127.0.0.1:8000/api.
Ya entre a dar a phpmyadmin a autorizar el ingreso de IP.
con usando Flutter laravel Php.
auth_services
class AuthServices {
static Future<http.Response> register(
String name, String email, String password) async {
Map data = {
"name": name,
"email": email,
"password": password,
};
var body = json.encode(data);
var url = Uri.parse(baseURL + '/auth/register');
http.Response response = await http.post(
url,
headers: headers,
body: body,
);
print(response.body);
return response;
}
register_screen
createAccountPressed() async {
bool emailValid = RegExp(
r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+")
.hasMatch(_email);
if (emailValid) {
http.Response response =
await AuthServices.register(_name, _email, _password);
Map responseMap = jsonDecode(response.body);
if (response.statusCode == 200) {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => const HomeScreen(),
));
} else {
errorSnackBar(context, responseMap.values.first[0]);
}
} else {
errorSnackBar(context, 'email not valid');
}
}
globals.dart
import 'package:flutter/material.dart';
const String baseURL = "http://192.168.100.4:8000/api/"; //emulator localhost
const Map<String, String> headers = {"Content-Type": "application/json"};
errorSnackBar(BuildContext context, String text) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
backgroundColor: Colors.red,
content: Text(text),
duration: const Duration(seconds: 1),
));
}