/
first.dart
51 lines (42 loc) · 1.35 KB
/
first.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
typedef FirstWidgetCreatedCallback = void Function(
FirstWidgetController controller);
class FirstWidget extends StatefulWidget {
const FirstWidget({
Key key,
this.onFirstWidgetWidgetCreated,
}) : super(key: key);
final FirstWidgetCreatedCallback onFirstWidgetWidgetCreated;
@override
State<StatefulWidget> createState() => _FirstWidgetState();
}
class _FirstWidgetState extends State<FirstWidget> {
@override
Widget build(BuildContext context) {
if (defaultTargetPlatform == TargetPlatform.android) {
return AndroidView(
viewType: 'plugins/first_widget',
onPlatformViewCreated: _onPlatformViewCreated,
creationParamsCodec: const StandardMessageCodec(),
);
}
return const Text('iOS platform version is not implemented yet.');
}
void _onPlatformViewCreated(int id) {
if (widget.onFirstWidgetWidgetCreated == null) {
return;
}
widget.onFirstWidgetWidgetCreated(FirstWidgetController._(id));
}
}
class FirstWidgetController {
FirstWidgetController._(int id)
: _channel = MethodChannel('plugins/first_widget_$id');
final MethodChannel _channel;
Future<void> ping() async {
return _channel.invokeMethod('ping');
}
}