I encounter an issue: I integrated flutter with node.js API. Debugger shows I got 2 requests. 1 is GET and 1 is OPTIONS. For GET request is success status 200 with return body data but for OPTIONS request success status 200 but no data. My current page showed error on for the widget.
[API file]
- seen like this returned the data
[https://i.stack.imgur.com/xWmKn.png][1]
result
[https://i.stack.imgur.com/pGblN.png][1]
[GET request]
- Status success = 200 return data
[https://i.stack.imgur.com/trL1P.png][1]
[OPTIONS request]
- Status success = 200 but no data
[https://i.stack.imgur.com/H8hG7.png][1]
I still new with Flutter and nodejs. This I follow tutorial from here https://youtu.be/rXLwX3uUYjA?list=PL7zgwanvi8_MIQwPHbhCL3xulZIGxabKo
The error is from widget_home_categories.dart
Widget _categoriesList(WidgetRef ref) {
final categories = ref.watch(
categoriesProvider(
PaginationModel(page: 1, pageSize: 10),
),
);
return categories.when(
data: (list) {
return _buildCategoryList(list!);
},
error: (_, __) => const Center(
child: Text("ERR1a"),
),
loading: () => const Center(child: CircularProgressIndicator()),
);
}
CodePudding user response:
What you see is a CORS request, because you are running this in a browser and browsers will do this for you. You would not see this if you ran your code as an app or desktop application, because then there is no layer your application code has to go through that does things for you it deems "correct".
However, it seems your actual call was approved by the CORS call and made it through and returned successfully with data.
So the only help we can give you is to not ignore the help your compiler gave you and instead use it to find out what is wrong. I'm pretty sure, one of those parameters will hold the answer:
error: (_, __) => const Center(
child: Text("ERR1a"),
),
You should probably print them, instead of some generic text that isn't helpful.