@@ -3,8 +3,11 @@ import 'dart:io';
33import 'package:extended_image/extended_image.dart' ;
44import 'package:flutter/cupertino.dart' ;
55import 'package:flutter/material.dart' ;
6+ import 'package:flutter/services.dart' ;
67import 'package:flutter_picgo/components/upload_item/upload_item_presenter.dart' ;
78import 'package:flutter_picgo/utils/extended.dart' ;
9+ import 'package:flutter_picgo/utils/local_notification.dart' ;
10+ import 'package:toast/toast.dart' ;
811
912enum UploadState {
1013 /// 上传中
@@ -26,8 +29,9 @@ enum UploadState {
2629class UploadItem extends StatefulWidget {
2730 final File file;
2831 final String rename;
32+ final bool needNotify;
2933
30- UploadItem (this .file, this .rename);
34+ UploadItem (this .file, this .rename, { this .needNotify = false } );
3135
3236 @override
3337 _UploadItemState createState () => _UploadItemState ();
@@ -36,6 +40,9 @@ class UploadItem extends StatefulWidget {
3640class _UploadItemState extends State <UploadItem > implements UploadItemContract {
3741 UploadState _state;
3842 UploadItemPresenter _presenter;
43+ String _uploadedImageUrl = '' ;
44+
45+ /// construct
3946 _UploadItemState () {
4047 _state = UploadState .Uploading ;
4148 _presenter = new UploadItemPresenter (this );
@@ -81,7 +88,9 @@ class _UploadItemState extends State<UploadItem> implements UploadItemContract {
8188 style: TextStyle (color: Colors .grey),
8289 ),
8390 trailing: buildStateTip (),
84- onTap: () {},
91+ onTap: () {
92+ _handleTap ();
93+ },
8594 );
8695 }
8796
@@ -98,6 +107,7 @@ class _UploadItemState extends State<UploadItem> implements UploadItemContract {
98107 return Icon (
99108 Icons .done,
100109 size: 16 ,
110+ color: Colors .green,
101111 );
102112 case UploadState .UploadFail :
103113 case UploadState .SaveFail :
@@ -141,17 +151,43 @@ class _UploadItemState extends State<UploadItem> implements UploadItemContract {
141151 _presenter.doUploadImage (widget.file, widget.rename);
142152 }
143153
154+ /// 处理点击事件
155+ _handleTap () {
156+ if (_state == UploadState .Complete ) {
157+ Clipboard .setData (ClipboardData (text: _uploadedImageUrl));
158+ Toast .show ('已复制到剪切板' , context);
159+ } else {
160+ Toast .show ('当前状态无法操作' , context);
161+ }
162+ }
163+
144164 @override
145165 uploadFaild (String errorMsg) {
146166 setState (() {
147167 _state = UploadState .UploadFail ;
148168 });
169+
170+ _showNotification (0 , '${widget .rename }上传失败:$errorMsg ' );
149171 }
150172
151173 @override
152- uploadSuccess (String url) {
174+ uploadSuccess (String url) async {
175+ _uploadedImageUrl = url;
153176 setState (() {
154177 _state = UploadState .Complete ;
155178 });
179+
180+ _showNotification (0 , '${widget .rename }上传成功:$url ' );
181+ }
182+
183+ Future <void > _showNotification (int id, String body) async {
184+ LocalNotificationUtil .getInstance ().show (
185+ id,
186+ '上传提示' ,
187+ body,
188+ LocalNotificationUtil .createNotificationDetails (
189+ LocalNotificationUtil .uploadAndroidChannel (),
190+ LocalNotificationUtil .normalIOSNotificationDetails (),
191+ LocalNotificationUtil .normalMacOSNotificationDetails ()));
156192 }
157193}
0 commit comments