Firebase UI Storage is a set of Flutter widgets and utilities designed to help you build and integrate your user interface with Firebase Storage.
Install dependencies
flutter pub add firebase_core firebase_storage firebase_ui_storage
Install the FlutterFire CLI by running the following command from any directory:
flutter pub global activate flutterfire_cli
Use the FlutterFire CLI to configure your Flutter apps to connect to Firebase.
From your Flutter project directory, run the following command to start the app configuration workflow:
flutterfire configure
This section will walk you through the configuration process for Firebase UI Storage
If you're building for macOS, you will need to add an entitlement.
For read-only access if you only upload files:
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
For read/write access if you want to be able to download files as well:
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
Make sure to add network client entitlement as well:
<key>com.apple.security.network.client</key>
<true/>
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
}
FirebaseUIStorage
has a top-level configuration, that reduces amount of widget properties needed
to be passed to the widget constructors.
import 'package:firebase_storage/firebase_storage.dart';
Future<void> main() async {
// configuration steps from above
final storage = FirebaseStorage.instance;
final config = FirebaseUIStorageConfiguration(
storage: storage,
uploadRoot: storage.ref('flutter-tests'),
namingPolicy: UuidFileUploadNamingPolicy(), // optional, will generate a UUID for each uploaded file
);
await FirebaseUIStorage.configure(config);
}
Available file naming policies:
KeepOriginalNameUploadPolicy
– keeps the original file name (default)KeepPathUploadPolicy
- keeps the original file pathUuidFileUploadNamingPolicy
– generates a UUID for each uploaded file
If you ever need to override this top-level configuration, you can do so by using FirebaseUIStorageConfigOverride
:
import 'package:firebase_storage/firebase_storage.dart';
import 'package:firebase_ui_storage/firebase_ui_storage.dart';
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
return FirebaseUIStorageConfigOverride(
config: FirebaseUIStorageConfiguration(
uploadRoot: FirebaseStorage.instance.ref('other-location'),
),
child: const OtherWidget(),
);
}
}
UploadButton
TaskProgressIndicator
StorageImage
StorageListView
StorageGridView
PaginatedLoadingController
See API reference for more details.