├── LICENSE
├── CHANGELOG.md
├── example
├── ios
│ ├── Runner
│ │ ├── Runner-Bridging-Header.h
│ │ ├── Assets.xcassets
│ │ │ ├── LaunchImage.imageset
│ │ │ │ ├── LaunchImage.png
│ │ │ │ ├── LaunchImage@2x.png
│ │ │ │ ├── LaunchImage@3x.png
│ │ │ │ ├── README.md
│ │ │ │ └── Contents.json
│ │ │ └── AppIcon.appiconset
│ │ │ │ ├── Icon-App-20x20@1x.png
│ │ │ │ ├── Icon-App-20x20@2x.png
│ │ │ │ ├── Icon-App-20x20@3x.png
│ │ │ │ ├── Icon-App-29x29@1x.png
│ │ │ │ ├── Icon-App-29x29@2x.png
│ │ │ │ ├── Icon-App-29x29@3x.png
│ │ │ │ ├── Icon-App-40x40@1x.png
│ │ │ │ ├── Icon-App-40x40@2x.png
│ │ │ │ ├── Icon-App-40x40@3x.png
│ │ │ │ ├── Icon-App-60x60@2x.png
│ │ │ │ ├── Icon-App-60x60@3x.png
│ │ │ │ ├── Icon-App-76x76@1x.png
│ │ │ │ ├── Icon-App-76x76@2x.png
│ │ │ │ ├── Icon-App-1024x1024@1x.png
│ │ │ │ ├── Icon-App-83.5x83.5@2x.png
│ │ │ │ └── Contents.json
│ │ ├── AppDelegate.swift
│ │ ├── Base.lproj
│ │ │ ├── Main.storyboard
│ │ │ └── LaunchScreen.storyboard
│ │ └── Info.plist
│ ├── Flutter
│ │ ├── Debug.xcconfig
│ │ ├── Release.xcconfig
│ │ └── AppFrameworkInfo.plist
│ ├── Runner.xcodeproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ ├── WorkspaceSettings.xcsettings
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ ├── xcshareddata
│ │ │ └── xcschemes
│ │ │ │ └── Runner.xcscheme
│ │ └── project.pbxproj
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ ├── WorkspaceSettings.xcsettings
│ │ │ └── IDEWorkspaceChecks.plist
│ ├── .gitignore
│ ├── Podfile.lock
│ └── Podfile
├── web
│ ├── favicon.png
│ ├── icons
│ │ ├── Icon-192.png
│ │ ├── Icon-512.png
│ │ ├── Icon-maskable-192.png
│ │ └── Icon-maskable-512.png
│ ├── manifest.json
│ └── index.html
├── android
│ ├── gradle.properties
│ ├── app
│ │ ├── src
│ │ │ ├── main
│ │ │ │ ├── res
│ │ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── drawable
│ │ │ │ │ │ └── launch_background.xml
│ │ │ │ │ ├── drawable-v21
│ │ │ │ │ │ └── launch_background.xml
│ │ │ │ │ ├── values
│ │ │ │ │ │ └── styles.xml
│ │ │ │ │ └── values-night
│ │ │ │ │ │ └── styles.xml
│ │ │ │ ├── kotlin
│ │ │ │ │ └── com
│ │ │ │ │ │ └── example
│ │ │ │ │ │ └── example
│ │ │ │ │ │ └── MainActivity.kt
│ │ │ │ └── AndroidManifest.xml
│ │ │ ├── debug
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── profile
│ │ │ │ └── AndroidManifest.xml
│ │ └── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ └── gradle-wrapper.properties
│ ├── .gitignore
│ ├── settings.gradle
│ └── build.gradle
├── .metadata
├── README.md
├── test
│ └── widget_test.dart
├── .gitignore
├── lib
│ ├── tools
│ │ └── local_server_webview_manager.dart
│ ├── main.dart
│ └── web_page.dart
├── analysis_options.yaml
├── pubspec.yaml
└── pubspec.lock
├── analysis_options.yaml
├── .metadata
├── lib
├── tools
│ ├── local_server_status_handler.dart
│ ├── local_server_config_cache.dart
│ ├── local_server_binder.dart
│ ├── local_server_manager.dart
│ └── local_server_downloader.dart
├── local_server_for_webview.dart
└── src
│ ├── model
│ ├── local_server_client_config_item.dart
│ ├── download_service_total_asset_item.dart
│ ├── download_service_item.dart
│ └── local_server_client_config.dart
│ └── services
│ ├── local_server_configuration.dart
│ └── local_server_service.dart
├── test
└── local_server_for_webview_test.dart
├── .gitignore
├── pubspec.yaml
└── README.md
/LICENSE:
--------------------------------------------------------------------------------
1 | TODO: Add your license here.
2 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 0.0.1
2 |
3 | * TODO: Describe initial release.
4 |
--------------------------------------------------------------------------------
/example/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
2 |
--------------------------------------------------------------------------------
/example/web/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/web/favicon.png
--------------------------------------------------------------------------------
/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/example/web/icons/Icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/web/icons/Icon-192.png
--------------------------------------------------------------------------------
/example/web/icons/Icon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/web/icons/Icon-512.png
--------------------------------------------------------------------------------
/example/web/icons/Icon-maskable-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/web/icons/Icon-maskable-192.png
--------------------------------------------------------------------------------
/example/web/icons/Icon-maskable-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/web/icons/Icon-maskable-512.png
--------------------------------------------------------------------------------
/example/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:flutter_lints/flutter.yaml
2 |
3 | # Additional information about this file can be found at
4 | # https://dart.dev/guides/language/analysis-options
5 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.example
2 |
3 | import io.flutter.embedding.android.FlutterActivity
4 |
5 | class MainActivity: FlutterActivity() {
6 | }
7 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EchoPuda/local_server_webview/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 23 08:50:38 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
7 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 7e9793dee1b85a243edd0e06cb1658e98b077561
8 | channel: stable
9 |
10 | project_type: package
11 |
--------------------------------------------------------------------------------
/example/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 7e9793dee1b85a243edd0e06cb1658e98b077561
8 | channel: stable
9 |
10 | project_type: app
11 |
--------------------------------------------------------------------------------
/example/android/.gitignore:
--------------------------------------------------------------------------------
1 | gradle-wrapper.jar
2 | /.gradle
3 | /captures/
4 | /gradlew
5 | /gradlew.bat
6 | /local.properties
7 | GeneratedPluginRegistrant.java
8 |
9 | # Remember to never publicly share your keystore.
10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11 | key.properties
12 | **/*.keystore
13 | **/*.jks
14 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md:
--------------------------------------------------------------------------------
1 | # Launch Screen Assets
2 |
3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory.
4 |
5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
--------------------------------------------------------------------------------
/lib/tools/local_server_status_handler.dart:
--------------------------------------------------------------------------------
1 | abstract class LocalServerStatusHandler {
2 | /// server创建成功
3 | createServerSuccess(int port,String localAddress);
4 | /// server创建失败
5 | createServerFailure(dynamic err);
6 | /// server将要关闭
7 | serverWillCancel();
8 | /// server关闭
9 | serverDidCancel();
10 | /// server 请求失败
11 | requestServerFailure(String path,Object error);
12 | /// server 获取返回资源
13 | dynamic fetchRespondsSources(String path);
14 | }
--------------------------------------------------------------------------------
/example/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4 | def properties = new Properties()
5 |
6 | assert localPropertiesFile.exists()
7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
8 |
9 | def flutterSdkPath = properties.getProperty("flutter.sdk")
10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
12 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable-v21/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchImage.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchImage@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "LaunchImage@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/test/local_server_for_webview_test.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_test/flutter_test.dart';
2 |
3 | import 'package:local_server_for_webview/local_server_for_webview.dart';
4 |
5 | void main() {
6 | test('start local server', () async {
7 | var server = await LocalServerService.instance.startServer('127.0.0.1', 0);
8 | String res = LocalServerService.instance.getLocalServerWebUrl('', '/test/index.html');
9 | expect(res, 'http://127.0.0.1:${server.port}/test/index.html');
10 | });
11 |
12 | test('close local server', () {
13 | LocalServerService.instance.closeServer();
14 | });
15 | }
16 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # example
2 |
3 | A new Flutter project.
4 |
5 | ## Getting Started
6 |
7 | This project is a starting point for a Flutter application.
8 |
9 | A few resources to get you started if this is your first Flutter project:
10 |
11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
13 |
14 | For help getting started with Flutter, view our
15 | [online documentation](https://flutter.dev/docs), which offers tutorials,
16 | samples, guidance on mobile development, and a full API reference.
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 |
12 | # IntelliJ related
13 | *.iml
14 | *.ipr
15 | *.iws
16 | .idea/
17 |
18 | # The .vscode folder contains launch configuration and tasks you configure in
19 | # VS Code which you may wish to be included in version control, so this line
20 | # is commented out by default.
21 | #.vscode/
22 |
23 | # Flutter/Dart/Pub related
24 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
25 | /pubspec.lock
26 | **/doc/api/
27 | .dart_tool/
28 | .packages
29 | build/
30 |
--------------------------------------------------------------------------------
/example/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | // This is a basic Flutter widget test.
2 | //
3 | // To perform an interaction with a widget in your test, use the WidgetTester
4 | // utility that Flutter provides. For example, you can send tap and scroll
5 | // gestures. You can also use WidgetTester to find child widgets in the widget
6 | // tree, read text, and verify that the values of widget properties are correct.
7 |
8 | import 'package:example/tools/local_server_webview_manager.dart';
9 |
10 | import 'package:flutter_test/flutter_test.dart';
11 |
12 | void main() {
13 | test('test init download', () {
14 | LocalServerWebViewManager.instance.initSetting();
15 | });
16 | }
17 |
--------------------------------------------------------------------------------
/example/ios/.gitignore:
--------------------------------------------------------------------------------
1 | **/dgph
2 | *.mode1v3
3 | *.mode2v3
4 | *.moved-aside
5 | *.pbxuser
6 | *.perspectivev3
7 | **/*sync/
8 | .sconsign.dblite
9 | .tags*
10 | **/.vagrant/
11 | **/DerivedData/
12 | Icon?
13 | **/Pods/
14 | **/.symlinks/
15 | profile
16 | xcuserdata
17 | **/.generated/
18 | Flutter/App.framework
19 | Flutter/Flutter.framework
20 | Flutter/Flutter.podspec
21 | Flutter/Generated.xcconfig
22 | Flutter/ephemeral/
23 | Flutter/app.flx
24 | Flutter/app.zip
25 | Flutter/flutter_assets/
26 | Flutter/flutter_export_environment.sh
27 | ServiceDefinitions.json
28 | Runner/GeneratedPluginRegistrant.*
29 |
30 | # Exceptions to above rules.
31 | !default.mode1v3
32 | !default.mode2v3
33 | !default.pbxuser
34 | !default.perspectivev3
35 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.6.10'
3 | repositories {
4 | google()
5 | mavenCentral()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:4.1.0'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | mavenCentral()
18 | }
19 | }
20 |
21 | rootProject.buildDir = '../build'
22 | subprojects {
23 | project.buildDir = "${rootProject.buildDir}/${project.name}"
24 | }
25 | subprojects {
26 | project.evaluationDependsOn(':app')
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/example/ios/Flutter/AppFrameworkInfo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | App
9 | CFBundleIdentifier
10 | io.flutter.flutter.app
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | App
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | MinimumOSVersion
24 | 9.0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 |
12 | # IntelliJ related
13 | *.iml
14 | *.ipr
15 | *.iws
16 | .idea/
17 |
18 | # The .vscode folder contains launch configuration and tasks you configure in
19 | # VS Code which you may wish to be included in version control, so this line
20 | # is commented out by default.
21 | #.vscode/
22 |
23 | # Flutter/Dart/Pub related
24 | **/doc/api/
25 | **/ios/Flutter/.last_build_id
26 | .dart_tool/
27 | .flutter-plugins
28 | .flutter-plugins-dependencies
29 | .packages
30 | .pub-cache/
31 | .pub/
32 | /build/
33 |
34 | # Web related
35 | lib/generated_plugin_registrant.dart
36 |
37 | # Symbolication related
38 | app.*.symbols
39 |
40 | # Obfuscation related
41 | app.*.map.json
42 |
43 | # Android Studio will place build artifacts here
44 | /android/app/debug
45 | /android/app/profile
46 | /android/app/release
47 |
--------------------------------------------------------------------------------
/lib/local_server_for_webview.dart:
--------------------------------------------------------------------------------
1 | library local_server_for_webview;
2 |
3 | export 'package:local_server_for_webview/src/services/local_server_configuration.dart';
4 | export 'package:local_server_for_webview/src/services/local_server_service.dart';
5 | export 'package:local_server_for_webview/tools/local_server_status_handler.dart';
6 | export 'package:local_server_for_webview/tools/local_server_binder.dart';
7 | export 'package:local_server_for_webview/tools/local_server_config_cache.dart';
8 | export 'package:local_server_for_webview/tools/local_server_downloader.dart';
9 | export 'package:local_server_for_webview/tools/local_server_manager.dart';
10 | export 'package:local_server_for_webview/src/model/download_service_item.dart';
11 | export 'package:local_server_for_webview/src/model/download_service_total_asset_item.dart';
12 | export 'package:local_server_for_webview/src/model/local_server_client_config.dart';
13 | export 'package:local_server_for_webview/src/model/local_server_client_config_item.dart';
--------------------------------------------------------------------------------
/example/web/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "short_name": "example",
4 | "start_url": ".",
5 | "display": "standalone",
6 | "background_color": "#0175C2",
7 | "theme_color": "#0175C2",
8 | "description": "A new Flutter project.",
9 | "orientation": "portrait-primary",
10 | "prefer_related_applications": false,
11 | "icons": [
12 | {
13 | "src": "icons/Icon-192.png",
14 | "sizes": "192x192",
15 | "type": "image/png"
16 | },
17 | {
18 | "src": "icons/Icon-512.png",
19 | "sizes": "512x512",
20 | "type": "image/png"
21 | },
22 | {
23 | "src": "icons/Icon-maskable-192.png",
24 | "sizes": "192x192",
25 | "type": "image/png",
26 | "purpose": "maskable"
27 | },
28 | {
29 | "src": "icons/Icon-maskable-512.png",
30 | "sizes": "512x512",
31 | "type": "image/png",
32 | "purpose": "maskable"
33 | }
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values-night/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/example/ios/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - Flutter (1.0.0)
3 | - path_provider_ios (0.0.1):
4 | - Flutter
5 | - shared_preferences_ios (0.0.1):
6 | - Flutter
7 | - webview_flutter_wkwebview (0.0.1):
8 | - Flutter
9 |
10 | DEPENDENCIES:
11 | - Flutter (from `Flutter`)
12 | - path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
13 | - shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`)
14 | - webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`)
15 |
16 | EXTERNAL SOURCES:
17 | Flutter:
18 | :path: Flutter
19 | path_provider_ios:
20 | :path: ".symlinks/plugins/path_provider_ios/ios"
21 | shared_preferences_ios:
22 | :path: ".symlinks/plugins/shared_preferences_ios/ios"
23 | webview_flutter_wkwebview:
24 | :path: ".symlinks/plugins/webview_flutter_wkwebview/ios"
25 |
26 | SPEC CHECKSUMS:
27 | Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
28 | path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
29 | shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad
30 | webview_flutter_wkwebview: b7e70ef1ddded7e69c796c7390ee74180182971f
31 |
32 | PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
33 |
34 | COCOAPODS: 1.11.2
35 |
--------------------------------------------------------------------------------
/lib/src/model/local_server_client_config_item.dart:
--------------------------------------------------------------------------------
1 | /// local server options 配置model
2 | class LocalServerClientConfigItem {
3 | /// H5 路径标识
4 | String? key;
5 |
6 | /// 该路径是否下载完毕
7 | bool? isAssetsDone;
8 |
9 | /// 该路径优先级
10 | int priority = 0;
11 |
12 | /// 版本
13 | String? version;
14 |
15 | LocalServerClientConfigItem({this.key, this.isAssetsDone, this.version, this.priority = 0});
16 |
17 | static LocalServerClientConfigItem? parse(Map json) {
18 | if (json['open'] == null || json['open'] == 0) {
19 | return null;
20 | }
21 | return LocalServerClientConfigItem()
22 | ..isAssetsDone = false
23 | ..key = json['key']
24 | ..priority = json['priority'] ?? 0
25 | ..version = json['version'];
26 | }
27 |
28 | LocalServerClientConfigItem.fromJson(Map json) {
29 | isAssetsDone = json['isAssetsDone'];
30 | key = json['key'];
31 | priority = json['priority'] ?? 0;
32 | version = json['version'];
33 | }
34 |
35 | Map toJson() {
36 | Map data = {};
37 | data['isAssetsDone'] = isAssetsDone;
38 | data['key'] = key;
39 | data['priority'] = priority;
40 | data['version'] = version;
41 | return data;
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/example/lib/tools/local_server_webview_manager.dart:
--------------------------------------------------------------------------------
1 | import 'package:local_server_for_webview/local_server_for_webview.dart';
2 |
3 | class LocalServerWebViewManager extends LocalServerClientManager {
4 |
5 | factory LocalServerWebViewManager() => _getInstance();
6 |
7 | static LocalServerWebViewManager get instance => _getInstance();
8 | static LocalServerWebViewManager? _instance;
9 |
10 | static LocalServerWebViewManager _getInstance() {
11 | _instance ??= LocalServerWebViewManager._internal();
12 | return _instance!;
13 | }
14 |
15 | LocalServerWebViewManager._internal();
16 |
17 | /// 测试的配置
18 | void initSetting() {
19 | init();
20 | LocalServerCacheBinderSetting.instance.setBaseHost('https://jomin-web.web.app');
21 | Map baCache = {'common': {'compress': '/local-server/common.zip', "version": "20220503"}};
22 | LocalServerClientConfig localServerClientConfig = LocalServerClientConfig.fromJson({
23 | 'option': [{'key': 'test-one', 'open': 1, 'priority': 0, "version": "20220503"}],
24 | 'assets': {
25 | 'test-one': {'compress': '/local-server/test-one.zip'}
26 | },
27 | 'basics': baCache,
28 | });
29 | prepareManager(localServerClientConfig);
30 | startLocalServer();
31 | }
32 |
33 | }
--------------------------------------------------------------------------------
/example/ios/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | # platform :ios, '9.0'
3 |
4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true'
6 |
7 | project 'Runner', {
8 | 'Debug' => :debug,
9 | 'Profile' => :release,
10 | 'Release' => :release,
11 | }
12 |
13 | def flutter_root
14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15 | unless File.exist?(generated_xcode_build_settings_path)
16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
17 | end
18 |
19 | File.foreach(generated_xcode_build_settings_path) do |line|
20 | matches = line.match(/FLUTTER_ROOT\=(.*)/)
21 | return matches[1].strip if matches
22 | end
23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
24 | end
25 |
26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
27 |
28 | flutter_ios_podfile_setup
29 |
30 | target 'Runner' do
31 | use_frameworks!
32 | use_modular_headers!
33 |
34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
35 | end
36 |
37 | post_install do |installer|
38 | installer.pods_project.targets.each do |target|
39 | flutter_additional_ios_build_settings(target)
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/example/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | # This file configures the analyzer, which statically analyzes Dart code to
2 | # check for errors, warnings, and lints.
3 | #
4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6 | # invoked from the command line by running `flutter analyze`.
7 |
8 | # The following line activates a set of recommended lints for Flutter apps,
9 | # packages, and plugins designed to encourage good coding practices.
10 | include: package:flutter_lints/flutter.yaml
11 |
12 | linter:
13 | # The lint rules applied to this project can be customized in the
14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml`
15 | # included above or to enable additional rules. A list of all available lints
16 | # and their documentation is published at
17 | # https://dart-lang.github.io/linter/lints/index.html.
18 | #
19 | # Instead of disabling a lint rule for the entire project in the
20 | # section below, it can also be suppressed for a single line of code
21 | # or a specific dart file by using the `// ignore: name_of_lint` and
22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file
23 | # producing the lint.
24 | rules:
25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule
26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27 |
28 | # Additional information about this file can be found at
29 | # https://dart.dev/guides/language/analysis-options
30 |
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/lib/src/model/download_service_total_asset_item.dart:
--------------------------------------------------------------------------------
1 | import 'package:local_server_for_webview/local_server_for_webview.dart';
2 |
3 | class DownloadServiceTotalAssetItem {
4 | String h5Path = '';
5 | bool isAssetsDone = false;
6 | List assets = [];
7 |
8 | DownloadServiceTotalAssetItem.fromConfigCenter(Map json, String keyPath) {
9 | h5Path = keyPath;
10 | DownloadServiceItem _createItem(String url, bool isCom) {
11 | return DownloadServiceItem()
12 | ..h5Path = h5Path
13 | ..zipUrl = LocalServerConfiguration.downloadUrl(url)
14 | ..downloadCount = 0
15 | ..loadState = LoadStateType.unLoad
16 | ..isCompress = isCom
17 | ..filePath = [];
18 | }
19 |
20 | List tmPAssets = [];
21 | if (json['compress'] != null) {
22 | tmPAssets.add(_createItem(json['compress'], true));
23 | }
24 | if (json['deps'] != null) {
25 | List deps = json['deps'];
26 | var tempDeps = deps.toList().map((e) => _createItem(e, false)).toList();
27 | tmPAssets.addAll(tempDeps);
28 | }
29 | assets = tmPAssets;
30 | }
31 |
32 | DownloadServiceTotalAssetItem.fromJson(Map json) {
33 | h5Path = json['h5Path'];
34 | isAssetsDone = json['isAssetsDone'];
35 | if (json['assets'] != null) {
36 | List tmpAssets = json['assets'];
37 | assets = tmpAssets.map((e) => DownloadServiceItem.fromJson(e)).toList();
38 | }
39 | }
40 |
41 | Map toJson() {
42 | Map data = {};
43 | data['h5Path'] = h5Path;
44 | data['isAssetsDone'] = isAssetsDone;
45 | if (assets.isNotEmpty) {
46 | data['assets'] = assets.map((e) => e.toJson()).toList();
47 | }
48 | return data;
49 | }
50 | }
--------------------------------------------------------------------------------
/example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
8 |
16 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
31 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/example/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleDisplayName
8 | Example
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | example
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(FLUTTER_BUILD_NAME)
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | $(FLUTTER_BUILD_NUMBER)
25 | LSRequiresIPhoneOS
26 |
27 | NSAppTransportSecurity
28 |
29 | NSAllowsArbitraryLoads
30 |
31 |
32 | UILaunchStoryboardName
33 | LaunchScreen
34 | UIMainStoryboardFile
35 | Main
36 | UISupportedInterfaceOrientations
37 |
38 | UIInterfaceOrientationPortrait
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 | UISupportedInterfaceOrientations~ipad
43 |
44 | UIInterfaceOrientationPortrait
45 | UIInterfaceOrientationPortraitUpsideDown
46 | UIInterfaceOrientationLandscapeLeft
47 | UIInterfaceOrientationLandscapeRight
48 |
49 | UIViewControllerBasedStatusBarAppearance
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: local_server_for_webview
2 | description: flutter local server for webview
3 | version: 0.0.1
4 | homepage: ''
5 |
6 | environment:
7 | sdk: ">=2.12.0 <3.0.0"
8 | flutter: ">=1.17.0"
9 |
10 | dependencies:
11 | flutter:
12 | sdk: flutter
13 |
14 | path: ^1.8.0
15 | http: ^0.13.4
16 | path_provider: ^2.0.9
17 | dio: ^4.0.6
18 | archive: ^3.3.0
19 | shared_preferences: ^2.0.13
20 | mime: ^1.0.1
21 | uuid: ^3.0.6
22 |
23 | dev_dependencies:
24 | flutter_test:
25 | sdk: flutter
26 | flutter_lints: ^1.0.0
27 |
28 | # For information on the generic Dart part of this file, see the
29 | # following page: https://dart.dev/tools/pub/pubspec
30 |
31 | # The following section is specific to Flutter.
32 | flutter:
33 |
34 | # To add assets to your package, add an assets section, like this:
35 | # assets:
36 | # - images/a_dot_burr.jpeg
37 | # - images/a_dot_ham.jpeg
38 | #
39 | # For details regarding assets in packages, see
40 | # https://flutter.dev/assets-and-images/#from-packages
41 | #
42 | # An image asset can refer to one or more resolution-specific "variants", see
43 | # https://flutter.dev/assets-and-images/#resolution-aware.
44 |
45 | # To add custom fonts to your package, add a fonts section here,
46 | # in this "flutter" section. Each entry in this list should have a
47 | # "family" key with the font family name, and a "fonts" key with a
48 | # list giving the asset and other descriptors for the font. For
49 | # example:
50 | # fonts:
51 | # - family: Schyler
52 | # fonts:
53 | # - asset: fonts/Schyler-Regular.ttf
54 | # - asset: fonts/Schyler-Italic.ttf
55 | # style: italic
56 | # - family: Trajan Pro
57 | # fonts:
58 | # - asset: fonts/TrajanPro.ttf
59 | # - asset: fonts/TrajanPro_Bold.ttf
60 | # weight: 700
61 | #
62 | # For details regarding fonts in packages, see
63 | # https://flutter.dev/custom-fonts/#from-packages
64 |
--------------------------------------------------------------------------------
/example/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:example/tools/local_server_webview_manager.dart';
2 | import 'package:example/web_page.dart';
3 | import 'package:flutter/material.dart';
4 |
5 | void main() {
6 | runApp(const MyApp());
7 | }
8 |
9 | class MyApp extends StatelessWidget {
10 | const MyApp({Key? key}) : super(key: key);
11 |
12 | // This widget is the root of your application.
13 | @override
14 | Widget build(BuildContext context) {
15 | return MaterialApp(
16 | title: 'Flutter Demo',
17 | theme: ThemeData(
18 | primarySwatch: Colors.blue,
19 | ),
20 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
21 | );
22 | }
23 | }
24 |
25 | class MyHomePage extends StatefulWidget {
26 | const MyHomePage({Key? key, required this.title}) : super(key: key);
27 |
28 | final String title;
29 |
30 | @override
31 | State createState() => _MyHomePageState();
32 | }
33 |
34 | class _MyHomePageState extends State {
35 |
36 | final String testUrl = "https://jomin-web.web.app/test-one/index.html";
37 |
38 | @override
39 | void initState() {
40 | super.initState();
41 | LocalServerWebViewManager.instance.initSetting();
42 | }
43 |
44 | @override
45 | void dispose() {
46 |
47 | super.dispose();
48 | }
49 |
50 | @override
51 | Widget build(BuildContext context) {
52 | return Scaffold(
53 | appBar: AppBar(
54 | title: Text(widget.title),
55 | ),
56 | body: Center(
57 | child: GestureDetector(
58 | onTap: () {
59 | Navigator.push(
60 | context,
61 | MaterialPageRoute(
62 | builder: (_) => WebPage(
63 | url: testUrl,
64 | ),
65 | ),
66 | );
67 | },
68 | child: const Text(
69 | 'Open The WebView',
70 | style: TextStyle(
71 | fontSize: 20,
72 | ),
73 | ),
74 | ),
75 | ),
76 | );
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | def localProperties = new Properties()
2 | def localPropertiesFile = rootProject.file('local.properties')
3 | if (localPropertiesFile.exists()) {
4 | localPropertiesFile.withReader('UTF-8') { reader ->
5 | localProperties.load(reader)
6 | }
7 | }
8 |
9 | def flutterRoot = localProperties.getProperty('flutter.sdk')
10 | if (flutterRoot == null) {
11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12 | }
13 |
14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15 | if (flutterVersionCode == null) {
16 | flutterVersionCode = '1'
17 | }
18 |
19 | def flutterVersionName = localProperties.getProperty('flutter.versionName')
20 | if (flutterVersionName == null) {
21 | flutterVersionName = '1.0'
22 | }
23 |
24 | apply plugin: 'com.android.application'
25 | apply plugin: 'kotlin-android'
26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27 |
28 | android {
29 | compileSdkVersion flutter.compileSdkVersion
30 |
31 | compileOptions {
32 | sourceCompatibility JavaVersion.VERSION_1_8
33 | targetCompatibility JavaVersion.VERSION_1_8
34 | }
35 |
36 | kotlinOptions {
37 | jvmTarget = '1.8'
38 | }
39 |
40 | sourceSets {
41 | main.java.srcDirs += 'src/main/kotlin'
42 | }
43 |
44 | defaultConfig {
45 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
46 | applicationId "com.example.example"
47 | minSdkVersion 21
48 | targetSdkVersion flutter.targetSdkVersion
49 | versionCode flutterVersionCode.toInteger()
50 | versionName flutterVersionName
51 | }
52 |
53 | buildTypes {
54 | release {
55 | // TODO: Add your own signing config for the release build.
56 | // Signing with the debug keys for now, so `flutter run --release` works.
57 | signingConfig signingConfigs.debug
58 | }
59 | }
60 | }
61 |
62 | flutter {
63 | source '../..'
64 | }
65 |
66 | dependencies {
67 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
68 | }
69 |
--------------------------------------------------------------------------------
/lib/src/model/download_service_item.dart:
--------------------------------------------------------------------------------
1 |
2 | import 'package:local_server_for_webview/local_server_for_webview.dart';
3 |
4 | /// zip下载状态
5 | enum LoadStateType {
6 | // 未下载
7 | unLoad,
8 | // 加载中
9 | loading,
10 | // 已下载
11 | success,
12 | // 下载失败
13 | failure,
14 | }
15 |
16 | class DownloadServiceItem {
17 |
18 | /// H5路径
19 | String h5Path = '';
20 |
21 | /// zip 压缩 url
22 | String zipUrl = '';
23 |
24 | /// 下载次数
25 | int downloadCount = 0;
26 |
27 | /// 下载状态
28 | LoadStateType loadState = LoadStateType.unLoad;
29 |
30 | /// file path
31 | List filePath = [];
32 |
33 | /// 是否为Compress路径
34 | bool isCompress = false;
35 |
36 | String? version;
37 |
38 | DownloadServiceItem();
39 |
40 | DownloadServiceItem.fromJson(Map json) {
41 | h5Path = json['h5Path'];
42 | zipUrl = LocalServerConfiguration.downloadUrl(json['zipUrl']);
43 | isCompress = json['isCompress'];
44 | downloadCount = json['downloadCount'];
45 | loadState = LoadStateType.values[json['loadState'] ?? 0];
46 | if (json['filePath'] != null && json['filePath'] is List) {
47 | filePath = json['filePath'].cast();
48 | }
49 | version = json['version'];
50 | }
51 |
52 | void replaceLoadState(DownloadServiceItem oldItem) {
53 | downloadCount = oldItem.downloadCount;
54 | filePath = oldItem.filePath;
55 | loadState = oldItem.loadState;
56 | version = oldItem.version;
57 | }
58 |
59 | void replaceFull(DownloadServiceItem oldItem) {
60 | downloadCount = oldItem.downloadCount;
61 | filePath = oldItem.filePath;
62 | loadState = oldItem.loadState;
63 | h5Path = oldItem.h5Path;
64 | zipUrl = LocalServerConfiguration.downloadUrl(oldItem.zipUrl);
65 | downloadCount = oldItem.downloadCount;
66 | filePath = oldItem.filePath;
67 | isCompress = oldItem.isCompress;
68 | version = oldItem.version;
69 | }
70 |
71 | Map toJson() {
72 | Map data = {};
73 | data['h5Path'] = h5Path;
74 | data['zipUrl'] = LocalServerConfiguration.downloadUrl(zipUrl);
75 | data['downloadCount'] = downloadCount;
76 | data['loadState'] = loadState.index;
77 | data['filePath'] = filePath;
78 | data['isCompress'] = isCompress;
79 | data['version'] = version;
80 | return data;
81 | }
82 |
83 | }
--------------------------------------------------------------------------------
/example/lib/web_page.dart:
--------------------------------------------------------------------------------
1 | import 'dart:developer';
2 |
3 | import 'package:example/tools/local_server_webview_manager.dart';
4 | import 'package:flutter/material.dart';
5 | import 'package:local_server_for_webview/local_server_for_webview.dart';
6 | import 'package:webview_flutter/webview_flutter.dart';
7 |
8 | class WebPage extends StatefulWidget {
9 | const WebPage({Key? key, required this.url}) : super(key: key);
10 | final String url;
11 |
12 | @override
13 | State createState() => _WebPageState();
14 |
15 | }
16 |
17 | class _WebPageState extends State {
18 |
19 | // Local server 管理
20 | late LocalServerCacheBinder _localServerBuilder;
21 | WebViewController? webViewController;
22 | String _innerUrl = '';
23 | String _title = '';
24 |
25 | @override
26 | void initState() {
27 | super.initState();
28 | log('页面开始加载:${DateTime.now()}', name: 'web-time');
29 | _localServerBuilder = LocalServerCacheBinder()..initBinder();
30 | LocalServerWebViewManager.instance.registerBuilder(_localServerBuilder);
31 | _innerUrl = _localServerBuilder.convertH5Url2LocalServerUrl(widget.url);
32 | }
33 |
34 | @override
35 | void dispose() {
36 | LocalServerWebViewManager.instance.resignBuilder(_localServerBuilder);
37 | _localServerBuilder.dispose();
38 | super.dispose();
39 | }
40 |
41 | @override
42 | Widget build(BuildContext context) {
43 | return Scaffold(
44 | appBar: AppBar(
45 | title: Text(
46 | _title,
47 | ),
48 | ),
49 | body: WebView(
50 | initialUrl: _innerUrl,
51 | debuggingEnabled: true,
52 | onPageStarted: (url) {
53 | print("onPageStarted($url) ----------------------");
54 | log('Web开始加载:${DateTime.now()}', name: 'web-time');
55 | },
56 | onPageFinished: (url) {
57 | print("onPageFinished($url) ----------------------");
58 | log('Web加载完成:${DateTime.now()}', name: 'web-time');
59 | },
60 | onWebViewCreated: (controller) async {
61 | webViewController = controller;
62 | webViewController!.getTitle().then((value) {
63 | setState(() {
64 | _title = value ?? '';
65 | });
66 | });
67 | },
68 | javascriptMode: JavascriptMode.unrestricted,
69 | ),
70 | );
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-60x60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-60x60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-App-20x20@1x.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "20x20",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-App-20x20@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-29x29@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "29x29",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-29x29@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-40x40@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "40x40",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-40x40@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-76x76@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "76x76",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-76x76@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "83.5x83.5",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-App-83.5x83.5@2x.png",
109 | "scale" : "2x"
110 | },
111 | {
112 | "size" : "1024x1024",
113 | "idiom" : "ios-marketing",
114 | "filename" : "Icon-App-1024x1024@1x.png",
115 | "scale" : "1x"
116 | }
117 | ],
118 | "info" : {
119 | "version" : 1,
120 | "author" : "xcode"
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | HttpServer 对于Webview预加载、拦截替换资源的Flutter实现。优化Webview的首次加载时间、白屏时间。
2 |
3 | ## Pub get
4 | ```yaml
5 | local_server_for_webview:
6 | git:
7 | url: https://github.com/EchoPuda/local_server_webview.git
8 | ```
9 | ## Usage
10 |
11 | 继承LocalServerClientManager, 初始化并配置载入LocalServerClientConfig,最后在合适的时机startLocalServer()
12 | ```dart
13 | import 'package:local_server_for_webview/local_server_for_webview.dart';
14 |
15 | class LocalServerWebViewManager extends LocalServerClientManager {
16 |
17 | factory LocalServerWebViewManager() => _getInstance();
18 |
19 | static LocalServerWebViewManager get instance => _getInstance();
20 | static LocalServerWebViewManager? _instance;
21 |
22 | static LocalServerWebViewManager _getInstance() {
23 | _instance ??= LocalServerWebViewManager._internal();
24 | return _instance!;
25 | }
26 |
27 | LocalServerWebViewManager._internal();
28 |
29 | /// 测试的配置
30 | void initSetting() {
31 | init();
32 | LocalServerCacheBinderSetting.instance.setBaseHost('https://jomin-web.web.app');
33 | Map baCache = {'common': {'compress': '/local-server/common.zip', "version": "20220503"}};
34 | LocalServerClientConfig localServerClientConfig = LocalServerClientConfig.fromJson({
35 | 'option': [{'key': 'test-one', 'open': 1, 'priority': 0, "version": "20220503"}],
36 | 'assets': {
37 | 'test-one': {'compress': '/local-server/test-one.zip'}
38 | },
39 | 'basics': baCache,
40 | });
41 | prepareManager(localServerClientConfig);
42 | startLocalServer();
43 | }
44 |
45 | }
46 | ```
47 |
48 | 在WebView页面中,绑定LocalServerCacheBinder到Manager中。然后获取转换后的LocalServerUrl,最后由WebView加载展示。
49 | ```dart
50 | class _WebPageState extends State {
51 |
52 | // Local server 管理
53 | late LocalServerCacheBinder _localServerBuilder;
54 | WebViewController? webViewController;
55 | String _innerUrl = '';
56 | String _title = '';
57 |
58 | @override
59 | void initState() {
60 | super.initState();
61 | log('页面开始加载:${DateTime.now()}', name: 'web-time');
62 | _localServerBuilder = LocalServerCacheBinder()..initBinder();
63 | LocalServerWebViewManager.instance.registerBuilder(_localServerBuilder);
64 | _innerUrl = _localServerBuilder.convertH5Url2LocalServerUrl(widget.url);
65 | }
66 |
67 | @override
68 | void dispose() {
69 | LocalServerWebViewManager.instance.resignBuilder(_localServerBuilder);
70 | _localServerBuilder.dispose();
71 | super.dispose();
72 | }
73 |
74 | @override
75 | Widget build(BuildContext context) {
76 | return Scaffold(
77 | appBar: AppBar(
78 | title: Text(
79 | _title,
80 | ),
81 | ),
82 | body: WebView(
83 | initialUrl: _innerUrl,
84 | debuggingEnabled: true,
85 | onPageStarted: (url) {
86 | print("onPageStarted($url) ----------------------");
87 | log('Web开始加载:${DateTime.now()}', name: 'web-time');
88 | },
89 | onPageFinished: (url) {
90 | print("onPageFinished($url) ----------------------");
91 | log('Web加载完成:${DateTime.now()}', name: 'web-time');
92 | },
93 | onWebViewCreated: (controller) async {
94 | webViewController = controller;
95 | webViewController!.getTitle().then((value) {
96 | setState(() {
97 | _title = value ?? '';
98 | });
99 | });
100 | },
101 | javascriptMode: JavascriptMode.unrestricted,
102 | ),
103 | );
104 | }
105 | }
106 | ```
107 |
108 | 在不用的时候记得关闭LocalServer
109 |
110 |
--------------------------------------------------------------------------------
/lib/src/services/local_server_configuration.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 | import 'dart:io';
3 |
4 | import 'package:local_server_for_webview/tools/local_server_binder.dart';
5 | import 'package:path_provider/path_provider.dart';
6 |
7 | /// 本地文件缓存目录管理
8 | class LocalServerConfiguration {
9 |
10 | static String? cacheDirectory;
11 | static Directory? distDirectory;
12 | static String kFileName = 'app_web_cache';
13 | static String kFileNameDist = 'app_web_cache/dist';
14 | static String kFileBasic = 'app_web_cache/basic';
15 |
16 | /// basic 统一文件类的存放目录
17 | static Future getBasicFile(String keyPath) async {
18 | Directory directory;
19 | if (cacheDirectory != null) {
20 | directory = Directory(cacheDirectory!);
21 | } else {
22 | directory = await getTemporaryDirectory();
23 | cacheDirectory = directory.path;
24 | }
25 | String distPath = directory.path + '/$kFileBasic' + '/$keyPath';
26 | final tmpFile = File(distPath);
27 | if (tmpFile.existsSync()) {
28 | return tmpFile;
29 | } else {
30 | try {
31 | final tmpDir = await tmpFile.create(recursive: true);
32 | return tmpDir;
33 | } catch(e) {
34 | rethrow;
35 | }
36 | }
37 | }
38 |
39 | /// dist 各项目的存放目录
40 | static Future getDistDirectory() async {
41 | Directory directory;
42 | if (distDirectory != null) {
43 | return distDirectory!;
44 | }
45 | if (cacheDirectory != null) {
46 | directory = Directory(cacheDirectory!);
47 | } else {
48 | directory = await getTemporaryDirectory();
49 | cacheDirectory = directory.path + '/$kFileName';
50 | }
51 | String distPath = directory.path + '/$kFileNameDist';
52 | final tmpDirectory = Directory(distPath);
53 | if (tmpDirectory.existsSync()) {
54 | distDirectory = tmpDirectory;
55 | return tmpDirectory;
56 | } else {
57 | try {
58 | final tmpDir = await tmpDirectory.create(recursive: true);
59 | distDirectory = tmpDir;
60 | return tmpDir;
61 | } catch(e) {
62 | rethrow;
63 | }
64 | }
65 | }
66 |
67 | /// 检查当前项目是否已经存在
68 | static Future checkZipPathDirectoryIsExist(String zippurl) async {
69 | String zipTmpPath = base64Encode(utf8.encode(zippurl));
70 | final dist = await getDistDirectory();
71 | String zipPath = dist.path + '/' + zipTmpPath;
72 | final checkDirect = Directory(zipPath);
73 | return checkDirect.existsSync();
74 | }
75 |
76 | /// 返回对应路径
77 | static String joinZipPathSync(String zipUrl, String fileName) {
78 | Directory tmpDir = getCurrentZipPathSyncDirectory(zipUrl);
79 | if (fileName.isEmpty) {
80 | return tmpDir.path;
81 | }
82 | return tmpDir.path + '/' + fileName;
83 | }
84 |
85 | /// 返回对应目录
86 | static Directory getCurrentZipPathSyncDirectory(String zipUrl, {bool isExist = false}) {
87 | String zipTmpPath = base64Encode(utf8.encode(zipUrl));
88 | final dist = distDirectory!;
89 | String zipPath = dist.path + '/' + zipTmpPath;
90 | final checkDirect = Directory(zipPath);
91 | return checkDirect;
92 | }
93 |
94 | /// 处理为完整的下载downloadUrl
95 | /// 必须配置 [LocalServerCacheBinderSetting.instance.baseDomain]
96 | static String downloadUrl(String url) {
97 | String downUrl = url;
98 | if (!downUrl.startsWith('http') && !downUrl.startsWith('https')) {
99 | if (!downUrl.startsWith("/")) {
100 | downUrl = "/" + downUrl;
101 | }
102 | downUrl = LocalServerCacheBinderSetting.instance.baseDomain + downUrl;
103 | }
104 | return downUrl;
105 | }
106 |
107 | }
--------------------------------------------------------------------------------
/lib/tools/local_server_config_cache.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 | import 'dart:developer';
3 |
4 | import 'package:flutter/foundation.dart';
5 | import 'package:local_server_for_webview/src/model/download_service_item.dart';
6 | import 'package:local_server_for_webview/src/model/download_service_total_asset_item.dart';
7 | import 'package:local_server_for_webview/src/model/local_server_client_config_item.dart';
8 | import 'package:shared_preferences/shared_preferences.dart';
9 |
10 | /// 相应的配置本地存储
11 | class LocalServerConfigCache {
12 |
13 | static const String _optionKey = 'local_options_key';
14 | static const String _basicKey = 'local_basic_key';
15 | static const String _assetsKey = 'local_assets_key';
16 | static SharedPreferences? _sp;
17 | static Future get getSp async {
18 | if (_sp != null) {
19 | return _sp!;
20 | } else {
21 | _sp = await SharedPreferences.getInstance();
22 | return _sp!;
23 | }
24 | }
25 |
26 | static Future setOptions(List items) async {
27 | List