fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.

Home Page:https://fzyzcjy.github.io/flutter_rust_bridge/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Static methods/getters aren't generated correctly in dart

jquesada2016 opened this issue · comments

Describe the bug

Given the following code:

pub struct MyStruct {}

impl MyStruct {
  pub fn my_function() {}
  }

Does not output the MyStruct class in dart, presumably because it's not being referenced anywhere else, but this is often needed for better code organization, rathern than relying solely on top-level functions.

Regarding getters

#[frb(opaque)]
pub struct MyStruct {}

impl MyStruct {
  #[frb(sync)]
  pub fn new() -> Self {
    Self {}
  }

  #[frb(sync, getter)]
  pub fn a() -> String {
    "apple".into()
  }
}

generates invalid dart code, because it tries to pass a hint parameter which doesn't exist in a getter

Steps to reproduce

  1. Copy/paste the above examples into a new project
  2. Run codegen
  3. Observe the errors from dart

Logs

N/A

Expected behavior

Static methods should always be generated on classes, even if the struct isn't part of a public API directly.

Static getters should be generated correctly.

Generated binding code

No response

OS

No response

Version of flutter_rust_bridge_codegen

No response

Flutter info

No response

Version of clang++

No response

Additional context

No response

This looks like a bug, I do expect them to work. Feel free to PR, alternatively I will fix in the next batch (possibly within several days)

(oops close by mistake)

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.