Created
September 7, 2018 05:48
-
-
Save felangel/e84d8c6986e01f1b4f57f5e9649d4fed to your computer and use it in GitHub Desktop.
[platform_views] FlutterTextView
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 angelov.felix.textview; | |
import android.content.Context; | |
import android.view.View; | |
import android.widget.TextView; | |
import io.flutter.plugin.common.MethodCall; | |
import io.flutter.plugin.common.MethodChannel; | |
import static io.flutter.plugin.common.MethodChannel.MethodCallHandler; | |
import static io.flutter.plugin.common.MethodChannel.Result; | |
import io.flutter.plugin.common.BinaryMessenger; | |
import io.flutter.plugin.platform.PlatformView; | |
public class FlutterTextView implements PlatformView, MethodCallHandler { | |
private final TextView textView; | |
private final MethodChannel methodChannel; | |
FlutterTextView(Context context, BinaryMessenger messenger, int id) { | |
textView = new TextView(context); | |
methodChannel = new MethodChannel(messenger, "plugins.felix.angelov/textview_" + id); | |
methodChannel.setMethodCallHandler(this); | |
} | |
@Override | |
public View getView() { | |
return textView; | |
} | |
@Override | |
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { | |
switch (methodCall.method) { | |
case "setText": | |
setText(methodCall, result); | |
break; | |
default: | |
result.notImplemented(); | |
} | |
} | |
private void setText(MethodCall methodCall, Result result) { | |
String text = (String) methodCall.arguments; | |
textView.setText(text); | |
result.success(null); | |
} | |
@Override | |
public void dispose() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment