Skip to content

Instantly share code, notes, and snippets.

@felangel felangel/text_view.dart
Last active Sep 7, 2018

What would you like to do?
[platform_views] TextView
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
typedef void TextViewCreatedCallback(TextViewController controller);
class TextView extends StatefulWidget {
const TextView({
Key key,
}) : super(key: key);
final TextViewCreatedCallback onTextViewCreated;
State<StatefulWidget> createState() => _TextViewState();
class _TextViewState extends State<TextView> {
Widget build(BuildContext context) {
if (defaultTargetPlatform == {
return AndroidView(
viewType: 'plugins.felix.angelov/textview',
onPlatformViewCreated: _onPlatformViewCreated,
return Text(
'$defaultTargetPlatform is not yet supported by the text_view plugin');
void _onPlatformViewCreated(int id) {
if (widget.onTextViewCreated == null) {
widget.onTextViewCreated(new TextViewController._(id));
class TextViewController {
TextViewController._(int id)
: _channel = new MethodChannel('plugins.felix.angelov/textview_$id');
final MethodChannel _channel;
Future<void> setText(String text) async {
assert(text != null);
return _channel.invokeMethod('setText', text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.