项目作者: Mindinventory

项目描述 :
Flutter + Kotlin Usage Tutorial
高级语言: Kotlin
项目地址: git://github.com/Mindinventory/Flutlin.git
创建时间: 2019-05-07T12:24:38Z
项目社区:https://github.com/Mindinventory/Flutlin

开源协议:MIT License

下载


N|SolidN|SolidN|Solid

N|Solid

Flutter + Kotlin (Flutlin)

Aim

To find out the way to utilize flutter UI design benefits while on logical tasks like rest api calling with Kotlin.

  • UI design in Flutter
  • Rest api calling with Retrofit in Kotlin.

Tech

Steps to follow to use Flutter View

1) Create Flutter Project.
2) Open android project in Android Studio.

  1. * Create your own layout for your activity and add simple `FlutterView`
  2. ```
  3. <io.flutter.view.FlutterView
  4. android:id="@+id/flutter_view"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent" ></io.flutter.view.FlutterView>
  7. * Need some initialisation for flutter as per below:
  8. ```
  9. val args = getArgsFromIntent(intent)
  10. FlutterMain.ensureInitializationComplete(applicationContext, args)
  11. * Create `FlutterRunArguments`, provide context and entry point of dart for that view.
  12. ```
  13. val runArguments = FlutterRunArguments()
  14. runArguments.bundlePath = FlutterMain.findAppBundlePath(applicationContext)
  15. runArguments.entrypoint = "main"
  16. * Bind your `FlutterView`
  17. ```
  18. flutterView = findViewById(R.id.flutter_view)
  19. flutterView!!.runFromBundle(runArguments)
  20. * User any channel to communicate with your dart file and activity. In our case, I have used `BasicMessageChannel` to pass string as response.
  21. ```
  22. messageChannel = BasicMessageChannel(flutterView, CHANNEL, StringCodec.INSTANCE)
  23. messageChannel?.send(message)
  24. * Close android project.

3) Open Flutter Project.

  1. * Initialise `BasicMessageChannel` channel which will be helpful to fetch data shared in our Actitivy.
  2. ```
  3. static const BasicMessageChannel<String> platform =
  4. BasicMessageChannel<String>(_channel, StringCodec());
  5. * Register callback in your `initState()` widget
  6. ```
  7. platform.setMessageHandler(_handlePlatformMessage);
  8. * Create method as per below through which you can parse your string into response model and that you can use to reflect in UI.
  9. ```
  10. Future<String> _handlePlatformMessage(String message) async {
  11. // use setState() to reflect the message in your ui.
  12. }

LICENSE!

Flutlin is MIT-licensed.

Let us know!

We’d be really happy if you send us links to your projects where you use our component. Just send an email to sales@mindinventory.com And do let us know if you have any questions or suggestion regarding our work.