android 初版
This commit is contained in:
commit
9ac7462523
|
|
@ -0,0 +1,49 @@
|
|||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
.DS_Store
|
||||
.atom/
|
||||
.buildlog/
|
||||
.history
|
||||
.svn/
|
||||
migrate_working_dir/
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
# The .vscode folder contains launch configuration and tasks you configure in
|
||||
# VS Code which you may wish to be included in version control, so this line
|
||||
# is commented out by default.
|
||||
#.vscode/
|
||||
|
||||
# Flutter/Dart/Pub related
|
||||
**/doc/api/
|
||||
**/ios/Flutter/.last_build_id
|
||||
.dart_tool/
|
||||
.flutter-plugins
|
||||
.flutter-plugins-dependencies
|
||||
.pub-cache/
|
||||
.pub/
|
||||
/build/
|
||||
|
||||
# Symbolication related
|
||||
app.*.symbols
|
||||
|
||||
# Obfuscation related
|
||||
app.*.map.json
|
||||
|
||||
# Android Studio will place build artifacts here
|
||||
/android/app/debug
|
||||
/android/app/profile
|
||||
/android/app/release
|
||||
windows/
|
||||
android/
|
||||
test/widget_test.dart
|
||||
pubspec.lock
|
||||
.metadata
|
||||
analysis_options.yaml
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
# web_synchronization_tool
|
||||
|
||||
A new Flutter project.
|
||||
|
||||
## Getting Started
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
|
||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||
|
||||
For help getting started with Flutter development, view the
|
||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
class JavaScriptString {
|
||||
/// 点击监听
|
||||
static String clickEventkJSString =
|
||||
'''document.addEventListener('click', function(event) {
|
||||
var x = event.clientX;
|
||||
var y = event.clientY;
|
||||
|
||||
console.log('点击坐标:x=' + x + ', y=' + y);
|
||||
window.flutter_inappwebview.callHandler('Click', x, y);
|
||||
|
||||
});''';
|
||||
|
||||
/// 模拟点击
|
||||
static String clickJSString(int x, int y) {
|
||||
return 'document.elementFromPoint($x, $y).click();';
|
||||
}
|
||||
|
||||
/// 输入
|
||||
static String inputJsString(int value) {
|
||||
return '''
|
||||
|
||||
var inputEvent = new Event('input', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
});
|
||||
|
||||
var inputElement = document.querySelector(".bet-money");
|
||||
|
||||
inputElement.value = "$value";
|
||||
|
||||
inputElement.dispatchEvent(inputEvent);
|
||||
|
||||
''';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:web_synchronization_tool/main_page.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MainPage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:web_synchronization_tool/web_widget.dart';
|
||||
|
||||
import 'JavaScriptString.dart';
|
||||
|
||||
class MainPage extends StatefulWidget {
|
||||
const MainPage({super.key});
|
||||
|
||||
@override
|
||||
State<MainPage> createState() => _MainPageState();
|
||||
}
|
||||
|
||||
class _MainPageState extends State<MainPage> {
|
||||
|
||||
late InAppWebViewController mainController;
|
||||
late InAppWebViewController controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// 注入点击监听
|
||||
addClickEventJS(){
|
||||
|
||||
final clickJsUS = UserScript(groupName: 'click',source: JavaScriptString.clickEventkJSString, injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START);
|
||||
|
||||
mainController.addUserScript(userScript: clickJsUS);
|
||||
|
||||
mainController.addJavaScriptHandler(handlerName: 'Click', callback: (args){
|
||||
controller.evaluateJavascript(source: JavaScriptString.clickJSString(args.first, args.last) );
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 50,
|
||||
color: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
child: Row(
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
controller.evaluateJavascript(source: JavaScriptString.clickJSString(600, 280) );
|
||||
},
|
||||
child: const Text('模拟点击测试')),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
mainController.evaluateJavascript(source: JavaScriptString.inputJsString(45) );
|
||||
controller.evaluateJavascript(source: JavaScriptString.inputJsString(45) );
|
||||
},
|
||||
child: const Text('模拟输入测试')),
|
||||
const SizedBox(
|
||||
width: 50,
|
||||
child: TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: InputDecoration(prefixText: '网页数量'),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(child: pageViewWidget()),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget pageViewWidget() {
|
||||
return PageView(
|
||||
children: <Widget>[
|
||||
KeepAlivePage(
|
||||
child: WebWidget(controlerCallBack: (_mainController) {
|
||||
mainController = _mainController;
|
||||
|
||||
addClickEventJS();
|
||||
}),
|
||||
),
|
||||
KeepAlivePage(
|
||||
child: WebWidget(controlerCallBack: (_controller) {
|
||||
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,31 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:web_synchronization_tool/JavaScriptString.dart';
|
||||
|
||||
class WebWidget extends StatefulWidget {
|
||||
WebWidget({super.key, required this.controlerCallBack});
|
||||
|
||||
final Function(InAppWebViewController) controlerCallBack;
|
||||
|
||||
@override
|
||||
State<WebWidget> createState() => _WebWidgetState();
|
||||
}
|
||||
|
||||
class _WebWidgetState extends State<WebWidget> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InAppWebView(
|
||||
initialUrlRequest:
|
||||
URLRequest(url: WebUri('http://www.df6831.com/game/')),
|
||||
initialSettings: InAppWebViewSettings(initialScale: 200,loadWithOverviewMode: false,useWideViewPort: false),
|
||||
onWebViewCreated: (_controller) {
|
||||
widget.controlerCallBack(_controller);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
name: web_synchronization_tool
|
||||
description: "A new Flutter project."
|
||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: '>=3.2.3 <4.0.0'
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
cupertino_icons: ^1.0.2
|
||||
flutter_inappwebview: ^6.0.0
|
||||
webview_dart: ^1.0.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
flutter_lints: ^2.0.0
|
||||
|
||||
flutter:
|
||||
|
||||
uses-material-design: true
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/assets-and-images/#resolution-aware
|
||||
|
||||
# For details regarding adding assets from package dependencies, see
|
||||
# https://flutter.dev/assets-and-images/#from-packages
|
||||
|
||||
# To add custom fonts to your application, add a fonts section here,
|
||||
# in this "flutter" section. Each entry in this list should have a
|
||||
# "family" key with the font family name, and a "fonts" key with a
|
||||
# list giving the asset and other descriptors for the font. For
|
||||
# example:
|
||||
# fonts:
|
||||
# - family: Schyler
|
||||
# fonts:
|
||||
# - asset: fonts/Schyler-Regular.ttf
|
||||
# - asset: fonts/Schyler-Italic.ttf
|
||||
# style: italic
|
||||
# - family: Trajan Pro
|
||||
# fonts:
|
||||
# - asset: fonts/TrajanPro.ttf
|
||||
# - asset: fonts/TrajanPro_Bold.ttf
|
||||
# weight: 700
|
||||
#
|
||||
# For details regarding fonts from package dependencies,
|
||||
# see https://flutter.dev/custom-fonts/#from-packages
|
||||
Loading…
Reference in New Issue