means_pdf.dart 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import 'package:flutter_full_pdf_viewer/flutter_full_pdf_viewer.dart';
  2. import 'package:flutter_full_pdf_viewer/full_pdf_viewer_scaffold.dart';
  3. import 'dart:async';
  4. import 'package:flutter/foundation.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:liftmanager/internal/means/page/pdf_scaffold.dart';
  7. import 'package:liftmanager/res/iconfont.dart';
  8. import 'package:liftmanager/routers/fluro_navigator.dart';
  9. import 'package:liftmanager/utils/theme_utils.dart';
  10. import 'package:liftmanager/widgets/app_bar.dart';
  11. import 'package:liftmanager/widgets/load_image.dart';
  12. import 'package:liftmanager/widgets/popup_window.dart';
  13. import 'package:path_provider/path_provider.dart';
  14. import 'package:liftmanager/utils/toast.dart';
  15. import 'package:liftmanager/net/api_service.dart';
  16. // class MeansPDF extends StatefulWidget {
  17. // @override
  18. // MeansPDFState createState() => new MeansPDFState();
  19. // }
  20. // class MeansPDFState extends State<MeansPDF> {
  21. // String pathPDF = "";
  22. // @override
  23. // void initState() {
  24. // super.initState();
  25. // createFileOfPdfUrl().then((f) {
  26. // setState(() {
  27. // pathPDF = f.path;
  28. // print(pathPDF);
  29. // });
  30. // });
  31. // }
  32. // Future<File> createFileOfPdfUrl() async {
  33. // final url = "http://africau.edu/images/default/sample.pdf";
  34. // final filename = url.substring(url.lastIndexOf("/") + 1);
  35. // var request = await HttpClient().getUrl(Uri.parse(url));
  36. // var response = await request.close();
  37. // var bytes = await consolidateHttpClientResponseBytes(response);
  38. // String dir = (await getApplicationDocumentsDirectory()).path;
  39. // File file = new File('$dir/$filename');
  40. // await file.writeAsBytes(bytes);
  41. // return file;
  42. // }
  43. // @override
  44. // Widget build(BuildContext context) {
  45. // return Container(
  46. // child: PDFScreen(pathPDF)
  47. // )
  48. // ;
  49. // }
  50. // // Widget build(BuildContext context) {
  51. // // return Scaffold(
  52. // // appBar: AppBar(title: const Text('Plugin example app')),
  53. // // body: Center(
  54. // // child: RaisedButton(
  55. // // child: Text("Open PDF"),
  56. // // onPressed: () => Navigator.push(
  57. // // context,
  58. // // MaterialPageRoute(builder: (context) => PDFScreen(pathPDF)),
  59. // // ),
  60. // // ),
  61. // // ),
  62. // // );
  63. // // }
  64. // }
  65. class PDFScreen extends StatelessWidget {
  66. String pathPDF = "";
  67. String fileUrl = "";
  68. String id = "";
  69. PDFScreen(this.pathPDF, this.fileUrl, this.id);
  70. GlobalKey _addKey = GlobalKey();
  71. getUpdateDownLoadNum() {
  72. // showLoading(context);
  73. NewApiService().getUpdateDownLoadNum(id, onSuccess: (res) {},
  74. onError: (code, msg) {
  75. // dismissLoading(context);
  76. toasts(msg);
  77. });
  78. }
  79. getViewNum(context) {
  80. // showLoading(context);
  81. // NewApiService().getLiftFilesDetail(id, onSuccess: (res) {},
  82. // onError: (code, msg) {
  83. // // dismissLoading(context);
  84. // toasts(msg);
  85. // });
  86. }
  87. @override
  88. Widget build(BuildContext context) {
  89. print(pathPDF);
  90. print(fileUrl);
  91. print(id);
  92. if (id != null && id != "null") {
  93. getViewNum(context);
  94. }
  95. Future<String> _findLocalPath() async {
  96. //这里根据平台获取当前安装目录
  97. final directory = Theme.of(context).platform == TargetPlatform.android
  98. ? await getExternalStorageDirectory()
  99. : await getApplicationDocumentsDirectory();
  100. return directory.path;
  101. }
  102. return CzPDFViewerScaffold(
  103. appBar: MyAppBar(
  104. centerTitle: fileUrl != null && fileUrl != "null" ? '电梯资料库' : "文件详情",
  105. // actions: [
  106. // IconButton(
  107. // key: _addKey,
  108. // icon: Icon(Iconfont.gengduo),
  109. // onPressed: () {
  110. // _showAddMenu(context);
  111. // })
  112. // ],
  113. // actions: <Widget>[
  114. // fileUrl!=null&&fileUrl!="null"? FlatButton(
  115. // child: Text("下载"),
  116. // textColor: Colours.dark_text,
  117. // highlightColor: Colors.transparent,
  118. // onPressed: () async {
  119. // String _localPath = (await _findLocalPath()) + '/Download/';
  120. // var pos = fileUrl.lastIndexOf("/");
  121. // if (pos == -1) {
  122. // pos = fileUrl.lastIndexOf("\\");
  123. // }
  124. // var filename = fileUrl.substring(pos + 1);
  125. // Response responce =
  126. // await Dio().download(fileUrl, _localPath + filename);
  127. // if (responce.statusCode == 200) {
  128. // // Scaffold.of(context).showSnackBar(SnackBar(content: Text("下载成功")));
  129. // getUpdateDownLoadNum();
  130. // toasts("下载成功");
  131. // } else {
  132. // // Scaffold.of(context).showSnackBar(SnackBar(content: Text("下载失败")));
  133. // toasts("下载失败");
  134. // }
  135. // },
  136. // ):Container(child:null,)
  137. // ],
  138. ),
  139. path: pathPDF);
  140. }
  141. _showAddMenu(BuildContext context) {
  142. final RenderBox button = _addKey.currentContext.findRenderObject();
  143. final RenderBox overlay = Overlay.of(context).context.findRenderObject();
  144. var a = button.localToGlobal(
  145. Offset(button.size.width - 8.0, button.size.height - 12.0),
  146. ancestor: overlay);
  147. var b = button.localToGlobal(button.size.bottomLeft(Offset(0, -12.0)),
  148. ancestor: overlay);
  149. final RelativeRect position = RelativeRect.fromRect(
  150. Rect.fromPoints(a, b),
  151. Offset.zero & overlay.size,
  152. );
  153. final Color backgroundColor = ThemeUtils.getBackgroundColor(context);
  154. final Color _iconColor = ThemeUtils.getIconColor(context);
  155. showPopupWindow(
  156. context: context,
  157. fullWidth: false,
  158. isShowBg: true,
  159. position: position,
  160. elevation: 2,
  161. child: GestureDetector(
  162. onTap: () => NavigatorUtils.goBack(context),
  163. child: Column(
  164. crossAxisAlignment: CrossAxisAlignment.end,
  165. children: <Widget>[
  166. Padding(
  167. padding: const EdgeInsets.only(right: 12.0),
  168. child: LoadAssetImage(
  169. "icon_jt",
  170. width: 8.0,
  171. height: 4.0,
  172. ),
  173. ),
  174. SizedBox(
  175. width: 120.0,
  176. height: 40.0,
  177. child: FlatButton.icon(
  178. textColor: Theme.of(context).textTheme.body1.color,
  179. onPressed: () {
  180. Navigator.pop(context);
  181. // NavigatorUtils.pushResult(
  182. // context, '${TeamRouter.teamCreatePage}', (res) {
  183. // _onRefresh();
  184. // });
  185. },
  186. color: backgroundColor,
  187. shape: RoundedRectangleBorder(
  188. borderRadius: BorderRadius.only(
  189. topLeft: Radius.circular(8.0),
  190. topRight: Radius.circular(8.0)),
  191. ),
  192. icon: LoadAssetImage(
  193. "wode/icon_team_add",
  194. width: 16.0,
  195. height: 16.0,
  196. color: _iconColor,
  197. ),
  198. label: const Text("创建团队")),
  199. ),
  200. Divider(),
  201. SizedBox(
  202. width: 120.0,
  203. height: 40.0,
  204. child: FlatButton.icon(
  205. textColor: Theme.of(context).textTheme.body1.color,
  206. color: backgroundColor,
  207. onPressed: () {
  208. Navigator.pop(context);
  209. // NavigatorUtils.push(
  210. // context, '${TeamRouter.teamSearchPage}');
  211. },
  212. shape: RoundedRectangleBorder(
  213. borderRadius: BorderRadius.only(
  214. bottomLeft: Radius.circular(8.0),
  215. bottomRight: Radius.circular(8.0)),
  216. ),
  217. icon: LoadAssetImage(
  218. "wode/icon_team_add",
  219. width: 16.0,
  220. height: 16.0,
  221. color: _iconColor,
  222. ),
  223. label: const Text("加入团队")),
  224. ),
  225. ],
  226. ),
  227. ),
  228. );
  229. }
  230. }