|
| 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 | +} |
0 commit comments