In flask:
<code>from datetime import timedelta
from flask import Flask, jsonify, request, redirect, session, render_template
from flask_cors import CORS
app = Flask(__name__)
CORS(app
)
app.config["SECRET_KEY"] = '12345'
app.config.update(SESSION_COOKIE_SAMESITE="None", SESSION_COOKIE_SECURE=True)
@app.route('/test1', methods=['POST'])
def test1():
session["first_auth"] = 'abcde'
print(session)
return jsonify(message="Hello from Flask!")
@app.route('/test2', methods=['GET'])
def test2():
print(session)
return jsonify(message="Hello from Flask!")
</code>
<code>from datetime import timedelta
from flask import Flask, jsonify, request, redirect, session, render_template
from flask_cors import CORS
app = Flask(__name__)
CORS(app
)
app.config["SECRET_KEY"] = '12345'
app.config.update(SESSION_COOKIE_SAMESITE="None", SESSION_COOKIE_SECURE=True)
@app.route('/test1', methods=['POST'])
def test1():
session["first_auth"] = 'abcde'
print(session)
return jsonify(message="Hello from Flask!")
@app.route('/test2', methods=['GET'])
def test2():
print(session)
return jsonify(message="Hello from Flask!")
</code>
from datetime import timedelta
from flask import Flask, jsonify, request, redirect, session, render_template
from flask_cors import CORS
app = Flask(__name__)
CORS(app
)
app.config["SECRET_KEY"] = '12345'
app.config.update(SESSION_COOKIE_SAMESITE="None", SESSION_COOKIE_SECURE=True)
@app.route('/test1', methods=['POST'])
def test1():
session["first_auth"] = 'abcde'
print(session)
return jsonify(message="Hello from Flask!")
@app.route('/test2', methods=['GET'])
def test2():
print(session)
return jsonify(message="Hello from Flask!")
and I have this in my flutter
<code>Future<String?> onPressed() async {
final HttpResponse response =
await HttpRequests.post('http://127.0.0.1:5000/test1');
if (response.statusCode == 200) {
final jsonResponse = response.json;
return jsonResponse['message'];
} else {
return null;
}
}
Future<String?> onPressed2() async {
final HttpResponse response =
await HttpRequests.get('http://127.0.0.1:5000/test2');
if (response.statusCode == 200) {
final jsonResponse = response.json;
return jsonResponse['message'];
} else {
return null;
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
ElevatedButton(onPressed: onPressed, child: Text('Press Me')),
ElevatedButton(onPressed: onPressed2, child: Text('Print'))]
)}
</code>
<code>Future<String?> onPressed() async {
final HttpResponse response =
await HttpRequests.post('http://127.0.0.1:5000/test1');
if (response.statusCode == 200) {
final jsonResponse = response.json;
return jsonResponse['message'];
} else {
return null;
}
}
Future<String?> onPressed2() async {
final HttpResponse response =
await HttpRequests.get('http://127.0.0.1:5000/test2');
if (response.statusCode == 200) {
final jsonResponse = response.json;
return jsonResponse['message'];
} else {
return null;
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
ElevatedButton(onPressed: onPressed, child: Text('Press Me')),
ElevatedButton(onPressed: onPressed2, child: Text('Print'))]
)}
</code>
Future<String?> onPressed() async {
final HttpResponse response =
await HttpRequests.post('http://127.0.0.1:5000/test1');
if (response.statusCode == 200) {
final jsonResponse = response.json;
return jsonResponse['message'];
} else {
return null;
}
}
Future<String?> onPressed2() async {
final HttpResponse response =
await HttpRequests.get('http://127.0.0.1:5000/test2');
if (response.statusCode == 200) {
final jsonResponse = response.json;
return jsonResponse['message'];
} else {
return null;
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
ElevatedButton(onPressed: onPressed, child: Text('Press Me')),
ElevatedButton(onPressed: onPressed2, child: Text('Print'))]
)}
but When i press two buttons I got,
<code><SecureCookieSession {'first_auth': 'abcde'}> 127.0.0.1 - - [21/Oct/2024 11:54:26] "POST /test1 HTTP/1.1" 200 - <SecureCookieSession {}> 127.0.0.1 - - [21/Oct/2024 11:54:30] "GET /test2 HTTP/1.1" 200 -
</code>
<code><SecureCookieSession {'first_auth': 'abcde'}> 127.0.0.1 - - [21/Oct/2024 11:54:26] "POST /test1 HTTP/1.1" 200 - <SecureCookieSession {}> 127.0.0.1 - - [21/Oct/2024 11:54:30] "GET /test2 HTTP/1.1" 200 -
</code>
<SecureCookieSession {'first_auth': 'abcde'}> 127.0.0.1 - - [21/Oct/2024 11:54:26] "POST /test1 HTTP/1.1" 200 - <SecureCookieSession {}> 127.0.0.1 - - [21/Oct/2024 11:54:30] "GET /test2 HTTP/1.1" 200 -
I wonder what can fix this? The endpoints work fine when using postman… so i wonder if there is anything special with flutter but cannot find any solutions