尝试 添加了 windows 端的插件
This commit is contained in:
parent
9ac7462523
commit
cef3227375
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:web_synchronization_tool/main_page.dart';
|
import 'package:web_synchronization_tool/main_page.dart';
|
||||||
|
import 'package:web_synchronization_tool/windows/windows_main_page.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
|
|
@ -18,6 +19,7 @@ class MyApp extends StatelessWidget {
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
),
|
),
|
||||||
home: const MainPage(),
|
home: const MainPage(),
|
||||||
|
// home: const WindowsPage(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,152 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'windows_web_page.dart';
|
||||||
|
import 'package:webview_windows/webview_windows.dart';
|
||||||
|
|
||||||
|
import '../JavaScriptString.dart';
|
||||||
|
|
||||||
|
class WindowsPage extends StatefulWidget {
|
||||||
|
const WindowsPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<WindowsPage> createState() => _WindowsPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _WindowsPageState extends State<WindowsPage> {
|
||||||
|
final mainController = WebviewController();
|
||||||
|
final controller = WebviewController();
|
||||||
|
|
||||||
|
bool initDone = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
controllerInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future controllerInit() async {
|
||||||
|
await mainController.initialize();
|
||||||
|
await controller.initialize();
|
||||||
|
|
||||||
|
mainController.clearCache();
|
||||||
|
mainController.clearCookies();
|
||||||
|
controller.clearCache();
|
||||||
|
controller.clearCookies();
|
||||||
|
|
||||||
|
|
||||||
|
mainController.loadUrl('http://www.df6831.com/');
|
||||||
|
controller.loadUrl('http://www.df6831.com/');
|
||||||
|
|
||||||
|
addClickEventJS();
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
initDone = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 注入点击监听
|
||||||
|
addClickEventJS() {
|
||||||
|
|
||||||
|
controller.executeScript('document.documentElement.innerHTML').then((value){
|
||||||
|
print(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
mainController.addScriptToExecuteOnDocumentCreated(
|
||||||
|
JavaScriptString.clickEventkJSString).then((value){
|
||||||
|
print(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (initDone == false) return Container();
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
body: Column(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
height: 50,
|
||||||
|
color: Colors.white,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
controller.executeScript(
|
||||||
|
JavaScriptString.clickJSString(600, 280)).then((value){
|
||||||
|
print(value);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: const Text('模拟点击测试')),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
mainController
|
||||||
|
.executeScript(JavaScriptString.inputJsString(45));
|
||||||
|
controller
|
||||||
|
.executeScript(JavaScriptString.inputJsString(45));
|
||||||
|
},
|
||||||
|
child: const Text('模拟输入测试')),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
mainController.loadUrl('http://www.df6831.com/game/');
|
||||||
|
// controller.loadUrl('http://www.df6831.com/game/');
|
||||||
|
},
|
||||||
|
child: const Text('跳转')),
|
||||||
|
const SizedBox(
|
||||||
|
width: 50,
|
||||||
|
child: TextField(
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
decoration: InputDecoration(prefixText: '网页数量'),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// pageViewWidget()
|
||||||
|
Expanded(child: pageViewWidget()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget pageViewWidget() {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: WindowsWebWidget(
|
||||||
|
controller: mainController,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: WindowsWebWidget(
|
||||||
|
controller: controller,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class KeepAlivePage extends StatefulWidget {
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
KeepAlivePage({super.key, required this.child});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_KeepAlivePageState createState() => _KeepAlivePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _KeepAlivePageState extends State<KeepAlivePage>
|
||||||
|
with AutomaticKeepAliveClientMixin {
|
||||||
|
@override
|
||||||
|
bool get wantKeepAlive => true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
super.build(context);
|
||||||
|
return widget.child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:webview_windows/webview_windows.dart';
|
||||||
|
|
||||||
|
class WindowsWebWidget extends StatefulWidget {
|
||||||
|
WindowsWebWidget({super.key, required this.controller});
|
||||||
|
final WebviewController controller;
|
||||||
|
@override
|
||||||
|
State<WindowsWebWidget> createState() => _WindowsWebWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _WindowsWebWidgetState extends State<WindowsWebWidget> {
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return inWindowsWebView();
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget inWindowsWebView(){
|
||||||
|
return Webview(widget.controller,);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -13,7 +13,7 @@ dependencies:
|
||||||
|
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
flutter_inappwebview: ^6.0.0
|
flutter_inappwebview: ^6.0.0
|
||||||
webview_dart: ^1.0.1
|
webview_windows: ^0.4.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue