Code Monkey home page Code Monkey logo

Comments (5)

menuology-chris avatar menuology-chris commented on July 24, 2024

Oh, this is on 8.0.7

wordpress_client: ^8.0.7

from wordpress_client.

ArunPrakashG avatar ArunPrakashG commented on July 24, 2024

Hey @menuology-chris
I attempted to replicate the scenario you described and obtained the expected results. I used the same domain as the one in the log file you provided.

I suspect that the issue stems from your codebase. Since you are calling setState immediately after the network call, could you please verify your program flow? That might be causing the problem.

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());
    },
  );

from wordpress_client.

menuology-chris avatar menuology-chris commented on July 24, 2024

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?

from wordpress_client.

ArunPrakashG avatar ArunPrakashG commented on July 24, 2024

@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?

from wordpress_client.

ArunPrakashG avatar ArunPrakashG commented on July 24, 2024

Closing this due to inactivity.

from wordpress_client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.