forked from lxm_tools/flutter-picgo
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03dbf3ad93 | ||
|
|
b01bf49a0f | ||
|
|
fbb877e12f | ||
|
|
a9b70bc259 | ||
|
|
9680e1660f | ||
|
|
04b41548fe | ||
|
|
5c3eecf284 | ||
|
|
be70cc70e1 | ||
|
|
479fa4700c | ||
|
|
105ff1d806 |
@@ -4,8 +4,8 @@
|
||||
<blockquote>图片上传+管理新体验 </blockquote>
|
||||
<img src="https://img.shields.io/github/license/hackycy/flutter-picgo" alt="">
|
||||
<img src="https://img.shields.io/github/workflow/status/hackycy/flutter-picgo/Build and Release apk" alt="">
|
||||
<img src="https://img.shields.io/github/repo-size/hackycy/flutter-picgo" alt="">
|
||||
<img src="https://img.shields.io/github/v/release/hackycy/flutter-picgo" alt="">
|
||||
<img src="https://img.shields.io/github/issues-closed/hackycy/flutter-picgo" alt="">
|
||||
<img src="https://img.shields.io/github/v/release/hackycy/flutter-picgo?include_prereleases" alt="">
|
||||
<img src="https://img.shields.io/github/downloads/hackycy/flutter-picgo/total" alt="">
|
||||
</div>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"versionCode": "22"
|
||||
},
|
||||
"Android": {
|
||||
"versionName": "1.9.1",
|
||||
"versionCode": "22"
|
||||
"versionName": "1.9.2",
|
||||
"versionCode": "23"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_picgo/utils/image_upload.dart';
|
||||
import 'package:flutter_picgo/utils/strategy/upload_strategy_factory.dart';
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import 'package:flutter_picgo/views/pb_setting_page/tcyun_page/tcyun_page.dart';
|
||||
import 'package:flutter_picgo/views/pb_setting_page/upyun_page/upyun_page.dart';
|
||||
import 'package:flutter_picgo/views/picgo_setting_page/theme_setting_page.dart';
|
||||
import 'package:flutter_picgo/views/upload_page/handle_upload_page.dart';
|
||||
import 'package:flutter_picgo/views/upload_page/upload_page.dart';
|
||||
import 'package:flutter_picgo/views/pb_setting_page/github_page/github_page.dart';
|
||||
import 'package:flutter_picgo/views/picgo_setting_page/picgo_setting_page.dart';
|
||||
import 'package:flutter_picgo/views/setting_page/setting_page.dart';
|
||||
@@ -56,11 +55,6 @@ var settingHandler = new Handler(
|
||||
);
|
||||
|
||||
// 上传页面
|
||||
var uploadHandler = new Handler(
|
||||
handlerFunc: (BuildContext context, Map<String, List<String>> params) =>
|
||||
UploadPage(),
|
||||
);
|
||||
|
||||
var preUploadHandler = new Handler(
|
||||
handlerFunc: (context, parameters) {
|
||||
final assets = context.settings.arguments as List<AssetEntity>;
|
||||
|
||||
@@ -50,7 +50,6 @@ class Routes {
|
||||
router.define(root, handler: appHandler);
|
||||
router.define(notfound, handler: notfoundHandler);
|
||||
router.define(album, handler: albumHandler);
|
||||
router.define(upload, handler: uploadHandler);
|
||||
router.define(handleUpload, handler: preUploadHandler);
|
||||
router.define(setting, handler: settingHandler);
|
||||
router.define(settingPb, handler: pbsettingHandler);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_picgo/resources/pb_type_keys.dart';
|
||||
import 'package:flutter_picgo/resources/table_name_keys.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
@@ -4,15 +4,15 @@ import 'dart:math';
|
||||
import 'package:extended_image/extended_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_picgo/model/uploaded.dart';
|
||||
import 'package:flutter_picgo/utils/extended.dart';
|
||||
import 'package:toast/toast.dart';
|
||||
|
||||
class ImagePreviewUtils {
|
||||
/// 打开图片预览页面
|
||||
static void open(BuildContext context, String content) {
|
||||
var item = new GalleryItem(id: '0', resource: '$content');
|
||||
static void open(BuildContext context, Uploaded content) {
|
||||
var page = GalleryPhotoViewWrapper(
|
||||
galleryItems: [item],
|
||||
galleryItems: [content],
|
||||
);
|
||||
Navigator.push(
|
||||
context,
|
||||
@@ -22,8 +22,7 @@ class ImagePreviewUtils {
|
||||
);
|
||||
}
|
||||
|
||||
static void openMulti(
|
||||
BuildContext context, int index, List<GalleryItem> items) {
|
||||
static void openMulti(BuildContext context, int index, List<Uploaded> items) {
|
||||
var page = GalleryPhotoViewWrapper(
|
||||
galleryItems: items,
|
||||
initialIndex: index,
|
||||
@@ -36,16 +35,9 @@ class ImagePreviewUtils {
|
||||
}
|
||||
}
|
||||
|
||||
class GalleryItem {
|
||||
GalleryItem({this.id, this.resource});
|
||||
|
||||
final String id;
|
||||
final String resource;
|
||||
}
|
||||
|
||||
class GalleryPhotoViewWrapper extends StatefulWidget {
|
||||
final int initialIndex;
|
||||
final List<GalleryItem> galleryItems;
|
||||
final List<Uploaded> galleryItems;
|
||||
|
||||
GalleryPhotoViewWrapper({
|
||||
this.initialIndex = 0,
|
||||
@@ -85,44 +77,67 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
|
||||
color: Colors.black,
|
||||
pageGestureAxis: SlideAxis.both),
|
||||
child: GestureDetector(
|
||||
child: ExtendedImageGesturePageView.builder(
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
var item = widget.galleryItems[index];
|
||||
Widget image = item.resource.startsWith('http')
|
||||
? ExtendedImage.network(
|
||||
item.resource,
|
||||
fit: BoxFit.contain,
|
||||
cache: true,
|
||||
mode: ExtendedImageMode.gesture,
|
||||
enableSlideOutPage: true,
|
||||
loadStateChanged: (state) =>
|
||||
defaultLoadStateChanged(state, iconSize: 50),
|
||||
)
|
||||
: ExtendedImage.file(
|
||||
File(item.resource),
|
||||
fit: BoxFit.contain,
|
||||
mode: ExtendedImageMode.gesture,
|
||||
enableSlideOutPage: true,
|
||||
loadStateChanged: (state) =>
|
||||
defaultLoadStateChanged(state, iconSize: 50),
|
||||
child: Stack(
|
||||
// fit: StackFit.expand,
|
||||
alignment: Alignment.bottomRight,
|
||||
children: [
|
||||
ExtendedImageGesturePageView.builder(
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
var item = widget.galleryItems[index];
|
||||
Widget image = item.path.startsWith('http')
|
||||
? ExtendedImage.network(
|
||||
item.path,
|
||||
fit: BoxFit.contain,
|
||||
cache: true,
|
||||
mode: ExtendedImageMode.gesture,
|
||||
enableSlideOutPage: true,
|
||||
loadStateChanged: (state) =>
|
||||
defaultLoadStateChanged(state, iconSize: 50),
|
||||
)
|
||||
: ExtendedImage.file(
|
||||
File(item.path),
|
||||
fit: BoxFit.contain,
|
||||
mode: ExtendedImageMode.gesture,
|
||||
enableSlideOutPage: true,
|
||||
loadStateChanged: (state) =>
|
||||
defaultLoadStateChanged(state, iconSize: 50),
|
||||
);
|
||||
image = Container(
|
||||
child: image,
|
||||
);
|
||||
if (index == currentIndex) {
|
||||
return Hero(
|
||||
tag: index,
|
||||
child: image,
|
||||
);
|
||||
image = Container(
|
||||
child: image,
|
||||
);
|
||||
if (index == currentIndex) {
|
||||
return Hero(
|
||||
tag: index,
|
||||
child: image,
|
||||
);
|
||||
} else {
|
||||
return image;
|
||||
}
|
||||
},
|
||||
itemCount: widget.galleryItems.length,
|
||||
controller: PageController(
|
||||
initialPage: currentIndex,
|
||||
),
|
||||
scrollDirection: Axis.horizontal,
|
||||
} else {
|
||||
return image;
|
||||
}
|
||||
},
|
||||
itemCount: widget.galleryItems.length,
|
||||
controller: PageController(
|
||||
initialPage: currentIndex,
|
||||
),
|
||||
onPageChanged: onPageChanged,
|
||||
scrollDirection: Axis.horizontal,
|
||||
),
|
||||
SafeArea(
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(right: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(4)),
|
||||
color: Colors.grey),
|
||||
padding: EdgeInsets.fromLTRB(5, 2, 5, 2),
|
||||
child: Text(
|
||||
'${currentIndex + 1} / ${widget.galleryItems.length}',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
decoration: TextDecoration.none,
|
||||
fontWeight: FontWeight.normal,
|
||||
fontSize: 10),
|
||||
),
|
||||
))
|
||||
],
|
||||
),
|
||||
onLongPress: () {
|
||||
_showBottomPane();
|
||||
@@ -142,9 +157,41 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text('复制链接'),
|
||||
title: Text(
|
||||
'图床类型',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: Text(widget.galleryItems[currentIndex].type),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(
|
||||
'图片链接',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: Text(widget.galleryItems[currentIndex].path),
|
||||
onTap: () {
|
||||
_handleCopy(context);
|
||||
_handleCopy(
|
||||
widget.galleryItems[currentIndex].path, context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(
|
||||
'图片信息',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: Text(widget.galleryItems[currentIndex].info),
|
||||
onTap: () {
|
||||
_handleCopy(
|
||||
widget.galleryItems[currentIndex].info, context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(
|
||||
'取消',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -154,9 +201,8 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
|
||||
}
|
||||
|
||||
/// 复制链接
|
||||
_handleCopy(BuildContext context) {
|
||||
Clipboard.setData(
|
||||
ClipboardData(text: widget.galleryItems[currentIndex].resource));
|
||||
_handleCopy(String content, BuildContext context) {
|
||||
Clipboard.setData(ClipboardData(text: content));
|
||||
Toast.show('已复制到剪切板', context);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
|
||||
class LocalNotificationUtil {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_picgo/api/tcyun_api.dart';
|
||||
import 'package:flutter_picgo/model/tcyun_config.dart';
|
||||
import 'package:flutter_picgo/model/uploaded.dart';
|
||||
|
||||
@@ -197,12 +197,7 @@ class _AlbumPageState extends State<AlbumPage> implements AlbumPageContract {
|
||||
|
||||
/// 处理图片点击事件
|
||||
handleTap(int index) {
|
||||
ImagePreviewUtils.openMulti(
|
||||
context,
|
||||
index,
|
||||
_uploadeds.map((e) {
|
||||
return GalleryItem(id: e.id.toString(), resource: e.path);
|
||||
}).toList());
|
||||
ImagePreviewUtils.openMulti(context, index, _uploadeds);
|
||||
}
|
||||
|
||||
/// 处理图片双击
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_picgo/api/qiniu_api.dart';
|
||||
import 'package:flutter_picgo/components/manage_item.dart';
|
||||
import 'package:flutter_picgo/model/qiniu_config.dart';
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_picgo/model/pb_setting.dart';
|
||||
import 'package:flutter_picgo/resources/table_name_keys.dart';
|
||||
import 'package:flutter_picgo/utils/image_upload.dart';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:extended_image/extended_image.dart';
|
||||
import 'package:fluro/fluro.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@@ -120,10 +121,6 @@ class _PicGoSettingPageState extends State<PicGoSettingPage> {
|
||||
transition: TransitionType.cupertino);
|
||||
},
|
||||
),
|
||||
// ListTile(
|
||||
// title: Text('设置显示图床'),
|
||||
// onTap: () {},
|
||||
// ),
|
||||
ListTile(
|
||||
title: Text('版本更新'),
|
||||
onTap: () {
|
||||
@@ -141,6 +138,12 @@ class _PicGoSettingPageState extends State<PicGoSettingPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('清除缓存'),
|
||||
onTap: () {
|
||||
_handleClearCache();
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -181,4 +184,19 @@ class _PicGoSettingPageState extends State<PicGoSettingPage> {
|
||||
launch('https://apps.apple.com/cn/app/flutter-picgo/id1519714305');
|
||||
}
|
||||
}
|
||||
|
||||
/// 清空缓存
|
||||
_handleClearCache() async {
|
||||
/// extended_image
|
||||
try {
|
||||
bool clear = await clearDiskCachedImages();
|
||||
if (clear) {
|
||||
Toast.show('清除成功', context);
|
||||
} else {
|
||||
throw ('clear fail');
|
||||
}
|
||||
} catch (e) {
|
||||
Toast.show('清除失败', context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'package:flutter_picgo/components/upload_item/upload_item.dart';
|
||||
import 'package:flutter_picgo/utils/strings.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
@@ -116,15 +115,15 @@ class _HandleUploadPageState extends State<HandleUploadPage> {
|
||||
sp.getBool(SharedPreferencesKeys.settingIsTimestampRename) ?? false;
|
||||
|
||||
if (settingIsTimestampRename) {
|
||||
int timestamp = new DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
/// 处理时间戳命名
|
||||
var random = Random();
|
||||
for (int i = 0; i < widget.assets.length; i++) {
|
||||
/// 获取图片名
|
||||
String suffix = path.extension(tmp.path);
|
||||
|
||||
/// replace
|
||||
filesName[i] =
|
||||
'${new DateTime.now().millisecondsSinceEpoch.toString()}-${random.nextInt(100)}$suffix';
|
||||
filesName[i] = '${timestamp + i}$suffix';
|
||||
}
|
||||
}
|
||||
var settingIsUploadedRename =
|
||||
|
||||
@@ -1,347 +0,0 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_picgo/components/loading.dart';
|
||||
import 'package:flutter_picgo/utils/local_notification.dart';
|
||||
import 'package:flutter_picgo/utils/permission.dart';
|
||||
import 'package:flutter_picgo/utils/shared_preferences.dart';
|
||||
import 'package:flutter_picgo/utils/strings.dart';
|
||||
import 'package:flutter_picgo/views/upload_page/upload_page_presenter.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:toast/toast.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class UploadPage extends StatefulWidget {
|
||||
_UploadPageState createState() => _UploadPageState();
|
||||
}
|
||||
|
||||
class _UploadPageState extends State<UploadPage>
|
||||
with WidgetsBindingObserver
|
||||
implements UploadPageContract {
|
||||
String _title = '';
|
||||
String _previewPath = '';
|
||||
String _renameImage = '';
|
||||
String _clipUrl = '';
|
||||
TextEditingController _controller;
|
||||
// 默认不选中则不复制
|
||||
int _selectButton = 0;
|
||||
|
||||
// 通知提示
|
||||
bool needNotify = false;
|
||||
|
||||
// 按钮id
|
||||
static const MARKDOWN = 1;
|
||||
static const HTML = 2;
|
||||
static const URL = 3;
|
||||
|
||||
UploadPagePresenter _presenter;
|
||||
|
||||
_UploadPageState() {
|
||||
_presenter = UploadPagePresenter(this);
|
||||
SpUtil.getInstance().then((sp) {
|
||||
this.needNotify =
|
||||
sp.getBool(SharedPreferencesKeys.settingIsUploadedTip) ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 加载当前图床的名称
|
||||
_presenter.doLoadCurrentPB();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(this._title),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: uploadView(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget uploadView(BuildContext context) {
|
||||
return ListView(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
clipBehavior: Clip.antiAliasWithSaveLayer,
|
||||
margin: EdgeInsets.all(10.0),
|
||||
height: 250.0,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Theme.of(context).accentColor,
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
SizedBox.expand(
|
||||
child: this._previewPath == ''
|
||||
? Center()
|
||||
: Image.file(new File(this._previewPath),
|
||||
fit: BoxFit.cover),
|
||||
),
|
||||
SizedBox.expand(
|
||||
child: IconButton(
|
||||
icon: Icon(
|
||||
IconData(0xe639, fontFamily: 'iconfont'),
|
||||
size: 50,
|
||||
color: Theme.of(context).accentColor,
|
||||
),
|
||||
highlightColor: Colors.transparent,
|
||||
splashColor: Colors.transparent,
|
||||
tooltip: "上传",
|
||||
onPressed: () {
|
||||
_getImage();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
child: Center(
|
||||
child: Text(
|
||||
'图片预览 - ${isBlank(this._previewPath) ? "暂未选择图片" : this._renameImage}',
|
||||
maxLines: 1,
|
||||
textWidthBasis: TextWidthBasis.parent,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: RaisedButton(
|
||||
color: this._selectButton == MARKDOWN
|
||||
? Theme.of(context).accentColor
|
||||
: Colors.white,
|
||||
textColor: this._selectButton == MARKDOWN
|
||||
? Colors.white
|
||||
: Colors.black,
|
||||
child: Text('Markdown'),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
this._selectButton = MARKDOWN;
|
||||
setClipData();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: RaisedButton(
|
||||
color: this._selectButton == HTML
|
||||
? Theme.of(context).accentColor
|
||||
: Colors.white,
|
||||
textColor:
|
||||
this._selectButton == HTML ? Colors.white : Colors.black,
|
||||
child: Text('HTML'),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
this._selectButton = HTML;
|
||||
setClipData();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: RaisedButton(
|
||||
color: this._selectButton == URL
|
||||
? Theme.of(context).accentColor
|
||||
: Colors.white,
|
||||
textColor:
|
||||
this._selectButton == URL ? Colors.white : Colors.black,
|
||||
child: Text('URL'),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
this._selectButton = URL;
|
||||
setClipData();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Container(
|
||||
child: Center(
|
||||
child: Text('点击上传后可获取的对应选中的链接格式到剪切板,可点击切换', maxLines: 2),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Container(
|
||||
height: 40,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 10, right: 10),
|
||||
child: RaisedButton(
|
||||
color: Theme.of(context).accentColor,
|
||||
textColor: Colors.white,
|
||||
child: Text('上传'),
|
||||
onPressed: () {
|
||||
if (this._previewPath == null || this._previewPath == '') {
|
||||
_getImage();
|
||||
return;
|
||||
}
|
||||
_uploadImage();
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 获取图片
|
||||
_getImage() async {
|
||||
var status = await PermissionUtils.requestPhotos();
|
||||
if (status == PermissionStatus.denied) {
|
||||
PermissionUtils.showPermissionDialog(context);
|
||||
return;
|
||||
}
|
||||
// 获取图片
|
||||
// try {
|
||||
// final pickedFile = await picker.getImage(source: ImageSource.gallery);
|
||||
// if (pickedFile != null) {
|
||||
// var sp = await SpUtil.getInstance();
|
||||
// var settingIsTimestampRename =
|
||||
// sp.getBool(SharedPreferencesKeys.settingIsTimestampRename) ?? false;
|
||||
// var settingIsUploadedRename =
|
||||
// sp.getBool(SharedPreferencesKeys.settingIsUploadedRename) ?? false;
|
||||
|
||||
// /// 获取文件后缀
|
||||
// String suffix = path.extension(pickedFile.path);
|
||||
// String filename = path.basenameWithoutExtension(pickedFile.path);
|
||||
// _renameImage = settingIsTimestampRename
|
||||
// ? '${new DateTime.now().millisecondsSinceEpoch.toString()}$suffix'
|
||||
// : '$filename$suffix';
|
||||
// if (settingIsUploadedRename) {
|
||||
// _controller = TextEditingController(text: _renameImage);
|
||||
// await showDialog(
|
||||
// context: context,
|
||||
// barrierDismissible: false,
|
||||
// builder: (context) {
|
||||
// return AlertDialog(
|
||||
// title: Center(
|
||||
// child: Text('重命名图片'),
|
||||
// ),
|
||||
// content: Padding(
|
||||
// padding: EdgeInsets.only(left: 4, right: 4),
|
||||
// child: TextField(
|
||||
// controller: _controller,
|
||||
// ),
|
||||
// ),
|
||||
// actions: <Widget>[
|
||||
// FlatButton(
|
||||
// child: Text('确定'),
|
||||
// onPressed: () {
|
||||
// this._renameImage = _controller.text;
|
||||
// Navigator.pop(context);
|
||||
// }),
|
||||
// ],
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
// setState(() {
|
||||
// this._previewPath = pickedFile.path;
|
||||
// });
|
||||
// }
|
||||
// } catch (e) {
|
||||
// debugPrint(e);
|
||||
// }
|
||||
}
|
||||
|
||||
/// 上传图片
|
||||
_uploadImage() {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) {
|
||||
return NetLoadingDialog(
|
||||
loading: true,
|
||||
loadingText: "上传中",
|
||||
requestCallBack: _presenter.doUploadImage(
|
||||
new File(this._previewPath), _renameImage),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
loadCurrentPB(String pbname) {
|
||||
setState(() {
|
||||
this._title = '图片上传 - $pbname';
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
uploadFaild(String errorMsg) async {
|
||||
if (needNotify) {
|
||||
await _showNotification(0, '上传失败:$errorMsg');
|
||||
}
|
||||
Toast.show(errorMsg ?? '', context);
|
||||
}
|
||||
|
||||
/// 设置剪切板
|
||||
setClipData([bool needShowTip = true]) {
|
||||
if (isBlank(_clipUrl)) {
|
||||
Toast.show('暂无可获取图片', context);
|
||||
return;
|
||||
}
|
||||
String cliptext;
|
||||
switch (_selectButton) {
|
||||
case MARKDOWN:
|
||||
{
|
||||
cliptext = '';
|
||||
}
|
||||
break;
|
||||
case HTML:
|
||||
{
|
||||
cliptext = '<img src="$_clipUrl">';
|
||||
}
|
||||
break;
|
||||
case URL:
|
||||
{
|
||||
cliptext = _clipUrl;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
//statements;
|
||||
cliptext = '';
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!isBlank(cliptext)) {
|
||||
Clipboard.setData(ClipboardData(text: cliptext));
|
||||
}
|
||||
if (needShowTip) {
|
||||
Toast.show('已复制到剪切板', context);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
uploadSuccess(String imageUrl) async {
|
||||
if (needNotify) {
|
||||
await _showNotification(1, '上传成功, 图片链接:$imageUrl');
|
||||
}
|
||||
this._clipUrl = imageUrl;
|
||||
setClipData(false);
|
||||
Toast.show('上传成功,图片链接为:$imageUrl', context);
|
||||
}
|
||||
|
||||
Future<void> _showNotification(int id, String body) async {
|
||||
LocalNotificationUtil.getInstance().show(
|
||||
id,
|
||||
'上传提示',
|
||||
body,
|
||||
LocalNotificationUtil.createNotificationDetails(
|
||||
LocalNotificationUtil.uploadAndroidChannel(),
|
||||
LocalNotificationUtil.normalIOSNotificationDetails(),
|
||||
LocalNotificationUtil.normalMacOSNotificationDetails()));
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_picgo/utils/image_upload.dart';
|
||||
import 'package:flutter_picgo/utils/strategy/upload_strategy_factory.dart';
|
||||
|
||||
abstract class UploadPageContract {
|
||||
loadCurrentPB(String pbname);
|
||||
uploadSuccess(String url);
|
||||
uploadFaild(String errorMsg);
|
||||
}
|
||||
|
||||
class UploadPagePresenter {
|
||||
UploadPageContract _view;
|
||||
UploadPagePresenter(this._view);
|
||||
|
||||
/// 读取当前默认图床
|
||||
doLoadCurrentPB() async {
|
||||
try {
|
||||
String pbType = await ImageUploadUtils.getDefaultPB();
|
||||
String name = await ImageUploadUtils.getPBName(pbType);
|
||||
if (name != null) {
|
||||
_view.loadCurrentPB(name);
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
/// 根据配置上传图片
|
||||
doUploadImage(File file, String renameImage) async {
|
||||
// 读取配置
|
||||
try {
|
||||
String pbType = await ImageUploadUtils.getDefaultPB();
|
||||
var uploader =
|
||||
ImageUploadUtils(UploadStrategyFactory.getUploadStrategy(pbType));
|
||||
var uploadedItem = await uploader.upload(file, renameImage);
|
||||
if (uploadedItem != null) {
|
||||
_view.uploadSuccess(uploadedItem.path);
|
||||
} else {
|
||||
_view.uploadFaild('上传失败!请重试');
|
||||
}
|
||||
} on DioError catch (e) {
|
||||
_view.uploadFaild('${e.message}');
|
||||
} catch (e) {
|
||||
_view.uploadFaild('$e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
|
||||
# Read more about iOS versioning at
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
version: 1.9.2+23
|
||||
version: 1.9.2+24
|
||||
|
||||
environment:
|
||||
sdk: ">=2.7.0 <3.0.0"
|
||||
|
||||
Reference in New Issue
Block a user