Skip to content

Instantly share code, notes, and snippets.

View robertohuertasm's full-sized avatar
🦀
friendly rustacean

Roberto Huertas robertohuertasm

🦀
friendly rustacean
View GitHub Profile
@robertohuertasm
robertohuertasm / main.dart
Created July 15, 2020 17:19
futures catchError dartpub
void main() async {
var f = Future.delayed(Duration(milliseconds: 500), () => 'Hola').then((_) => throw Exception('WTF'));
await f.catchError(handleError);
// await f;
print('Exiting main');
}
void handleError(e) {
print(e);
}
@robertohuertasm
robertohuertasm / rusty_flutter_lib.dart
Created November 3, 2019 12:23
rust_for_android_ios_flutter
static Future<String> hello({to: String}) async {
final String greetings = await _channel.invokeMethod('hello', {'to': to});
return greetings;
}
@robertohuertasm
robertohuertasm / import_ios_code.sh
Created November 3, 2019 12:22
rust_for_android_ios_flutter
# copy the header to the Classes folder
cp ../rust/rustylib.h ios/Classes
# create a new libs folder
mkdir ios/libs
# copy the universal library into the libs folder
cp ../rust/target/universal/release/librustylib.a ios/libs/
@robertohuertasm
robertohuertasm / android_build.gradle
Created November 3, 2019 12:21
rust_for_android_ios_flutter
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// this is the line to add including the directory holding our .aar package:
implementation fileTree(include: '*.aar', dir: 'rusty-android-lib-release')
}
@robertohuertasm
robertohuertasm / create_flutter_project.sh
Created November 3, 2019 12:19
rust_for_android_ios_flutter
# let's use the flutter folder
cd flutter
# create a plugin project, set its namespace and its name
flutter create --template=plugin --org com.robertohuertas rusty_flutter_lib
# now you'll have a folder called rusty_flutter_lib inside the flutter folder
# for convenience, we'll move everything to the parent directory (flutter)
# this last step is completely optional.
mv rusty_flutter_lib/{.,}* .
@robertohuertasm
robertohuertasm / build.gradle
Created November 3, 2019 12:18
rust_for_android_ios_flutter
dependencies {
implementation project(':rusty-android-lib')
}
@robertohuertasm
robertohuertasm / lib.rs
Created November 3, 2019 12:17
rust_for_android_ios_flutter
// add it below the use declarations.
#[cfg(target_os = "android")]
mod android;
@robertohuertasm
robertohuertasm / android_top.rs
Created November 3, 2019 12:16
rust_for_android_ios_flutter
#![cfg(target_os = "android")]
#![allow(non_snake_case)]
@robertohuertasm
robertohuertasm / create_android_rs.sh
Created November 3, 2019 12:15
rust_for_android_ios_flutter
cd rust/src
echo > android.rs
@robertohuertasm
robertohuertasm / ios_binary.sh
Created November 3, 2019 12:13
rust_for_android_ios_flutter
# we're still in the `rust` folder so…
inc=../ios/include
libs=../ios/libs
mkdir ${inc}
mkdir ${libs}
cp rustylib.h ${inc}
cp target/universal/release/librustylib.a ${libs}