Skip to content

Instantly share code, notes, and snippets.

@neiljaywarner
Created March 29, 2019 16:31
Show Gist options
  • Save neiljaywarner/2f88af27658ba2a2be46231527c12e4c to your computer and use it in GitHub Desktop.
Save neiljaywarner/2f88af27658ba2a2be46231527c12e4c to your computer and use it in GitHub Desktop.
MainActivity.java for add2app scenario with 'custom' plugin internal to package and regular plugin
package com.example.fluttergetstringdriver;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.FrameLayout;
import io.flutter.app.FlutterPluginRegistry;
import io.flutter.facade.Flutter;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.view.FlutterView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FlutterView flutterView = Flutter.createView(MainActivity.this, getLifecycle(), "route1");
FlutterPluginRegistry flutterPluginRegistry = flutterView.getPluginRegistry();
GeneratedPluginRegistrant.registerWith(flutterPluginRegistry);
//NOTE: This name should match canonical name of the plugin.
GetStringPlugin.registerWith(flutterPluginRegistry.registrarFor("com.example.fluttergetstringdriver.GetStringPlugin"));
FrameLayout.LayoutParams layout = new FrameLayout.LayoutParams(600, 800);
layout.leftMargin = 10;
layout.topMargin = 50;
addContentView(flutterView, layout);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment