|
|
@@ -1,5 +1,4 @@
|
|
|
import 'package:electronic_assistant/base/base_controller.dart';
|
|
|
-import 'package:flutter/widgets.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
|
|
@@ -13,30 +12,27 @@ class BrowserController extends BaseController {
|
|
|
@override
|
|
|
void onInit() {
|
|
|
super.onInit();
|
|
|
+ _initWebSetting();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ void onReady() {
|
|
|
+ super.onReady();
|
|
|
+ _loadUrl();
|
|
|
+ }
|
|
|
+
|
|
|
+ void _initWebSetting() {
|
|
|
+ webViewController.setJavaScriptMode(JavaScriptMode.unrestricted);
|
|
|
webViewController.setNavigationDelegate(
|
|
|
NavigationDelegate(
|
|
|
onPageFinished: (String url) {
|
|
|
- webViewController.getTitle().then((title) {
|
|
|
- if (title != null) {
|
|
|
- this.title.value = title;
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- onNavigationRequest: (NavigationRequest request) {
|
|
|
- return NavigationDecision.navigate;
|
|
|
+ _getTitle();
|
|
|
},
|
|
|
),
|
|
|
);
|
|
|
- webViewController.setJavaScriptMode(JavaScriptMode.unrestricted);
|
|
|
- }
|
|
|
-
|
|
|
- @override
|
|
|
- void onReady() {
|
|
|
- super.onReady();
|
|
|
- loadUrl();
|
|
|
}
|
|
|
|
|
|
- void loadUrl() {
|
|
|
+ void _loadUrl() {
|
|
|
if (url.isEmpty) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -50,4 +46,13 @@ class BrowserController extends BaseController {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ void _getTitle() async {
|
|
|
+ await Future.delayed(const Duration(milliseconds: 500));
|
|
|
+ webViewController.getTitle().then((title) {
|
|
|
+ if (title != null) {
|
|
|
+ this.title.value = title;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|