Skip to content

Commit

Permalink
feat(ui_storage): configuration API and UploadButton widget (#10699)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lesnitsky authored Apr 14, 2023
1 parent 65f11ac commit e802b3d
Show file tree
Hide file tree
Showing 148 changed files with 5,516 additions and 23 deletions.
21 changes: 16 additions & 5 deletions packages/firebase_ui_shared/lib/src/loading_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ class _LoadingButtonContent extends StatelessWidget {
}

if (isLoading) {
child = LoadingIndicator(
size: isCupertino ? 20 : 16,
borderWidth: 1,
color: color,
child = Stack(
alignment: Alignment.center,
children: [
Opacity(opacity: 0, child: child),
LoadingIndicator(
size: isCupertino ? 20 : 16,
borderWidth: 1,
color: color,
),
],
);
}

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

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

final contentColor = labelColor ?? resolvedColor;
var contentColor = labelColor ?? resolvedColor;

if (isCupertino && variant == ButtonVariant.filled) {
contentColor = contentColor ?? CupertinoColors.white;
}

final content = _LoadingButtonContent(
label: label,
Expand Down
15 changes: 8 additions & 7 deletions packages/firebase_ui_shared/lib/src/loading_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ class LoadingIndicator extends PlatformWidget {

@override
Widget? buildWrapper(BuildContext context, Widget child) {
return Center(
child: SizedBox(
width: size,
height: size,
child: child,
),
return SizedBox(
width: size,
height: size,
child: child,
);
}

@override
Widget buildCupertino(BuildContext context) {
return const CupertinoActivityIndicator();
return CupertinoActivityIndicator(
radius: size / 2,
color: color,
);
}

@override
Expand Down
1 change: 1 addition & 0 deletions packages/firebase_ui_shared/lib/src/universal_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class UniversalButton extends PlatformWidget {
} else {
button = CupertinoButton.filled(
onPressed: onPressed,
padding: EdgeInsets.zero,
child: child,
);
}
Expand Down
11 changes: 0 additions & 11 deletions packages/firebase_ui_shared/test/loading_indicator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,5 @@ void main() {
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
},
);

testWidgets(
'centered under both MaterialApp and CupertinoApp',
(tester) async {
await tester.pumpWidget(const MaterialApp(home: home));
expect(find.byType(Center), findsOneWidget);

await tester.pumpWidget(const CupertinoApp(home: home));
expect(find.byType(Center), findsOneWidget);
},
);
});
}
30 changes: 30 additions & 0 deletions packages/firebase_ui_storage/.gitignore
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/
10 changes: 10 additions & 0 deletions packages/firebase_ui_storage/.metadata
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
4 changes: 4 additions & 0 deletions packages/firebase_ui_storage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 0.1.0-dev.0

- Initial Firebase UI Stroage release with top-level configuration and UploadButton
- `i18n` is not yet supported and will be coming in future releases
26 changes: 26 additions & 0 deletions packages/firebase_ui_storage/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright 2017, the Chromium project authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
118 changes: 118 additions & 0 deletions packages/firebase_ui_storage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
## Firebase UI Storage

[![pub package](https://img.shields.io/pub/v/firebase_ui_storage.svg)](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}');
}
),
),
);
}
}
```
4 changes: 4 additions & 0 deletions packages/firebase_ui_storage/analysis_options.yaml
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
44 changes: 44 additions & 0 deletions packages/firebase_ui_storage/example/.gitignore
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
45 changes: 45 additions & 0 deletions packages/firebase_ui_storage/example/.metadata
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'
5 changes: 5 additions & 0 deletions packages/firebase_ui_storage/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# firebase_ui_storage_example

Example app that showcases widgets available in `firebase_ui_storage`.

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
1 change: 1 addition & 0 deletions packages/firebase_ui_storage/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:flutter_lints/flutter.yaml
Loading

0 comments on commit e802b3d

Please sign in to comment.