Skip to content

Commit 446b8c1

Browse files
committed
区分平台
1 parent bc6840b commit 446b8c1

File tree

9 files changed

+61
-16
lines changed

9 files changed

+61
-16
lines changed

RECORD.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ https://stackoverflow.com/questions/49862572
4545
readme等view的loading
4646

4747
flutter 的跨平台见兼容性意外的话,得益于flutter engine,skia的渲染,只需要canvas
48-
所以第一次运行意外的没有兼容问题,特别是有生之年在ios上看到完全一模一样的下拉刷新
48+
所以第一次运行意外的没有兼容问题,特别是有生之年在ios上看到完全一模一样的下拉刷新
49+
50+
https://github.com/dart-flitter/flutter_webview_plugin/issues/23

ios/Runner.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
"${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework",
231231
"${BUILT_PRODUCTS_DIR}/connectivity/connectivity.framework",
232232
"${BUILT_PRODUCTS_DIR}/device_info/device_info.framework",
233+
"${BUILT_PRODUCTS_DIR}/flutter_webview_plugin/flutter_webview_plugin.framework",
233234
"${BUILT_PRODUCTS_DIR}/fluttertoast/fluttertoast.framework",
234235
"${BUILT_PRODUCTS_DIR}/get_version/get_version.framework",
235236
"${BUILT_PRODUCTS_DIR}/package_info/package_info.framework",
@@ -243,6 +244,7 @@
243244
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
244245
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/connectivity.framework",
245246
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/device_info.framework",
247+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_webview_plugin.framework",
246248
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/fluttertoast.framework",
247249
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/get_version.framework",
248250
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/package_info.framework",

ios/Runner/Info.plist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222
<string>1</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
25+
<key>NSAppTransportSecurity</key>
26+
<dict>
27+
<key>NSAllowsArbitraryLoads</key>
28+
<true/>
29+
<key>NSAllowsArbitraryLoadsInWebContent</key>
30+
<true/>
31+
<key>NSExceptionDomains</key>
32+
<dict>
33+
<key>localhost</key>
34+
<dict>
35+
<key>NSExceptionAllowsInsecureHTTPLoads</key>
36+
<true/>
37+
</dict>
38+
</dict>
39+
</dict>
2540
<key>UILaunchStoryboardName</key>
2641
<string>LaunchScreen</string>
2742
<key>UIMainStoryboardFile</key>

lib/common/dao/ReposDao.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ class ReposDao {
128128
/***
129129
* 获取仓库的文件列表
130130
*/
131-
static getReposFileDirDao(userName, reposName, {path = '', branch, text = false}) async {
131+
static getReposFileDirDao(userName, reposName, {path = '', branch, text = false, isHtml = false}) async {
132132
String url = Address.reposDataDir(userName, reposName, path, branch);
133133
var res = await HttpManager.netFetch(
134134
url,
135135
null,
136136
//text ? {"Accept": 'application/vnd.github.VERSION.raw'} : {"Accept": 'application/vnd.github.html'},
137-
text ? {"Accept": 'application/vnd.github.html'} : {"Accept": 'application/vnd.github.VERSION.raw'},
137+
isHtml ? {"Accept": 'application/vnd.github.html'} : {"Accept": 'application/vnd.github.VERSION.raw'},
138138
new Options(contentType: text ? ContentType.text : ContentType.json),
139139
);
140140
if (res != null && res.result) {

lib/common/utils/CommonUtils.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class CommonUtils {
104104

105105
static void launchWebView(BuildContext context, String title, String url) {
106106
if (url.startsWith("http")) {
107+
print("fff");
108+
print(url);
107109
NavigatorUtils.goGSYWebView(context, url, title);
108110
} else {
109111
NavigatorUtils.goGSYWebView(context, new Uri.dataFromString(url, mimeType: 'text/html', encoding: Encoding.getByName("utf-8")).toString(), title);

lib/common/utils/HtmlUtils.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class HtmlUtils {
2020
RegExp exp = new RegExp("<code(([\\s\\S])*?)<\/code>");
2121
Iterable<Match> tags = exp.allMatches(mdData);
2222
String mdDataCode = mdData;
23-
print("---------------------`--------------------------");
24-
print(tags);
2523
for (Match m in tags) {
2624
print(m.group(0));
2725
String match = m.group(0).replaceAll(new RegExp("\n"), "\n\r<br>");

lib/page/GSYWebView.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class GSYWebView extends StatelessWidget {
1616
@override
1717
Widget build(BuildContext context) {
1818
return new WebviewScaffold(
19+
withJavascript: true,
1920
url: url,
2021
withLocalUrl: true,
2122
appBar: new AppBar(

lib/page/PushDetailPage.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'dart:io';
23

34
import 'package:flutter/material.dart';
45
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
@@ -76,9 +77,20 @@ class _PushDetailPageState extends GSYListState<PushDetailPage> {
7677
}
7778
PushCodeItemViewModel itemViewModel = pullLoadWidgetControl.dataList[index - 1];
7879
return new PushCodeItem(itemViewModel, () {
79-
String html =
80-
HtmlUtils.generateCode2HTml(HtmlUtils.parseDiffSource(itemViewModel.patch, false), backgroundColor: GSYColors.webDraculaBackgroundColorString, lang: '', userBR: false);
81-
CommonUtils.launchWebView(context, itemViewModel.name, html);
80+
if (Platform.isIOS) {
81+
NavigatorUtils.gotoCodeDetailPage(
82+
context,
83+
title: itemViewModel.name,
84+
userName: userName,
85+
reposName: reposName,
86+
data: itemViewModel.patch,
87+
htmlUrl: itemViewModel.blob_url,
88+
);
89+
} else {
90+
String html = HtmlUtils.generateCode2HTml(HtmlUtils.parseDiffSource(itemViewModel.patch, false),
91+
backgroundColor: GSYColors.webDraculaBackgroundColorString, lang: '', userBR: false);
92+
CommonUtils.launchWebView(context, itemViewModel.name, html);
93+
}
8294
});
8395
}
8496

lib/page/RepositoryFileListPage.dart

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:io';
2+
13
import 'package:flutter/material.dart';
24
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
35
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
@@ -122,14 +124,25 @@ class RepositoryDetailFileListPageState extends GSYListState<RepositoryDetailFil
122124
if (CommonUtils.isImageEnd(fileItemViewModel.name)) {
123125
//todo 图片
124126
} else {
125-
CommonUtils.showLoadingDialog(context);
126-
ReposDao.getReposFileDirDao(userName, reposName, path: path, branch: branchControl.currentBranch, text: true).then((res) {
127-
if (res != null && res.result) {
128-
Navigator.pop(context);
129-
String data = HtmlUtils.resolveHtmlFile(res, "java");
130-
CommonUtils.launchWebView(context, fileItemViewModel.name, data);
131-
}
132-
});
127+
if (Platform.isIOS) {
128+
NavigatorUtils.gotoCodeDetailPage(
129+
context,
130+
title: fileItemViewModel.name,
131+
reposName: reposName,
132+
userName: userName,
133+
path: path,
134+
branch: branchControl.currentBranch,
135+
);
136+
} else {
137+
CommonUtils.showLoadingDialog(context);
138+
ReposDao.getReposFileDirDao(userName, reposName, path: path, branch: branchControl.currentBranch, text: true, isHtml: true).then((res) {
139+
if (res != null && res.result) {
140+
Navigator.pop(context);
141+
String data = HtmlUtils.resolveHtmlFile(res, "java");
142+
CommonUtils.launchWebView(context, fileItemViewModel.name, data);
143+
}
144+
});
145+
}
133146
}
134147
}
135148
}

0 commit comments

Comments
 (0)