Repository navigation
Expand file tree
/
Copy pathcode_detail_page_web.dart
More file actions
125 lines (108 loc) · 3.17 KB
/
Copy pathcode_detail_page_web.dart
File metadata and controls
125 lines (108 loc) · 3.17 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
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:gsy_github_app_flutter/common/config/config.dart';
import 'package:gsy_github_app_flutter/common/dao/repos_dao.dart';
import 'package:gsy_github_app_flutter/common/style/gsy_style.dart';
import 'package:gsy_github_app_flutter/common/utils/common_utils.dart';
import 'package:gsy_github_app_flutter/common/utils/html_utils.dart';
import 'package:gsy_github_app_flutter/widget/gsy_title_bar.dart';
import 'package:webview_flutter/webview_flutter.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(data);
}
class _CodeDetailPageState extends State<CodeDetailPageWeb> {
String data;
_CodeDetailPageState(this.data);
@override
void initState() {
super.initState();
if (data == null) {
ReposDao.getReposFileDirDao(widget.userName, widget.reposName,
path: widget.path,
branch: widget.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(widget.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 && Platform.isAndroid) {
return Scaffold(
appBar: AppBar(
title: new Text(widget.title),
),
body: WebView(
initialUrl: data,
javascriptMode: JavascriptMode.unrestricted,
),
);
}
return Scaffold(
appBar: AppBar(
title: new Text(widget.title),
),
body: WebView(
initialUrl: data,
javascriptMode: JavascriptMode.unrestricted,
),
);
}
}