Created
March 3, 2021 13:18
-
-
Save edward1986/6c4daaa27056ee7d7f30a00496f0cd7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.red, | |
), | |
home: MyHomePage(title: 'Epic Page Is Amazing'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
static const platform = const MethodChannel('com.flutter.epic/epic'); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Container( | |
child: Column( | |
children: <Widget>[ | |
RaisedButton( | |
child: Text("Reverse"), | |
onPressed: () { | |
Printy(); | |
}, | |
), | |
], | |
) | |
) | |
); | |
} | |
void Printy() async { | |
String value; | |
try { | |
value = await platform.invokeMethod("Printy"); | |
} catch (e) { | |
print(e); | |
} | |
print(value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.calljava_app; | |
import android.os.Bundle; | |
import androidx.annotation.NonNull; | |
import io.flutter.app.FlutterActivity; | |
import io.flutter.embedding.engine.FlutterEngine; | |
import io.flutter.plugin.common.MethodCall; | |
import io.flutter.plugin.common.MethodChannel; | |
import io.flutter.plugins.GeneratedPluginRegistrant; | |
public class MainActivity extends FlutterActivity { | |
private static final String CHANNEL = "com.flutter.epic/epic"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
GeneratedPluginRegistrant.registerWith(new FlutterEngine(this)); | |
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(new MethodChannel.MethodCallHandler() { | |
@Override | |
public void onMethodCall(MethodCall methodCall, @NonNull MethodChannel.Result result) { | |
if (methodCall.method.equals("Printy")) { | |
result.success("Hi From Java"); | |
} | |
} | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment