-
-
Notifications
You must be signed in to change notification settings - Fork 166
Open
Description
When using the fetch API with flutter_js, the returned response object always reports a 200 status code, even if the actual HTTP status code is different. For example, when making a request to https://httpbin.org/status/400, the status is expected to be 400, but the reported resp.status is 200.
Sample Code to Reproduce:
import 'package:flutter/material.dart';
import 'package:flutter_js/extensions/fetch.dart';
import 'package:flutter_js/extensions/xhr.dart';
import 'package:flutter_js/flutter_js.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: FilledButton(
onPressed: () async {
final runtime = await getJavascriptRuntime().enableFetch();
runtime.enableHandlePromises();
runtime.enableXhr();
JsEvalResult result = await runtime.evaluateAsync("""
async function main() {
console.log("Hello, World!!!");
const resp = await fetch("https://httpbin.org/status/400");
console.log("Response status:", resp.status);
}
main();
""");
runtime.executePendingJob();
print(result);
if (result.isPromise ||
result.stringResult == "Instance of 'Future<dynamic>'") {
result = await runtime.handlePromise(result);
}
print(result);
},
child: Text('Click Me'),
),
),
),
);
}
}Output:
I/flutter ( 2843): Hello, World!!!
I/flutter ( 2843): Instance of 'Future<dynamic>'
I/flutter ( 2843): Response status: 200
I/flutter ( 2843): null
Environment:
- flutter_js version: 0.8.4
- Platform: tested on Android and iOS
- Flutter version: 3.32.0
Metadata
Metadata
Assignees
Labels
No labels