Skip to content

Commit

Permalink
Use http for the fetching example
Browse files Browse the repository at this point in the history
  • Loading branch information
temeddix committed Nov 3, 2023
1 parent 7090fdd commit e9efd52
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub async fn run_debug_tests() {
crate::debug_print!("System time: {current_time}");

// Fetch data from a web API.
let url = "https://jsonplaceholder.typicode.com/todos/1";
let url = "http://jsonplaceholder.typicode.com/todos/1";
let web_response = sample_crate::fetch_from_web_api(url).await;
crate::debug_print!("Response from a web API: {web_response}");

Expand Down
4 changes: 1 addition & 3 deletions flutter_ffi_plugin/example/native/sample_crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ edition = "2021"
[target.'cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))'.dependencies]
machineid-rs = "1.2.4"

[target.'cfg(not(any(target_os = "android")))'.dependencies]
reqwest = "0.11.22"

[dependencies]
num = "0.4"
image = "0.24.3"
chrono = "0.4.31"
reqwest = { version = "0.11.22", default-features = false }
13 changes: 1 addition & 12 deletions flutter_ffi_plugin/example/native/sample_crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,7 @@ pub fn get_current_time() -> DateTime<offset::Local> {
}

// `reqwest` supports all platforms, including web.
// However, compiling it for Android on Windows can be challenging
// due to its dependency on the `openssl-sys` crate,
// which requires the corresponding C library to be installed on the system.
// Compiling `reqwest` for Android is possible with the right system setup,
// but it's intentionally disabled in our sample crate
// to ensure that the example app 'just works'.

#[cfg(any(target_os = "android"))]
pub async fn fetch_from_web_api(url: &str) -> String {
String::from("API fetching is disabled on this platform.")
}
#[cfg(not(any(target_os = "android")))]

pub async fn fetch_from_web_api(url: &str) -> String {
reqwest::get(url)
.await
Expand Down

0 comments on commit e9efd52

Please sign in to comment.