Skip to content

Commit e21bc85

Browse files
committed
替换webview
1 parent 446b8c1 commit e21bc85

File tree

4 files changed

+142
-4
lines changed

4 files changed

+142
-4
lines changed

lib/common/utils/CommonUtils.dart

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

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

lib/common/utils/NavigatorUtils.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22

33
import 'package:flutter/material.dart';
44
import 'package:gsy_github_app_flutter/page/CodeDetailPage.dart';
5+
import 'package:gsy_github_app_flutter/page/CodeDetailPageWeb.dart';
56
import 'package:gsy_github_app_flutter/page/CommonListPage.dart';
67
import 'package:gsy_github_app_flutter/page/GSYWebView.dart';
78
import 'package:gsy_github_app_flutter/page/HomePage.dart';
@@ -124,4 +125,20 @@ class NavigatorUtils {
124125
);
125126
}
126127

128+
///文件代码详情
129+
static gotoCodeDetailPageWeb(BuildContext context, {String title, String userName, String reposName, String path, String data, String branch, String htmlUrl}) {
130+
Navigator.push(
131+
context,
132+
new MaterialPageRoute(
133+
builder: (context) => new CodeDetailPageWeb(
134+
title: title,
135+
userName: userName,
136+
reposName: reposName,
137+
path: path,
138+
data: data,
139+
branch: branch,
140+
htmlUrl: htmlUrl,
141+
)));
142+
}
143+
127144
}

lib/page/CodeDetailPageWeb.dart

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import 'dart:convert';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_spinkit/flutter_spinkit.dart';
5+
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
6+
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
7+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
8+
import 'package:gsy_github_app_flutter/common/utils/HtmlUtils.dart';
9+
import 'package:gsy_github_app_flutter/widget/GSYTitleBar.dart';
10+
11+
/**
12+
* 文件代码详情
13+
* Created by guoshuyu
14+
* Date: 2018-07-24
15+
*/
16+
17+
class CodeDetailPageWeb extends StatefulWidget {
18+
final String userName;
19+
20+
final String reposName;
21+
22+
final String path;
23+
24+
final String data;
25+
26+
final String title;
27+
28+
final String branch;
29+
30+
final String htmlUrl;
31+
32+
CodeDetailPageWeb({this.title, this.userName, this.reposName, this.path, this.data, this.branch, this.htmlUrl});
33+
34+
@override
35+
_CodeDetailPageState createState() => _CodeDetailPageState(this.title, this.userName, this.reposName, this.path, this.data, this.branch, this.htmlUrl);
36+
}
37+
38+
class _CodeDetailPageState extends State<CodeDetailPageWeb> {
39+
final String userName;
40+
41+
final String reposName;
42+
43+
final String path;
44+
45+
final String branch;
46+
47+
final String htmlUrl;
48+
49+
String data ;
50+
51+
final String title;
52+
53+
_CodeDetailPageState(this.title, this.userName, this.reposName, this.path, this.data, this.branch, this.htmlUrl);
54+
55+
@override
56+
void initState() {
57+
super.initState();
58+
print("22222222");
59+
if (data == null) {
60+
print("333333333");
61+
ReposDao.getReposFileDirDao(userName, reposName, path: path, branch: branch, text: true, isHtml: true).then((res) {
62+
if (res != null && res.result) {
63+
String data2 = HtmlUtils.resolveHtmlFile(res, "java");
64+
final flutterWebviewPlugin = new FlutterWebviewPlugin();
65+
String url = new Uri.dataFromString(data2, mimeType: 'text/html', encoding: Encoding.getByName("utf-8")).toString();
66+
print("-------------");
67+
print(url);
68+
flutterWebviewPlugin.reload();
69+
setState(() {
70+
this.data = url;
71+
});
72+
}
73+
});
74+
}
75+
}
76+
77+
@override
78+
Widget build(BuildContext context) {
79+
if(data == null) {
80+
return new Scaffold(
81+
appBar: new AppBar(
82+
title: GSYTitleBar(
83+
title
84+
),
85+
),
86+
body: new Center(
87+
child: new Container(
88+
width: 140.0,
89+
height: 140.0,
90+
padding: new EdgeInsets.all(4.0),
91+
child: new Row(
92+
mainAxisAlignment: MainAxisAlignment.center,
93+
children: <Widget>[
94+
new SpinKitDoubleBounce(color: Color(GSYColors.primaryValue)),
95+
new Container(width: 10.0),
96+
new Container(child: new Text(GSYStrings.loading_text, style: GSYConstant.middleText)),
97+
],
98+
),
99+
),
100+
),
101+
);
102+
}
103+
return new WebviewScaffold(
104+
withJavascript: true,
105+
url: data,
106+
withLocalUrl: true,
107+
appBar: new AppBar(
108+
title: new Text(title),
109+
),
110+
);
111+
;
112+
}
113+
}

lib/page/RepositoryFileListPage.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,25 @@ class RepositoryDetailFileListPageState extends GSYListState<RepositoryDetailFil
133133
path: path,
134134
branch: branchControl.currentBranch,
135135
);
136+
137+
136138
} else {
137-
CommonUtils.showLoadingDialog(context);
139+
/*CommonUtils.showLoadingDialog(context);
138140
ReposDao.getReposFileDirDao(userName, reposName, path: path, branch: branchControl.currentBranch, text: true, isHtml: true).then((res) {
139141
if (res != null && res.result) {
140142
Navigator.pop(context);
141143
String data = HtmlUtils.resolveHtmlFile(res, "java");
142144
CommonUtils.launchWebView(context, fileItemViewModel.name, data);
143145
}
144-
});
146+
});*/
147+
NavigatorUtils.gotoCodeDetailPageWeb(
148+
context,
149+
title: fileItemViewModel.name,
150+
reposName: reposName,
151+
userName: userName,
152+
path: path,
153+
branch: branchControl.currentBranch,
154+
);
145155
}
146156
}
147157
}

0 commit comments

Comments
 (0)