Skip to content

Commit

Permalink
update some dep pub , special webview flutter
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Sep 11, 2023
1 parent 3d71298 commit 4555903
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 119 deletions.
17 changes: 9 additions & 8 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ PODS:
- FMDB/standard (2.7.5)
- package_info (0.0.1):
- Flutter
- path_provider_ios (0.0.1):
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- "permission_handler (5.1.0+2)":
- Flutter
- Reachability (3.2)
- share (0.0.1):
- Flutter
- shared_preferences_ios (0.0.1):
- Flutter
- sqflite (0.0.2):
- sqflite (0.0.3):
- Flutter
- FMDB (>= 2.7.5)
- Toast (4.0.0)
Expand All @@ -37,7 +38,7 @@ DEPENDENCIES:
- Flutter (from `Flutter`)
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
- package_info (from `.symlinks/plugins/package_info/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- permission_handler (from `.symlinks/plugins/permission_handler/ios`)
- share (from `.symlinks/plugins/share/ios`)
- shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`)
Expand All @@ -62,8 +63,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/fluttertoast/ios"
package_info:
:path: ".symlinks/plugins/package_info/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
permission_handler:
:path: ".symlinks/plugins/permission_handler/ios"
share:
Expand All @@ -84,15 +85,15 @@ SPEC CHECKSUMS:
fluttertoast: 16fbe6039d06a763f3533670197d01fc73459037
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
package_info: 873975fc26034f0b863a300ad47e7f1ac6c7ec62
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
permission_handler: ccb20a9fad0ee9b1314a52b70b76b473c5f8dab0
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
share: 0b2c3e82132f5888bccca3351c504d0003b3b410
shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
webview_flutter_wkwebview: b7e70ef1ddded7e69c796c7390ee74180182971f
webview_flutter_wkwebview: 2e2d318f21a5e036e2c3f26171342e95908bd60a

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3

Expand Down
4 changes: 2 additions & 2 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
"${BUILT_PRODUCTS_DIR}/device_info_plus/device_info_plus.framework",
"${BUILT_PRODUCTS_DIR}/fluttertoast/fluttertoast.framework",
"${BUILT_PRODUCTS_DIR}/package_info/package_info.framework",
"${BUILT_PRODUCTS_DIR}/path_provider_ios/path_provider_ios.framework",
"${BUILT_PRODUCTS_DIR}/path_provider_foundation/path_provider_foundation.framework",
"${BUILT_PRODUCTS_DIR}/share/share.framework",
"${BUILT_PRODUCTS_DIR}/shared_preferences_ios/shared_preferences_ios.framework",
"${BUILT_PRODUCTS_DIR}/sqflite/sqflite.framework",
Expand All @@ -501,7 +501,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/device_info_plus.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/fluttertoast.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/package_info.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider_foundation.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/share.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqflite.framework",
Expand Down
34 changes: 17 additions & 17 deletions lib/page/code_detail_page_web.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
Expand Down Expand Up @@ -47,29 +46,29 @@ class CodeDetailPageWeb extends StatefulWidget {
class _CodeDetailPageState extends State<CodeDetailPageWeb> {
bool isLand = false;

late final WebViewController controller;

@override
void initState() {
controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted);

super.initState();
if (Platform.isAndroid) {
WebView.platform = SurfaceAndroidWebView();
}
}

Future<String?> _getData() async {
Future<Uri?> _getData() async {
if (widget.data != null) {
return widget.data;
return Uri.dataFromString(widget.data!);
}
var res = await ReposDao.getReposFileDirDao(
widget.userName, widget.reposName,
path: widget.path, branch: widget.branch, text: true, isHtml: true);
if (res != null && res.result) {
String data2 = HtmlUtils.resolveHtmlFile(res, "java");
String url = new Uri.dataFromString(data2,
mimeType: 'text/html', encoding: Encoding.getByName("utf-8"))
.toString();
return url;
return new Uri.dataFromString(data2,
mimeType: 'text/html', encoding: Encoding.getByName("utf-8"));
}
return "";
return null;
}

@override
Expand All @@ -86,11 +85,12 @@ class _CodeDetailPageState extends State<CodeDetailPageWeb> {
appBar: new AppBar(
title: GSYTitleBar(widget.title),
),
body: FutureBuilder<String?>(
initialData: widget.data,
body: FutureBuilder<Uri?>(
initialData:
widget.data != null ? Uri.dataFromString(widget.data!) : null,
future: _getData(),
builder: (context, result) {
if (result.data == null || result.data!.isEmpty) {
if (result.data == null) {
return new Center(
child: new Container(
width: 200.0,
Expand All @@ -111,9 +111,9 @@ class _CodeDetailPageState extends State<CodeDetailPageWeb> {
),
);
}
return WebView(
initialUrl: result.data,
javascriptMode: JavascriptMode.unrestricted,
controller.loadRequest(result.data!);
return WebViewWidget(
controller: controller,
);
},
),
Expand Down
49 changes: 27 additions & 22 deletions lib/page/gsy_webview.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:gsy_github_app_flutter/common/localization/default_localizations.dart';
Expand Down Expand Up @@ -45,12 +43,33 @@ class _GSYWebViewState extends State<GSYWebView> {

bool isLoading = true;

late final WebViewController controller;

@override
void initState() {
controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {
// Update loading bar.
},
onPageStarted: (String url) {},
onPageFinished: (String url) {
setState(() {
isLoading = false;
});
},
onWebResourceError: (WebResourceError error) {},
),
)
..addJavaScriptChannel("name", onMessageReceived: (message) {
print(message.message);
FocusScope.of(context).requestFocus(focusNode);
})
..loadRequest(Uri.parse(widget.url));

super.initState();
if (Platform.isAndroid) {
WebView.platform = SurfaceAndroidWebView();
}
}

@override
Expand All @@ -64,23 +83,9 @@ class _GSYWebViewState extends State<GSYWebView> {
TextField(
focusNode: focusNode,
),
WebView(
initialUrl: widget.url,
javascriptMode: JavascriptMode.unrestricted,
onPageFinished: (_) {
setState(() {
isLoading = false;
});
},
javascriptChannels: Set.from([
JavascriptChannel(
name: 'Print',
onMessageReceived: (JavascriptMessage message) {
///print("FFFFFF");
print(message.message);
FocusScope.of(context).requestFocus(focusNode);
})
])),
WebViewWidget(
controller: controller,
),
if (isLoading)
new Center(
child: new Container(
Expand Down
93 changes: 63 additions & 30 deletions lib/page/login/login_webview.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:gsy_github_app_flutter/common/localization/default_localizations.dart';
import 'package:gsy_github_app_flutter/common/style/gsy_style.dart';
import 'package:gsy_github_app_flutter/widget/gsy_common_option_widget.dart';
import 'package:webview_flutter/webview_flutter.dart';

// Import for Android features.
import 'package:webview_flutter_android/webview_flutter_android.dart';

// Import for iOS features.
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';

class LoginWebView extends StatefulWidget {
final String url;
Expand All @@ -19,13 +22,58 @@ class LoginWebView extends StatefulWidget {
}

class _LoginWebViewState extends State<LoginWebView> {
late final WebViewController controller;

late final PlatformWebViewControllerCreationParams params;

@override
void initState() {
super.initState();
if(Platform.isAndroid) {
WebView.platform = SurfaceAndroidWebView();
if (WebViewPlatform.instance is WebKitWebViewPlatform) {
params = WebKitWebViewControllerCreationParams(
allowsInlineMediaPlayback: true,
mediaTypesRequiringUserAction: const <PlaybackMediaTypes>{},
);
} else {
params = const PlatformWebViewControllerCreationParams();
}

controller = WebViewController.fromPlatformCreationParams(params);
if (controller.platform is AndroidWebViewController) {
//AndroidWebViewController.enableDebugging(true);
(controller.platform as AndroidWebViewController)
.setMediaPlaybackRequiresUserGesture(true);
}
controller
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(const Color(0x00000000))
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {
// Update loading bar.
},
onPageStarted: (String url) {},
onPageFinished: (String url) {
setState(() {
isLoading = false;
});
},
onWebResourceError: (WebResourceError error) {},
onNavigationRequest: (NavigationRequest request) {
if (request.url.startsWith("gsygithubapp://authed")) {
var code = Uri.parse(request.url).queryParameters["code"];
print("code ${code}");
Navigator.of(context).pop(code);
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
),
)
..loadRequest(Uri.parse(
widget.url,
));

super.initState();
}

_renderTitle() {
Expand All @@ -35,12 +83,12 @@ class _LoginWebViewState extends State<LoginWebView> {
return new Row(children: [
new Expanded(
child: new Container(
child: new Text(
widget.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
)),
child: new Text(
widget.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
)),
GSYCommonOptionWidget(url: widget.url),
]);
}
Expand All @@ -60,24 +108,9 @@ class _LoginWebViewState extends State<LoginWebView> {
TextField(
focusNode: focusNode,
),
WebView(
initialUrl: widget.url,
javascriptMode: JavascriptMode.unrestricted,
initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow,
navigationDelegate: (NavigationRequest navigation) {
if (navigation.url.startsWith("gsygithubapp://authed")) {
var code = Uri.parse(navigation.url).queryParameters["code"];
print("code ${code}");
Navigator.of(context).pop(code);
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
onPageFinished: (_) {
setState(() {
isLoading = false;
});
}),
WebViewWidget(
controller: controller,
),
if (isLoading)
new Center(
child: new Container(
Expand All @@ -102,4 +135,4 @@ class _LoginWebViewState extends State<LoginWebView> {
),
);
}
}
}
2 changes: 1 addition & 1 deletion lib/page/repos/repository_detail_issue_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RepositoryDetailIssuePageState extends State<RepositoryDetailIssuePage>
@override
showRefreshLoading() {
new Future.delayed(const Duration(seconds: 0), () {
refreshIKey.currentState!.show().then((e) {});
refreshIKey.currentState?.show().then((e) {});
return true;
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/redux/login_redux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LoginMiddleware implements MiddlewareClass<GSYState> {
void call(Store<GSYState> store, dynamic action, NextDispatcher next) {
if (action is LogoutAction) {
UserDao.clearAll(store);
CookieManager().clearCookies();
WebViewCookieManager().clearCookies();
SqlManager.close();
NavigatorUtils.goLogin(action.context);
}
Expand Down
Loading

0 comments on commit 4555903

Please sign in to comment.