添加文件下载

hmxc
小赖 4 years ago
parent 49991ff863
commit 857e0c011d

@ -9,6 +9,7 @@ class API {
static String get resource => '$host/static'; static String get resource => '$host/static';
static String image(String path) => '$resource$path'; static String image(String path) => '$resource$path';
static String file(String path) => '$resource$path';
static const int networkTimeOut = 10000; static const int networkTimeOut = 10000;
static _Login login = _Login(); static _Login login = _Login();

@ -220,7 +220,8 @@ class _VotingDetailPageState extends State<VotingDetailPage> {
borderRadius: BorderRadius.circular(8.w), borderRadius: BorderRadius.circular(8.w),
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_LOGO_PNG,
image: API.image(_model.imgUrls.first.url)), image: API.image(_model.imgUrls.first.url),
),
), ),
), ),
44.w.heightBox, 44.w.heightBox,

@ -105,12 +105,12 @@ class _ActivityDetailPageState extends State<ActivityDetailPage> {
.map((e) => GestureDetector( .map((e) => GestureDetector(
onTap: () { onTap: () {
Get.to( Get.to(
BeeImagePreview.path(path: API.image(e.url)), BeeImagePreview.path(path: e.url),
opaque: false, opaque: false,
); );
}, },
child: Hero( child: Hero(
tag: API.image(e.url), tag: e.url,
child: Container( child: Container(
height: 228.w, height: 228.w,
decoration: BoxDecoration( decoration: BoxDecoration(
@ -120,7 +120,7 @@ class _ActivityDetailPageState extends State<ActivityDetailPage> {
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: e.url, image: API.image(e.url),
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
), ),

@ -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/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:open_file/open_file.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
import 'package:akuCommunity/const/resource.dart'; import 'package:akuCommunity/const/resource.dart';
@ -48,7 +51,10 @@ class _NoticeDetailPageState extends State<NoticeDetailPage> {
), ),
], ],
), ),
onPressed: () {}, onPressed: () async {
String result = await Get.dialog(BeeDownloadView(file: path));
if (result != null) OpenFile.open(result);
},
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.w), borderRadius: BorderRadius.circular(8.w),
side: BorderSide(color: Color(0xFFD4CFBE)), side: BorderSide(color: Color(0xFFD4CFBE)),

@ -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<BeeDownloadView> {
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,
),
),
);
}
}

@ -471,6 +471,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.0-nullsafety.1" 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: package_info:
dependency: "direct main" dependency: "direct main"
description: description:

@ -58,7 +58,7 @@ dependencies:
power_logger: ^1.0.0-nullsafety.0 power_logger: ^1.0.0-nullsafety.0
flutter_rating_bar: ^4.0.0 flutter_rating_bar: ^4.0.0
jpush_flutter: ^2.0.1 jpush_flutter: ^2.0.1
open_file: ^3.1.0
badges: ^2.0.0-nullsafety.1 badges: ^2.0.0-nullsafety.1
amap_flutter_map: amap_flutter_map:
git: git:
@ -68,6 +68,7 @@ dependencies:
amap_flutter_base: ^1.0.2 amap_flutter_base: ^1.0.2
animated_text_kit: ^4.1.1 animated_text_kit: ^4.1.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter

Loading…
Cancel
Save