Storage Manager for online FirebaseStorage
and offline Shared Preferences
purposes
Add this import line
import 'package:storage_manager/storage_manager.dart';
This package can save and get images, videos, text (plain or json) and data (bytes) to device local storage shared_preferences
or Firebase Cloud Storage firebase_storage
using the latest dependencies
final file = await StorageProvider.get('/collectionName/fileName.png');
Uint8List? image = await StorageProvider.getImage('/collectionName/fileName.png');
Uint8List? video = await StorageProvider.getVideo('/collectionName/fileName.mp4');
String? text = await StorageProvider.getString('/collectionName/fileName.txt');
Map<String,dynamic>? json = await StorageProvider.getJson('/collectionName/fileName.json');
Uint8List? image = await StorageProvider.getLocalImage('/collectionName/fileName.png');
Uint8List? video = await StorageProvider.getLocalVideo('/collectionName/fileName.mp4');
String? text = await StorageProvider.getLocalString('/collectionName/fileName.txt');
Map<String,dynamic>? json = await StorageProvider.getLocalJson('/collectionName/fileName.json');
bool success = await StorageProvider.remove('/collectionName/fileName.png');
or from storage URL
bool success = await StorageProvider.removeUrl('url');
- Only the save method can save to local storage using the
toLocalStorage
parameter with a dynamicvalue
- The
value
parameter can be aString
,Uint8List
,File
,JSON
orXFile
from the image picker - The
fileName
parameter is the name of the file to be saved
StorageProvider.save('/images/image.png', value, toLocalStorage: true);
String url = await StorageProvider.save('/collectionName/fileName.png', image);
String url = await StorageProvider.saveImage('/collectionName/fileName.png', image);
String url = await StorageProvider.saveVideo('/collectionName/fileName.mp4', video);
String url = await StorageProvider.saveBytes('/collectionName/fileName.json', json);
String url = await StorageProvider.saveLocalImage('/collectionName/fileName', image);
String url = await StorageProvider.saveLocalVideo('/collectionName/fileName', video);
String url = await StorageProvider.saveLocalString('/collectionName/fileName', text);
String url = await StorageProvider.saveLocalJson('/collectionName/fileName', json);
if(await StorageProvider.selectImages()){
List<XFile> images = StorageProvider.selectedAssets;
}else{
print('User cancelled selection');
}
List<XFile> images = StorageProvider.selectedAssets;
List<String> urls = await StorageProvider.save('/collectionName/', images);
String url = await StorageProvider.selectAndUpload();
StorageProvider.configure(
context: context,
showProgress: true,
getImageSource: () async => await showDialog<ImageSource>(
context: context,
builder: (context) => SimpleDialog(
title: const Text("Select image source"),
children: [
ListTile(
title: const Text("Camera"),
leading: const Icon(Icons.camera_alt),
onTap: () => Navigator.pop(context, ImageSource.camera),
),
ListTile(
title: const Text("Gallery"),
leading: const Icon(Icons.photo),
onTap: () => Navigator.pop(context, ImageSource.gallery),
),
],
),
),
showDataUploadProgress: (uploadTask) async {
return await showDialog(
context: context,
barrierDismissible: true,
builder: (context) {
return StreamBuilder<TaskSnapshot>(
stream: uploadTask.snapshotEvents,
builder: (context, snapshot) {
if (snapshot.hasData) {
return AlertDialog(
title: const Text('Uploading...'),
content: ProgressFromUploadTask(
task: uploadTask,
onDone: () {
Navigator.pop(context);
},
),
);
} else {
return const AlertDialog(
title: Text('Waiting...'),
content: LinearProgressIndicator(),
);
}
},
);
},
);
},
);
- Flutter web requires an additional script to be added to the index.html file if you want to use Image.network()
Include this script in the bottom of your
body
inside the index.html:
<script type="text/javascript">
window.flutterWebRenderer = "html";
</script>
This package assumes complete Firebase configuration with Storage and permissions. We recommend flutterfire to configure your project. For more information visit: https://firebase.flutter.dev/docs/overview/
dart pub global activate flutterfire_cli
flutterfire configure