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

Document has wrong dart syntax on section 4.3.4 #421

Closed
dbsxdbsx opened this issue Apr 27, 2022 · 12 comments
Closed

Document has wrong dart syntax on section 4.3.4 #421

dbsxdbsx opened this issue Apr 27, 2022 · 12 comments

Comments

@dbsxdbsx
Copy link
Contributor

dbsxdbsx commented Apr 27, 2022

the refined code from this section is not compilable:

    final text = snap.data!.when(
                    ios: () => 'iOS',
                    windows: () => 'Windows',
                    android: () => 'Android',
                    unix: () => 'Unix',
                    macOs: (arch) => 'MacOS on $arch',
                    wasm: () => 'the Web',
                    unknown: () => 'Unknown OS',
                  );

error message: The method 'when' isn't defined for the type 'List'. ...

@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 27, 2022

Maybe you have not run freezed code generator?

/cc @Desdaemon Or is this a real bug

@dbsxdbsx
Copy link
Contributor Author

dbsxdbsx commented Apr 27, 2022

Maybe you have not run freezed code generator?

/cc @Desdaemon Or is this a real bug

I followed instruction from 4.3.3,and then run just with the following justfile script:

# Homebrew installs LLVM in a place that is not visible to ffigen.
# This explicitly specifies the place where the LLVM dylibs are kept.
llvm_path := if os() == "macos" {
    "--llvm-path /opt/homebrew/opt/llvm"
} else {
    ""
}

default: gen lint

gen:
    flutter_rust_bridge_codegen {{llvm_path}} \
        --rust-input native/src/api.rs \
        --dart-output lib/bridge_generated.dart \
        --c-output ios/Runner/bridge_generated.h
    cp ios/Runner/bridge_generated.h macos/Runner/bridge_generated.h
    # Uncomment this line to invoke build_runner as well
    flutter pub run build_runner build

lint:
    cd native && cargo fmt
    dart format .

clean:
    flutter clean
    cd native && cargo clean

# vim:expandtab:sw=4:ts=4

And the project is based on template from here: https://github.com/Desdaemon/flutter_rust_bridge_template.
Did I miss something?

@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 27, 2022

Sounds quite correct. Could you please share your whole (refined) repository, for example, as a github repo so I can look at the modified and generated dart code?

@dbsxdbsx
Copy link
Contributor Author

dbsxdbsx commented Apr 28, 2022

Sounds quite correct. Could you please share your whole (refined) repository, for example, as a github repo so I can look at the modified and generated dart code?
Now it is worked out to build a native windows app on win10.
But some detail needs to mention.

What I did totally according to official template:

  1. uncomment flutter pub run build_runner build in justfile
  2. add 3 freeze related package according to section 4.3.3
  3. install all dependencies according to section 4.3.1
  4. install corrison through cmake and comment some lines in windows\rust.cmake
  5. CHANGE CODE in lib\main.dart accordingly
  6. run just;
  7. run flutter build

From setp 5, I used the code bleow instead of that stated in section 4.3.4:

// replace with this:
                final text = platform.when(
                  //error here,'when' cannot be recognized
                  // final text = snap.data!.when(//error here,'when' cannot be recognized
                  ios: () => 'iOS',
                  windows: () => 'Windows',
                  android: () => 'Android',
                  unix: () => 'Unix',
                  macOs: (arch) => 'MacOS on $arch',
                  wasm: () => 'the Web',
                  unknown: () => 'Unknown OS',
                );
                return Text('$text ($release)', style: style);

In addition, since I changed api.rs, Whenever I run just, it would raise:

[2022-04-28T03:27:28Z ERROR flutter_rust_bridge_codegen::commands] Failed to run build_runner ...
...

But it is still workable.
ALso, with rust 1.6.0 on win10, Whenever I run flutter run, it raise:

Launching lib\main.dart on Windows in debug mode...
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.60.0 (7737e0b5c 2022-04-04)`
CMake Warning at C:/Program Files (x86)/Corrosion/share/cmake/Corrosion.cmake:314 (message):
  No linker preference for target native
Call Stack (most recent call first):
  C:/Program Files (x86)/Corrosion/share/cmake/CorrosionGenerator.cmake:329 (_add_cargo_build)
  C:/Program Files (x86)/Corrosion/share/cmake/CorrosionGenerator.cmake:479 (_generator_add_target)
  C:/Program Files (x86)/Corrosion/share/cmake/Corrosion.cmake:408 (_generator_add_cargo_targets)
  rust.cmake:17 (corrosion_import_crate)
  CMakeLists.txt:53 (include)

Though this warning seems to not harm output, it is still frustrated.

This is my modified template.
This is my modified template.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 28, 2022

Sounds like we need to modify the tutorial? /cc @Desdaemon

I am willing to review a PR :)

@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 28, 2022

Failed to run build_runner ...
No linker preference for target native

Sounds like a (or two) different bugs. Could you please raise them separately?

@Desdaemon
Copy link
Contributor

The example in the tutorial is a bit out of date with the actual template, but otherwise the provided template works on my MacOS machine. I'll have to check this again later on my Windows one.

@dbsxdbsx
Copy link
Contributor Author

dbsxdbsx commented Apr 28, 2022

Failed to run build_runner ...
No linker preference for target native

Sounds like a (or two) different bugs. Could you please raise them separately?

For issue on flutter run, I guess t it is related to version of corrison; And for issue on Failed to run build_runner, I cannot reproduce it, if I reproduced it , maybe I would raise it in another post.

Meanwhile, I made a new template for testing number value between dart and rust with a method called add_2_unsigned_value. It is workable, but I cannot parse dart Int into rust with type u8 or u16 (but ok with u32 and u64, but according to section3.1, it should be convertable with u8) for rust---It can not be compiled finally.

But even it is compiled ,like with u32 or u64, I tested out without expectation, find that users should be careful on the number value parsed between dart and rust. Otherwise, the calculation would either be stackoverflow or cutted. And range of Int from official dart documentation is not clear--- I am not sure whether it is in range [ -2^53,-2^53] or [ -2^63, 2^63].

@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 28, 2022

And range of Int from official dart documentation is not clear--- I am not sure whether it is in range [ -2^53,-2^53] or [ -2^63, 2^63].

If I remember correctly: 53 for web, 64 for others

@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 28, 2022

For other problems, what about raising separate issues, since those problems are unrelated to the current title - so future readers may be hard to find the information

@dbsxdbsx
Copy link
Contributor Author

For other problems, what about raising separate issues, since those problems are unrelated to the current title - so future readers may be hard to find the information

@fzyzcjy, I've put the flutter run bug here, for another, as I said, if I reproduced it , I would post it.

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants