-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wpResponse.data is empty #32
Comments
Oh, this is on 8.0.7 wordpress_client: ^8.0.7 |
Hey @menuology-chris I suspect that the issue stems from your codebase. Since you are calling final baseUrl = Uri.parse('https://{ommited}.com/wp-json/wp/v2');
// Simple Usage
final client = WordpressClient(
baseUrl: baseUrl,
);
client.initialize();
final response = await client.posts.list(
ListPostRequest(
perPage: 1,
order: Order.asc,
),
);
response.map<void>(
onSuccess: (response) {
print('Posts Count: ${response.data.length}');
// prints Posts Count: 1, as expected
},
onFailure: (response) {
print(response.error.toString());
},
); |
Thanks for the quick reply. So interestingly, all I did was switch out the response code from the Dart style to the WP style as you referenced final wpResponse = await client.posts.list(request);
switch (wpResponse) {
case WordpressSuccessResponse():
final data = wpResponse.data; // List<Post>
break;
case WordpressFailureResponse():
final error = wpResponse.error; // WordpressError
break;
} to response.map<void>(
onSuccess: (response) {
print('Posts Count: ${response.data.length}');
},
onFailure: (response) {
print(response.error.toString());
},
); And now it works void fetchArticles() async {
final baseUrl = Uri.parse('https://{mydomain}.com/wp-json/wp/v2');
final client = WordpressClient(
baseUrl: baseUrl,
);
client.initialize();
final response = await client.posts.list(
ListPostRequest(
perPage: 20,
order: Order.asc,
),
);
response.map<void>(
onSuccess: (response) {
print(response.data);
},
onFailure: (response) {
print(response.error.toString());
},
);
setState(() {});
} Could there be something different with the Dart 3 style that would cause it to be missing the data? |
@menuology-chris I had tried both methods before sharing the previous update and it was working for me. I have also retried with the same sample and it was still working on both approaches. There are no differences between the two approach. Could you please check again? |
Closing this due to inactivity. |
Hi-
Trying to implement this on an app I'm building but even with a WordpressSuccessResponse() the data varaible is empty in wpResponse.data
`
void fetchArticles() async {
final baseUrl = Uri.parse('https://mydomain.com/wp-json/wp/v2');
final client = WordpressClient(
baseUrl: baseUrl,
bootstrapper: (bootstrapper) => bootstrapper
.withStatisticDelegate((baseUrl, requestCount) {
//print('$baseUrl -> $requestCount');
})
.withDebugMode(true)
.build(),
);
client.initialize();
}
`
With debug enabled, I can see the successful connection and even the WP data in the Response Text field of the response, but the wpResponse.data field remains empty.
Logs:
scratch_1.txt
Is this a bug or am I just implementing it incorrectly? Thanks for your help!
The text was updated successfully, but these errors were encountered: