38 lines
1.0 KiB
Dart
38 lines
1.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
typedef NutPlayerAndroidViewCreatedCallback = void Function(
|
|
NutPlayerAndroidViewController controller);
|
|
|
|
class NutPlayerAndroid extends StatelessWidget {
|
|
final NutPlayerAndroidViewCreatedCallback onMapViewCreated;
|
|
|
|
const NutPlayerAndroid({Key? key, required this.onMapViewCreated})
|
|
: super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AndroidView(
|
|
viewType: 'nut_player_android_view',
|
|
onPlatformViewCreated: _onPlatformViewCreated,
|
|
);
|
|
}
|
|
|
|
void _onPlatformViewCreated(int id) =>
|
|
onMapViewCreated(NutPlayerAndroidViewController._(id));
|
|
}
|
|
|
|
class NutPlayerAndroidViewController {
|
|
NutPlayerAndroidViewController._(int id)
|
|
: _channel = MethodChannel('nut_player_android_view_$id');
|
|
|
|
final MethodChannel _channel;
|
|
|
|
Future<void> setUrl({required String url}) async {
|
|
return _channel.invokeMethod('setUrl', url);
|
|
}
|
|
|
|
Future<void> play() async {
|
|
_channel.invokeMethod('play');
|
|
}
|
|
} |