Skip to content

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 5 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -33,10 +33,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 @@ -93,12 +99,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 @@ -99,6 +99,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
3 changes: 3 additions & 0 deletions packages/firebase_ui_storage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
1 change: 1 addition & 0 deletions packages/firebase_ui_storage/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add your license here.
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'
3 changes: 3 additions & 0 deletions packages/firebase_ui_storage/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# firebase_ui_storage_example

A new Flutter project.
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
13 changes: 13 additions & 0 deletions packages/firebase_ui_storage/example/android/.gitignore
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
Loading