forked from juicycleff/flutter-unity-view-widget
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathweb_unity_widget_view.dart
More file actions
52 lines (44 loc) · 1.45 KB
/
web_unity_widget_view.dart
File metadata and controls
52 lines (44 loc) · 1.45 KB
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
52
import 'package:flutter/material.dart';
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
// ignore: unused_import
import 'package:webview_flutter_web/webview_flutter_web.dart'; // used indirectly through webview_flutter_platform_interface
class WebUnityWidgetView extends StatefulWidget {
const WebUnityWidgetView({
Key? key,
required this.onWebViewCreated,
required this.unityOptions,
}) : super(key: key);
final Map<String, dynamic> unityOptions;
final void Function() onWebViewCreated;
@override
State<WebUnityWidgetView> createState() => _WebUnityWidgetViewState();
}
class _WebUnityWidgetViewState extends State<WebUnityWidgetView> {
final PlatformWebViewController _controller = PlatformWebViewController(
const PlatformWebViewControllerCreationParams(),
)..loadRequest(
LoadRequestParams(
uri: Uri.parse('${_getBasePath()}/UnityLibrary/index.html'),
),
);
@override
void initState() {
super.initState();
widget.onWebViewCreated();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: _controller),
).build(context);
}
static String _getBasePath() {
var prefix = Uri.base.origin + Uri.base.path;
if (prefix.endsWith("/")) prefix = prefix.substring(0, prefix.length - 1);
return prefix;
}
}