Giter Site home page Giter Site logo

method-channels's Introduction

Flutter MethodChannel Example

This repository contains examples of how to use MethodChannel in Flutter to communicate between the Flutter part and native code (Android in this case).

Description

Step 1: Get Platform Version

  • Create a MethodChannel named "platform_version".
  • Invoke the native method to obtain the platform version.
  • Display the result in an AlertDialog.

Step 2: Data Channel ("dataChannel")

  • Create a MethodChannel named "data_channel".
  • Define a method in native code to receive a string from Flutter and return it concatenated with "- Native".
  • From Flutter, send the string "Hello Flutter" to native code through the channel.
  • Display the response on the user interface.

Step 3: Bidirectional Channel ("bidirectionalChannel")

  • Implement a bidirectional MethodChannel named "bidirectional_channel".
  • Define two methods in native code: flutterToNative and nativeToFlutter.
  • From Flutter, invoke the flutterToNative method and send a string.
  • From native code, invoke the nativeToFlutter method and send a different string.
  • Display both strings on the user interface.

Running Tests

To run unit tests that verify the MethodChannel functionality, follow these steps:

  1. Open a terminal in the project's root directory.
  2. Execute the following command:
flutter test

Screenshots

Home Bidirectional Platform Version
Home Bidirectional PV

Author

๐Ÿ‘ค Rogelio Torres

method-channels's People

Contributors

kelevra9900 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.