Build Your Own Flutter Plugin Using Android Native Kotlin — Part II

Build Your Own Flutter Plugin Using Android Native Kotlin — Part II

In the part I of this tutorial, we’ve explained how to initiate a Flutter Plugin project in IntelliJ IDEA, and what does a Flutter Plugin template look like. Build Your Own Flutter Plugin Using Android Native Kotlin — Part II.

In the part I of this tutorial, we’ve explained how to initiate a Flutter Plugin project in IntelliJ IDEA, and what does a Flutter Plugin template look like.

Next, we are going to complete the content of codes to bring the Flutter API and the MIDI keyboard app to live. The file structures were introduced in the Part I tutorial, please refer to  part I tutorial.

piano.dart

Let’s start from the Flutter API piano.dart under the lib. Again, this will be your Flutter API interface, which defines all the callable functions for your clients to call:

import 'dart:async';
import 'package:flutter/services.dart';

class Piano {
  static const MethodChannel _channel =                     // 1
      const MethodChannel("piano");
static Future<String?> get platformVersion async {          // 2
    final String? version = await _channel.invokeMethod('getPlatformVersion');                // 3
    return version;                                         // 4
  }
static Future<int?> onKeyDown(int key) async {              // 2
    final int? numNotesOn = await _channel.invokeMethod('onKeyDown', [key]);                  // 3
    return numNotesOn;                                      // 4
  }
static Future<int?> onKeyUp(int key) async {                // 2
    final int? numNotesOn = await 
_channel.invokeMethod('onKeyUp', [key]);                    // 3
    return numNotesOn;                                      // 4
  }
}

Note: The_question mark_ in the dart syntax is supporting  Null Safety dart version. Basically it’s a stricter type check, which requires you to explicitly identify the type can be ‘int’ or ‘null’, e.g., int?

flutter-plugin flutter android-app-development

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

Hire Dedicated Flutter App Developer USA| Flutter App Developers

Hire dedicated Flutter App Development services and reap the benefits of cost effective cross-platform app development services for your business as one needs manage single code base for all platforms.

Flutter App Development Company India, Flutter App Developers for Hire

IndianAppDevelopers offers Flutter app development services in India for Android and iOS, Hire our flutter developers to create native experience apps for the end-users.

Best Flutter App Development Company

AppClues Infotech is a top Mobile App Development Company in USA building high-quality Android, iOS, and Native apps for Startups, SMBs, & Enterprises. Contact us now!

Top Android App Development Company | Android App Development Services

WebClues Infotech provides custom android app development services using the latest Android SDKs. Our team of Android developers expert in Java & Kotlin languages.