I want to have python backend for my flutter app. So I created the python file:
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/", methods = ["GET"])
def index():
return jsonify({"testForMe": "HI! THIS IS PYTHON"})
if __name__ == "__main__":
app.run(debug = True)
This is connected to my main.dart file:
Text(
greetings,
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
Center(
child: Container(
width: 150,
height: 60,
child: FlatButton(
color: Colors.blue,
onPressed: () async {
final antwort = await http
.get("http://127.0.0.1:5000/")
.timeout(const Duration(seconds: 3));
print("HI");
final decoded =
json.decode(antwort.body) as Map<String, dynamic>;
setState(() {
greetings = decoded["testForMe"];
});
greetings += "hi";
(context as Element).reassemble();
},
child: Text(
"Press",
style: TextStyle(
fontSize: 24,
),
),
),
),
)
But after pressing the created Button, nothing happens and there is the error:
E/flutter ( 8706): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 40732
E/flutter ( 8706):
I found anybody with the same problem here Flutter Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111 but there was not a real solution for the problem.
Anyone knows, what to do now?
Thanks