Skip to content
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

[ui_state] Not working properly #2440

Open
Vzz1c opened this issue Dec 8, 2024 · 11 comments
Open

[ui_state] Not working properly #2440

Vzz1c opened this issue Dec 8, 2024 · 11 comments
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc enhancement New feature or request

Comments

@Vzz1c
Copy link

Vzz1c commented Dec 8, 2024

Future<void> main() async {
 return runRustApp(body: body, state: RustState.newInstance);
}

Widget body(Future<RustState> futureState) {
  return FutureBuilder<RustState>(
    future: futureState,
    builder: (context, snapshot) {
      if (snapshot.connectionState == ConnectionState.waiting) {
        return CircularProgressIndicator();
      } else if (snapshot.hasError) {
        return Text('Error: ${snapshot.error}');
      } else if (snapshot.hasData) {
        RustState state = snapshot.data!;
        return Column(
          children: [
            Text('Count: ${state.count}'),
            TextButton(onPressed: state.increment, child: Text('+1')),
          ],
        ).padding(all: 16);
      } else {
        return Text('No data available');
      }
    },
  );
}

Class 'Future<RustState>' has no instance method 'setBaseState'. Receiver: Instance of 'Future<RustState>' Tried calling: setBaseState(baseState: Instance of 'BaseRustStateImpl')

@Vzz1c Vzz1c added the enhancement New feature or request label Dec 8, 2024
Copy link

welcome bot commented Dec 8, 2024

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Dec 8, 2024

Hi, according to the demo

, it seems we should use

Widget body(RustState state) {

instead of

Widget body(Future<RustState> futureState) {

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Dec 8, 2024
@Vzz1c
Copy link
Author

Vzz1c commented Dec 9, 2024

The code I generated using the latest version of flutter_rust_bridge_codegen

abstract class RustState implements RustOpaqueInterface {
  int get count;

  set count(int count);

  Future<void> increment();

  // HINT: Make it `#[frb(sync)]` to let it become the default constructor of Dart class.
  static Future<RustState> newInstance() =>
      RustLib.instance.api.crateApiSimpleRustStateNew();

  Future<void> setBaseState({required BaseRustState baseState});
}

frb_example/rust_ui_counter/ui/lib/src/rust/app.dart

abstract class RustState implements RustOpaqueInterface {
  int get count;

  set count(int count);

  void increment();

  factory RustState() => RustLib.instance.api.crateAppRustStateNew();

  void setBaseState({required BaseRustState baseState});
}

@fzyzcjy
Copy link
Owner

fzyzcjy commented Dec 9, 2024

Not very sure about your question in the latest reply, but I mean your own code maybe need to remove that Future like mentioned above.

@Vzz1c Vzz1c closed this as completed Dec 9, 2024
@Vzz1c
Copy link
Author

Vzz1c commented Dec 10, 2024

Please delete my question completely, thank you.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Dec 10, 2024

No worries, everyone asks naive questions when starting programming!

@Vzz1c
Copy link
Author

Vzz1c commented Dec 11, 2024

naive questions?Have you tested the code yourself? Run the great code: cargo install flutter_rust_bridge_codegen && flutter_rust_bridge_codegen create my_app && cd my_app && flutter run, run flutter_ rust_bridge/frb_example/rust_ui_counter/src /app.rs example, do you get it to work? The code doesn't even match.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Dec 11, 2024

Have you tested the code yourself?

Yes, indeed both manually and automatically (via CI). The CI tests the code for each commit, e.g.

test_mimic_quickstart:
.

If you find any issues running the command, it is suggested to create an issue with detailed error logs or minimal reproducible sample.

Run the great code

I never claim my code is "great". It is because you mentioned deleting your question completely that I guess you thought your question was too naive and I hope to make you not felt that, thus I said the "naive question" thing. In addition, it is true that new learners often ask naive questions, and some people even claim there are no dumb questions.

do you get it to work? The code doesn't even match.

It is confusing what do you mean by "match". Surely the quickstart and the rust_ui_counter are different demos, so the code should be different.

@Vzz1c
Copy link
Author

Vzz1c commented Dec 11, 2024

If only you had written the code with half the focus you have in your replies, you don't even bother to validate the questions, there is no point in picking on my words, I translated it through a machine, are you fighting with the translator? Good luck to you and your project!

@fzyzcjy
Copy link
Owner

fzyzcjy commented Dec 11, 2024

If only you had written the code with half the focus you have in your replies

To be honest, I spent a large amount of time writing the code - which can be clearly seen from git commit history, much more than handling GitHub replies.

you don't even bother to validate the questions

It seems I have already answer your question here, and I am not sure what your further reply asks (thus I said "not very sure about your question in the latest reply ..."). Maybe add a few sentences describing what makes you confused may help. For example, what error do you see, etc. Only pasting two code snippets and expect a busy and tired programmer (me) to guess what you mean may not seem to super ideal.

there is no point in picking on my words

I am not picking on any words. As mentioned above, since you mentioned you wanted to delete the whole question, I am worried whether you felt the question is too easy and thus want to remove it from your thread history, and thus wanted to comfort you. Not sure what your machine translation convert my sentences to.

@Vzz1c
Copy link
Author

Vzz1c commented Dec 11, 2024

I hope you stay confident.

@Vzz1c Vzz1c reopened this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants