11import 'dart:async' ;
22import 'dart:convert' ;
3+ import 'dart:io' ;
34
45import 'package:flutter/material.dart' ;
56import 'package:flutter/services.dart' ;
7+ import 'package:flutter_cache_manager/flutter_cache_manager.dart' ;
68import 'package:fluttertoast/fluttertoast.dart' ;
79import 'package:gsy_github_app_flutter/common/localization/DefaultLocalizations.dart' ;
810import 'package:gsy_github_app_flutter/common/net/Address.dart' ;
@@ -14,7 +16,9 @@ import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
1416import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart' ;
1517import 'package:gsy_github_app_flutter/widget/GSYFlexButton.dart' ;
1618import 'package:gsy_github_app_flutter/widget/IssueEditDIalog.dart' ;
19+ import 'package:permission_handler/permission_handler.dart' ;
1720import 'package:flutter_spinkit/flutter_spinkit.dart' ;
21+ import 'package:path_provider/path_provider.dart' ;
1822import 'package:redux/redux.dart' ;
1923import 'package:url_launcher/url_launcher.dart' ;
2024import 'package:flutter_statusbar/flutter_statusbar.dart' ;
@@ -73,6 +77,43 @@ class CommonUtils {
7377 }
7478 }
7579
80+ static getLocalPath () async {
81+ Directory appDir;
82+ if (Platform .isIOS) {
83+ appDir = await getApplicationDocumentsDirectory ();
84+ } else {
85+ appDir = await getExternalStorageDirectory ();
86+ }
87+ PermissionStatus permission = await PermissionHandler ().checkPermissionStatus (PermissionGroup .storage);
88+ if (permission != PermissionStatus .granted) {
89+ Map <PermissionGroup , PermissionStatus > permissions = await PermissionHandler ().requestPermissions ([PermissionGroup .storage]);
90+ if (permissions[PermissionGroup .storage] != PermissionStatus .granted) {
91+ return null ;
92+ }
93+ }
94+ String appDocPath = appDir.path + "/gsygithubappflutter" ;
95+ Directory appPath = Directory (appDocPath);
96+ await appPath.create (recursive: true );
97+ return appPath;
98+ }
99+
100+ static saveImage (String url) async {
101+ Future <String > _findPath (String imageUrl) async {
102+ final cache = await CacheManager .getInstance ();
103+ final file = await cache.getFile (imageUrl);
104+ if (file == null ) {
105+ return null ;
106+ }
107+ Directory localPath = await CommonUtils .getLocalPath ();
108+ if (localPath == null ) {
109+ return null ;
110+ }
111+ final result = await file.copy (localPath.path + file.path.substring (file.path.lastIndexOf ("/" )));
112+ return result.path;
113+ }
114+ return _findPath (url);
115+ }
116+
76117 static getFullName (String repository_url) {
77118 if (repository_url != null && repository_url.substring (repository_url.length - 1 ) == "/" ) {
78119 repository_url = repository_url.substring (0 , repository_url.length - 1 );
0 commit comments