Last active
September 7, 2018 05:39
-
-
Save felangel/412ec9e55c1282aecd9411684ebb9037 to your computer and use it in GitHub Desktop.
[platform_views] TextView
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 '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, | |
this.onTextViewCreated, | |
}) : super(key: key); | |
final TextViewCreatedCallback onTextViewCreated; | |
@override | |
State<StatefulWidget> createState() => _TextViewState(); | |
} | |
class _TextViewState extends State<TextView> { | |
@override | |
Widget build(BuildContext context) { | |
if (defaultTargetPlatform == TargetPlatform.android) { | |
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) { | |
return; | |
} | |
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