From 857e0c011d26394981bf91344965f287200e1e7e Mon Sep 17 00:00:00 2001 From: laiiihz Date: Thu, 1 Apr 2021 11:26:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/api.dart | 1 + .../event_activity/voting_detail_page.dart | 5 +- .../activity/activity_detail_page.dart | 6 +- .../community/notice/notice_detail_page.dart | 8 ++- lib/widget/views/ bee_download_view.dart | 62 +++++++++++++++++++ pubspec.lock | 7 +++ pubspec.yaml | 3 +- 7 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 lib/widget/views/ bee_download_view.dart diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 03c231f7..2acf4a82 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -9,6 +9,7 @@ class API { static String get resource => '$host/static'; static String image(String path) => '$resource$path'; + static String file(String path) => '$resource$path'; static const int networkTimeOut = 10000; static _Login login = _Login(); diff --git a/lib/pages/event_activity/voting_detail_page.dart b/lib/pages/event_activity/voting_detail_page.dart index 98d2b45b..15a54e65 100644 --- a/lib/pages/event_activity/voting_detail_page.dart +++ b/lib/pages/event_activity/voting_detail_page.dart @@ -219,8 +219,9 @@ class _VotingDetailPageState extends State { child: ClipRRect( borderRadius: BorderRadius.circular(8.w), child: FadeInImage.assetNetwork( - placeholder: R.ASSETS_IMAGES_LOGO_PNG, - image: API.image(_model.imgUrls.first.url)), + placeholder: R.ASSETS_IMAGES_LOGO_PNG, + image: API.image(_model.imgUrls.first.url), + ), ), ), 44.w.heightBox, diff --git a/lib/ui/community/activity/activity_detail_page.dart b/lib/ui/community/activity/activity_detail_page.dart index 63f2af2b..59738d7f 100644 --- a/lib/ui/community/activity/activity_detail_page.dart +++ b/lib/ui/community/activity/activity_detail_page.dart @@ -105,12 +105,12 @@ class _ActivityDetailPageState extends State { .map((e) => GestureDetector( onTap: () { Get.to( - BeeImagePreview.path(path: API.image(e.url)), + BeeImagePreview.path(path: e.url), opaque: false, ); }, child: Hero( - tag: API.image(e.url), + tag: e.url, child: Container( height: 228.w, decoration: BoxDecoration( @@ -120,7 +120,7 @@ class _ActivityDetailPageState extends State { clipBehavior: Clip.antiAlias, child: FadeInImage.assetNetwork( placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, - image: e.url, + image: API.image(e.url), fit: BoxFit.cover, ), ), diff --git a/lib/ui/community/notice/notice_detail_page.dart b/lib/ui/community/notice/notice_detail_page.dart index e506a485..7d849ef9 100644 --- a/lib/ui/community/notice/notice_detail_page.dart +++ b/lib/ui/community/notice/notice_detail_page.dart @@ -1,7 +1,10 @@ +import 'package:akuCommunity/widget/views/%20bee_download_view.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:get/get.dart'; +import 'package:open_file/open_file.dart'; import 'package:velocity_x/velocity_x.dart'; import 'package:akuCommunity/const/resource.dart'; @@ -48,7 +51,10 @@ class _NoticeDetailPageState extends State { ), ], ), - onPressed: () {}, + onPressed: () async { + String result = await Get.dialog(BeeDownloadView(file: path)); + if (result != null) OpenFile.open(result); + }, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8.w), side: BorderSide(color: Color(0xFFD4CFBE)), diff --git a/lib/widget/views/ bee_download_view.dart b/lib/widget/views/ bee_download_view.dart new file mode 100644 index 00000000..4ed7366d --- /dev/null +++ b/lib/widget/views/ bee_download_view.dart @@ -0,0 +1,62 @@ +import 'dart:io'; + +import 'package:dio/dio.dart'; +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:path_provider/path_provider.dart'; + +import 'package:akuCommunity/constants/api.dart'; + +class BeeDownloadView extends StatefulWidget { + final String file; + BeeDownloadView({Key key, this.file}) : super(key: key); + + @override + _BeeDownloadViewState createState() => _BeeDownloadViewState(); +} + +class _BeeDownloadViewState extends State { + Dio dio = Dio(); + double progress; + Future download() async { + Directory dir = await getApplicationDocumentsDirectory(); + Directory docPath = Directory('${dir.path}/docs'); + if (!await (docPath.exists())) { + await docPath.create(); + } + await Future.delayed(Duration(milliseconds: 500)); + await dio.download( + API.file(widget.file), + '${docPath.path}/${widget.file.split('/').last}', + onReceiveProgress: (start, all) { + setState(() { + progress = start / all; + }); + print('$start,$all'); + }, + ); + Get.back(result: '${docPath.path}/${widget.file.split('/').last}'); + } + + @override + void initState() { + super.initState(); + download(); + } + + @override + Widget build(BuildContext context) { + return Center( + child: Container( + width: 100, + height: 100, + alignment: Alignment.center, + child: CircularProgressIndicator(value: progress), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + ), + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 754feb35..40a88c21 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -471,6 +471,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.0-nullsafety.1" + open_file: + dependency: "direct main" + description: + name: open_file + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.1.0" package_info: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 61b47be1..d8dea878 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -58,7 +58,7 @@ dependencies: power_logger: ^1.0.0-nullsafety.0 flutter_rating_bar: ^4.0.0 jpush_flutter: ^2.0.1 - + open_file: ^3.1.0 badges: ^2.0.0-nullsafety.1 amap_flutter_map: git: @@ -67,6 +67,7 @@ dependencies: amap_flutter_location: ^1.0.1 amap_flutter_base: ^1.0.2 animated_text_kit: ^4.1.1 + dev_dependencies: flutter_test: