Method Channel Default Android Folder

Method Channel Default Android Folder :

Screenshot :

Method Channel Default Android Folder

MainActivity.kt

package com.jdkgroup.methodchannel

import android.os.Bundle
import io.flutter.app.FlutterActivity
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity : FlutterActivity() {
  private val channel = "method_channel_plugin"
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    GeneratedPluginRegistrant.registerWith(this)

    MethodChannel(flutterView, channel).setMethodCallHandler { methodCall, result ->
      if (methodCall.method == "getMetaData") {
        result.success("www.fluttertutorial.in")
      }
      if (methodCall.method == "getTitle") {
        result.success("Flutter Tutorial")
      }
    }
  }
}

main.dart

import 'dart:async';

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final platform = MethodChannel("method_channel_plugin");
  String valueStore;
  final StreamController<String> _streamController = StreamController<String>();

  @override
  void initState() {
    /*getData().then((value) {
      valueStore = value;
    }, onError: (error) {});*/

    getData();
    super.initState();
  }

  Future getData() async {
    var value;
    try {
      value = await platform.invokeMethod("getMetaData");
      _streamController.add(value);
    } catch (e) {}
    return value;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("Flutter Tutorial"),
        ),
        body: StreamBuilder<String>(
            stream: _streamController.stream,
            builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
              if (!snapshot.hasData) {
                return Container();
              }
              return Center(
                  child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                    Text(snapshot.data),
                  ]));
            }));
  }
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in