-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(ui_storage): configuration API and UploadButton widget #10699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
94824a1
feat(ui_storage): configuration API and UploadButton widget
lesnitsky 06cf1d2
chore(ui_storage): add license header
lesnitsky 313cd6d
chore(ui_storage): format
lesnitsky 7ec4bfe
chore(ui_shared): drop unnecessary test
lesnitsky 0966dbb
fix review comments
lesnitsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
.packages | ||
build/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
channel: stable | ||
|
||
project_type: package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.0.1 | ||
|
||
* TODO: Describe initial release. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO: Add your license here. | ||
lesnitsky marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
## Firebase UI Storage | ||
|
||
[](https://pub.dev/packages/firebase_ui_storage) | ||
|
||
Firebase UI Storage is a set of Flutter widgets and utilities designed to help you build and integrate your user interface with Firebase Storage. | ||
|
||
## Installation | ||
|
||
Intall dependencies | ||
|
||
```sh | ||
flutter pub add firebase_core firebase_storage firebase_ui_storage | ||
``` | ||
|
||
Donwload Firebase project config | ||
|
||
```sh | ||
flutterfire configure | ||
``` | ||
|
||
## Configuration | ||
|
||
This section will walk you through the configuration process of the Firebase UI Storage | ||
|
||
### macOS | ||
|
||
If you're building for macOS, you will need to add an entitlement for either read-only access if you only upload files: | ||
|
||
```xml | ||
<key>com.apple.security.files.user-selected.read-only</key> | ||
<true/> | ||
``` | ||
|
||
or read/write access if you want to be able to download files as well: | ||
|
||
```xml | ||
<key>com.apple.security.files.user-selected.read-write</key> | ||
<true/> | ||
``` | ||
|
||
Make sure to add network client entitlement as well: | ||
|
||
```xml | ||
<key>com.apple.security.network.client</key> | ||
<true/> | ||
``` | ||
|
||
### FirebaseUIStorage.configure() | ||
|
||
To reduce boilerplate for widgets, `FirebaseUIStroage` has a top-level configuration: | ||
|
||
```dart | ||
import 'package:firebase_core/firebase_core.dart'; | ||
import 'package:firebase_storage/firebase_storage.dart'; | ||
import 'package:firebase_ui_storage/firebase_ui_storage.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'firebase_options.dart'; | ||
|
||
Future<void> main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
|
||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); | ||
|
||
final storage = FirebaseStorage.instance; | ||
final config = FirebaseUIStorageConfiguration(storage: storage); | ||
|
||
await FirebaseUIStorage.configure(config); | ||
|
||
runApp(const MyApp()); | ||
} | ||
``` | ||
|
||
See [API docs](https://pub.dev/documentation/firebase_ui_storage/latest/firebase_ui_storage/FirebaseUIStorageConfiguration-class.html) for more configuration options. | ||
|
||
### Overriding configuration | ||
|
||
It is possible to override a top-level configuration for a widget subtree: | ||
|
||
```dart | ||
class MyWidget extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return FirebaseUIStorageConfigOverride( | ||
config: FirebaseUIStorageConfiguration( | ||
uploadRoot: storage.ref('${FirebaseAuth.instance.currentUser.uid}/'), | ||
namingPolicy: const UuidFileUploadNamingPolicy(), | ||
child: const MyUserPage(), | ||
), | ||
); | ||
} | ||
} | ||
``` | ||
|
||
## Widgets | ||
|
||
### UploadButton | ||
|
||
```dart | ||
class MyUploadPage extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Center( | ||
child: UploadButton( | ||
mimeTypes: const ['image/png', 'image/jpeg'], | ||
onError: (err, stackTrace) { | ||
print(err.toString()); | ||
}, | ||
onUploadComplete: (ref) { | ||
print('File uploaded to ${ref.path}'); | ||
} | ||
), | ||
), | ||
); | ||
} | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include: package:flutter_lints/flutter.yaml | ||
|
||
# Additional information about this file can be found at | ||
# https://dart.dev/guides/language/analysis-options |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Android Studio will place build artifacts here | ||
/android/app/debug | ||
/android/app/profile | ||
/android/app/release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled. | ||
|
||
version: | ||
revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
channel: stable | ||
|
||
project_type: app | ||
|
||
# Tracks metadata for the flutter migrate command | ||
migration: | ||
platforms: | ||
- platform: root | ||
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
- platform: android | ||
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
- platform: ios | ||
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
- platform: linux | ||
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
- platform: macos | ||
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
- platform: web | ||
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
- platform: windows | ||
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0 | ||
|
||
# User provided section | ||
|
||
# List of Local paths (relative to this file) that should be | ||
# ignored by the migrate tool. | ||
# | ||
# Files that are not part of the templates will be ignored by default. | ||
unmanaged_files: | ||
- 'lib/main.dart' | ||
- 'ios/Runner.xcodeproj/project.pbxproj' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# firebase_ui_storage_example | ||
|
||
A new Flutter project. | ||
lesnitsky marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include: package:flutter_lints/flutter.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
gradle-wrapper.jar | ||
/.gradle | ||
/captures/ | ||
/gradlew | ||
/gradlew.bat | ||
/local.properties | ||
GeneratedPluginRegistrant.java | ||
|
||
# Remember to never publicly share your keystore. | ||
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app | ||
key.properties | ||
**/*.keystore | ||
**/*.jks |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.