Skip to content

Commit e802b3d

Browse files
authored
feat(ui_storage): configuration API and UploadButton widget (#10699)
* feat(ui_storage): configuration API and UploadButton widget * chore(ui_storage): add license header * chore(ui_storage): format * chore(ui_shared): drop unnecessary test * fix review comments
1 parent 65f11ac commit e802b3d

File tree

148 files changed

+5516
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+5516
-23
lines changed

packages/firebase_ui_shared/lib/src/loading_button.dart

+16-5
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ class _LoadingButtonContent extends StatelessWidget {
3232
}
3333

3434
if (isLoading) {
35-
child = LoadingIndicator(
36-
size: isCupertino ? 20 : 16,
37-
borderWidth: 1,
38-
color: color,
35+
child = Stack(
36+
alignment: Alignment.center,
37+
children: [
38+
Opacity(opacity: 0, child: child),
39+
LoadingIndicator(
40+
size: isCupertino ? 20 : 16,
41+
borderWidth: 1,
42+
color: color,
43+
),
44+
],
3945
);
4046
}
4147

@@ -92,12 +98,17 @@ class LoadingButton extends StatelessWidget {
9298
Widget build(BuildContext context) {
9399
final theme = Theme.of(context);
94100
final isMaterial3 = theme.useMaterial3;
101+
final isCupertino = CupertinoUserInterfaceLevel.maybeOf(context) != null;
95102

96103
final resolvedColor = variant == ButtonVariant.filled && !isMaterial3
97104
? theme.colorScheme.onPrimary
98105
: null;
99106

100-
final contentColor = labelColor ?? resolvedColor;
107+
var contentColor = labelColor ?? resolvedColor;
108+
109+
if (isCupertino && variant == ButtonVariant.filled) {
110+
contentColor = contentColor ?? CupertinoColors.white;
111+
}
101112

102113
final content = _LoadingButtonContent(
103114
label: label,

packages/firebase_ui_shared/lib/src/loading_indicator.dart

+8-7
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ class LoadingIndicator extends PlatformWidget {
3131

3232
@override
3333
Widget? buildWrapper(BuildContext context, Widget child) {
34-
return Center(
35-
child: SizedBox(
36-
width: size,
37-
height: size,
38-
child: child,
39-
),
34+
return SizedBox(
35+
width: size,
36+
height: size,
37+
child: child,
4038
);
4139
}
4240

4341
@override
4442
Widget buildCupertino(BuildContext context) {
45-
return const CupertinoActivityIndicator();
43+
return CupertinoActivityIndicator(
44+
radius: size / 2,
45+
color: color,
46+
);
4647
}
4748

4849
@override

packages/firebase_ui_shared/lib/src/universal_button.dart

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class UniversalButton extends PlatformWidget {
9898
} else {
9999
button = CupertinoButton.filled(
100100
onPressed: onPressed,
101+
padding: EdgeInsets.zero,
101102
child: child,
102103
);
103104
}

packages/firebase_ui_shared/test/loading_indicator_test.dart

-11
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,5 @@ void main() {
3131
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
3232
},
3333
);
34-
35-
testWidgets(
36-
'centered under both MaterialApp and CupertinoApp',
37-
(tester) async {
38-
await tester.pumpWidget(const MaterialApp(home: home));
39-
expect(find.byType(Center), findsOneWidget);
40-
41-
await tester.pumpWidget(const CupertinoApp(home: home));
42-
expect(find.byType(Center), findsOneWidget);
43-
},
44-
);
4534
});
4635
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
.packages
30+
build/
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
8+
channel: stable
9+
10+
project_type: package
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## 0.1.0-dev.0
2+
3+
- Initial Firebase UI Stroage release with top-level configuration and UploadButton
4+
- `i18n` is not yet supported and will be coming in future releases

packages/firebase_ui_storage/LICENSE

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright 2017, the Chromium project authors. All rights reserved.
2+
Redistribution and use in source and binary forms, with or without
3+
modification, are permitted provided that the following conditions are
4+
met:
5+
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above
9+
copyright notice, this list of conditions and the following
10+
disclaimer in the documentation and/or other materials provided
11+
with the distribution.
12+
* Neither the name of Google Inc. nor the names of its
13+
contributors may be used to endorse or promote products derived
14+
from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
## Firebase UI Storage
2+
3+
[![pub package](https://img.shields.io/pub/v/firebase_ui_storage.svg)](https://pub.dev/packages/firebase_ui_storage)
4+
5+
Firebase UI Storage is a set of Flutter widgets and utilities designed to help you build and integrate your user interface with Firebase Storage.
6+
7+
## Installation
8+
9+
Intall dependencies
10+
11+
```sh
12+
flutter pub add firebase_core firebase_storage firebase_ui_storage
13+
```
14+
15+
Donwload Firebase project config
16+
17+
```sh
18+
flutterfire configure
19+
```
20+
21+
## Configuration
22+
23+
This section will walk you through the configuration process of the Firebase UI Storage
24+
25+
### macOS
26+
27+
If you're building for macOS, you will need to add an entitlement for either read-only access if you only upload files:
28+
29+
```xml
30+
<key>com.apple.security.files.user-selected.read-only</key>
31+
<true/>
32+
```
33+
34+
or read/write access if you want to be able to download files as well:
35+
36+
```xml
37+
<key>com.apple.security.files.user-selected.read-write</key>
38+
<true/>
39+
```
40+
41+
Make sure to add network client entitlement as well:
42+
43+
```xml
44+
<key>com.apple.security.network.client</key>
45+
<true/>
46+
```
47+
48+
### FirebaseUIStorage.configure()
49+
50+
To reduce boilerplate for widgets, `FirebaseUIStroage` has a top-level configuration:
51+
52+
```dart
53+
import 'package:firebase_core/firebase_core.dart';
54+
import 'package:firebase_storage/firebase_storage.dart';
55+
import 'package:firebase_ui_storage/firebase_ui_storage.dart';
56+
import 'package:flutter/material.dart';
57+
58+
import 'firebase_options.dart';
59+
60+
Future<void> main() async {
61+
WidgetsFlutterBinding.ensureInitialized();
62+
63+
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
64+
65+
final storage = FirebaseStorage.instance;
66+
final config = FirebaseUIStorageConfiguration(storage: storage);
67+
68+
await FirebaseUIStorage.configure(config);
69+
70+
runApp(const MyApp());
71+
}
72+
```
73+
74+
See [API docs](https://pub.dev/documentation/firebase_ui_storage/latest/firebase_ui_storage/FirebaseUIStorageConfiguration-class.html) for more configuration options.
75+
76+
### Overriding configuration
77+
78+
It is possible to override a top-level configuration for a widget subtree:
79+
80+
```dart
81+
class MyWidget extends StatelessWidget {
82+
@override
83+
Widget build(BuildContext context) {
84+
return FirebaseUIStorageConfigOverride(
85+
config: FirebaseUIStorageConfiguration(
86+
uploadRoot: storage.ref('${FirebaseAuth.instance.currentUser.uid}/'),
87+
namingPolicy: const UuidFileUploadNamingPolicy(),
88+
child: const MyUserPage(),
89+
),
90+
);
91+
}
92+
}
93+
```
94+
95+
## Widgets
96+
97+
### UploadButton
98+
99+
```dart
100+
class MyUploadPage extends StatelessWidget {
101+
@override
102+
Widget build(BuildContext context) {
103+
return Scaffold(
104+
body: Center(
105+
child: UploadButton(
106+
mimeTypes: const ['image/png', 'image/jpeg'],
107+
onError: (err, stackTrace) {
108+
print(err.toString());
109+
},
110+
onUploadComplete: (ref) {
111+
print('File uploaded to ${ref.path}');
112+
}
113+
),
114+
),
115+
);
116+
}
117+
}
118+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
**/doc/api/
26+
**/ios/Flutter/.last_build_id
27+
.dart_tool/
28+
.flutter-plugins
29+
.flutter-plugins-dependencies
30+
.packages
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
35+
# Symbolication related
36+
app.*.symbols
37+
38+
# Obfuscation related
39+
app.*.map.json
40+
41+
# Android Studio will place build artifacts here
42+
/android/app/debug
43+
/android/app/profile
44+
/android/app/release
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled.
5+
6+
version:
7+
revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
8+
channel: stable
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
17+
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
18+
- platform: android
19+
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
20+
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
21+
- platform: ios
22+
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
23+
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
24+
- platform: linux
25+
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
26+
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
27+
- platform: macos
28+
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
29+
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
30+
- platform: web
31+
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
32+
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
33+
- platform: windows
34+
create_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
35+
base_revision: 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# firebase_ui_storage_example
2+
3+
Example app that showcases widgets available in `firebase_ui_storage`.
4+
5+
See [README](https://github.com/firebase/flutterfire/blob/master/packages/firebase_ui_storage/README.md) and [API docs](https://pub.dev/documentation/firebase_ui_storage/latest/firebase_ui_storage/firebase_ui_storage-library.html) for more details
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:flutter_lints/flutter.yaml

0 commit comments

Comments
 (0)