forked from CarGuo/gsy_github_app_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeDetailPageWeb.dart
More file actions
128 lines (104 loc) · 3.39 KB
/
CodeDetailPageWeb.dart
File metadata and controls
128 lines (104 loc) · 3.39 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:gsy_github_app_flutter/common/config/Config.dart';
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
import 'package:gsy_github_app_flutter/common/utils/HtmlUtils.dart';
import 'package:gsy_github_app_flutter/widget/GSYTitleBar.dart';
import 'package:gsy_github_app_flutter/widget/webview/WebView.dart';
/**
* 文件代码详情
* Created by guoshuyu
* Date: 2018-07-24
*/
class CodeDetailPageWeb extends StatefulWidget {
final String userName;
final String reposName;
final String path;
final String data;
final String title;
final String branch;
final String htmlUrl;
CodeDetailPageWeb({this.title, this.userName, this.reposName, this.path, this.data, this.branch, this.htmlUrl});
@override
_CodeDetailPageState createState() => _CodeDetailPageState(this.title, this.userName, this.reposName, this.path, this.data, this.branch, this.htmlUrl);
}
class _CodeDetailPageState extends State<CodeDetailPageWeb> {
final String userName;
final String reposName;
final String path;
final String branch;
final String htmlUrl;
String data ;
final String title;
_CodeDetailPageState(this.title, this.userName, this.reposName, this.path, this.data, this.branch, this.htmlUrl);
@override
void initState() {
super.initState();
if (data == null) {
ReposDao.getReposFileDirDao(userName, reposName, path: path, branch: branch, text: true, isHtml: true).then((res) {
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();
setState(() {
this.data = url;
});
}
});
}
}
@override
Widget build(BuildContext context) {
if (data == null) {
return new Scaffold(
appBar: new AppBar(
title: GSYTitleBar(
title
),
),
body: new Center(
child: new Container(
width: 200.0,
height: 200.0,
padding: new EdgeInsets.all(4.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new SpinKitDoubleBounce(color: Theme
.of(context)
.primaryColor),
new Container(width: 10.0),
new Container(child: new Text(CommonUtils
.getLocale(context)
.loading_text, style: GSYConstant.middleText)),
],
),
),
),
);
}
if (Config.USE_NATIVE_WEBVIEW) {
return Scaffold(
appBar: AppBar(
title: new Text(title),
),
body: WebView(
initialUrl: data,
javaScriptMode: JavaScriptMode.unrestricted,
),
);
}
return new WebviewScaffold(
withJavascript: true,
url: data,
scrollBar:false,
withLocalUrl: true,
appBar: new AppBar(
title: new Text(title),
),
);
}
}