Desdaemon / flutter_rust_bridge_template

Template for Flutter + Rust integration with flutter_rust_bridge.
https://desdaemon.github.io/flutter_rust_bridge_template/
Apache License 2.0
120 stars 63 forks source link

wasm http-request doesn't return #48

Closed wgtun closed 1 year ago

wgtun commented 1 year ago

Hello, I would like to ask a question, I added a http request code, the mobile is normal, but the web does not return, I want to know where is my problem, web http request code like this:

use gloo_net::http::{Headers, Request};
#[tokio::main(flavor = "current_thread")]
pub fn request(params: MyRequest) -> Result<String> {
            let headers = get_web_default_headers().unwrap();
            for header in &params.headers {
                headers.set(&header.key, &header.value);
            }
            let result = Request::get(&params.url).headers(headers).send().await?;
            Ok(result.text().await?)
}
Desdaemon commented 1 year ago

You'll need to use #[cfg] attributes to enable Tokio only for non-web users and wasm-bindgen-futures for web users. Also I'll open discussions so common questions like this can be collected in one place.