Created
November 3, 2019 11:11
-
-
Save robertohuertasm/b3e57549578d5cc704602d8193ca77a5 to your computer and use it in GitHub Desktop.
rust_for_android_ios_flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'dart:async'; | |
import 'package:flutter/services.dart'; | |
import 'package:rusty_flutter_lib/rusty_flutter_lib.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
String _platformVersion = 'Unknown'; | |
String _greeting = ''; | |
@override | |
void initState() { | |
super.initState(); | |
initPlatformState(); | |
} | |
// Platform messages are asynchronous, so we initialize in an async method. | |
Future<void> initPlatformState() async { | |
String platformVersion; | |
String greeting; | |
// Platform messages may fail, so we use a try/catch PlatformException. | |
try { | |
platformVersion = await RustyFlutterLib.platformVersion; | |
greeting = await RustyFlutterLib.hello(to: 'Rob'); | |
} on PlatformException { | |
platformVersion = 'Failed to get platform version.'; | |
greeting = 'Failed to get hello'; | |
} | |
// If the widget was removed from the tree while the asynchronous platform | |
// message was in flight, we want to discard the reply rather than calling | |
// setState to update our non-existent appearance. | |
if (!mounted) return; | |
setState(() { | |
_platformVersion = platformVersion; | |
_greeting = greeting; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
title: const Text('Plugin example app'), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
_greeting, | |
style: TextStyle(fontSize: 20), | |
), | |
Text('Running on: $_platformVersion\n'), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment