Flutter plugin for mofun flutter video.

mofun_video_view.dart 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import 'dart:async';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter/widgets.dart';
  5. typedef void MofunVideoViewCreatedCallback(MofunVideoViewController controller);
  6. const _CHANNEL = 'plugins.shuangyunbang.mofun/mofunvideoview';
  7. class MofunVideoView extends StatefulWidget {
  8. final MofunVideoViewCreatedCallback onMofunVideoViewCreated;
  9. const MofunVideoView({
  10. Key key,
  11. this.onMofunVideoViewCreated,
  12. }) : super(key: key);
  13. @override
  14. State<StatefulWidget> createState() {
  15. return _MofunVideoViewState();
  16. }
  17. }
  18. class _MofunVideoViewState extends State<MofunVideoView> {
  19. @override
  20. Widget build(BuildContext context) {
  21. if (defaultTargetPlatform == TargetPlatform.android) {
  22. return AndroidView(
  23. viewType: _CHANNEL,
  24. onPlatformViewCreated: _onPlatformViewCreated,
  25. );
  26. }else if (defaultTargetPlatform == TargetPlatform.iOS) {
  27. return UiKitView(
  28. viewType: _CHANNEL,
  29. onPlatformViewCreated: _onPlatformViewCreated,
  30. );
  31. }
  32. return Text(
  33. '$defaultTargetPlatform is not yet supported by the text_view plugin');
  34. }
  35. void _onPlatformViewCreated(int id) {
  36. if (widget.onMofunVideoViewCreated == null) {
  37. return;
  38. }
  39. widget.onMofunVideoViewCreated(new MofunVideoViewController._(id));
  40. }
  41. }
  42. class MofunVideoViewController {
  43. MofunVideoViewController._(int id)
  44. : _channel = new MethodChannel('${_CHANNEL}_$id');
  45. final MethodChannel _channel;
  46. Future<void> setText(String text) async {
  47. assert(text != null);
  48. return _channel.invokeMethod('setText', text);
  49. }
  50. }