Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: update flutter example with file upsert

phamhieuf2b94983a332
diff --git a/examples/flutter-user-management/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/examples/flutter-user-management/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json
index e882ab98894..d36b1fab2d9 100644
--- a/examples/flutter-user-management/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json
+++ b/examples/flutter-user-management/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -1,122 +1,122 @@
{
- "images": [
+ "images" : [
{
- "size": "20x20",
- "idiom": "iphone",
- "filename": "[email protected]",
- "scale": "2x"
+ "size" : "20x20",
+ "idiom" : "iphone",
+ "filename" : "[email protected]",
+ "scale" : "2x"
},
{
- "size": "20x20",
- "idiom": "iphone",
- "filename": "[email protected]",
- "scale": "3x"
+ "size" : "20x20",
+ "idiom" : "iphone",
+ "filename" : "[email protected]",
+ "scale" : "3x"
},
{
- "size": "29x29",
- "idiom": "iphone",
- "filename": "[email protected]",
- "scale": "1x"
+ "size" : "29x29",
+ "idiom" : "iphone",
+ "filename" : "[email protected]",
+ "scale" : "1x"
},
{
- "size": "29x29",
- "idiom": "iphone",
- "filename": "[email protected]",
- "scale": "2x"
+ "size" : "29x29",
+ "idiom" : "iphone",
+ "filename" : "[email protected]",
+ "scale" : "2x"
},
{
- "size": "29x29",
- "idiom": "iphone",
- "filename": "[email protected]",
- "scale": "3x"
+ "size" : "29x29",
+ "idiom" : "iphone",
+ "filename" : "[email protected]",
+ "scale" : "3x"
},
{
- "size": "40x40",
- "idiom": "iphone",
- "filename": "[email protected]",
- "scale": "2x"
+ "size" : "40x40",
+ "idiom" : "iphone",
+ "filename" : "[email protected]",
+ "scale" : "2x"
},
{
- "size": "40x40",
- "idiom": "iphone",
- "filename": "[email protected]",
- "scale": "3x"
+ "size" : "40x40",
+ "idiom" : "iphone",
+ "filename" : "[email protected]",
+ "scale" : "3x"
},
{
- "size": "60x60",
- "idiom": "iphone",
- "filename": "[email protected]",
- "scale": "2x"
+ "size" : "60x60",
+ "idiom" : "iphone",
+ "filename" : "[email protected]",
+ "scale" : "2x"
},
{
- "size": "60x60",
- "idiom": "iphone",
- "filename": "[email protected]",
- "scale": "3x"
+ "size" : "60x60",
+ "idiom" : "iphone",
+ "filename" : "[email protected]",
+ "scale" : "3x"
},
{
- "size": "20x20",
- "idiom": "ipad",
- "filename": "[email protected]",
- "scale": "1x"
+ "size" : "20x20",
+ "idiom" : "ipad",
+ "filename" : "[email protected]",
+ "scale" : "1x"
},
{
- "size": "20x20",
- "idiom": "ipad",
- "filename": "[email protected]",
- "scale": "2x"
+ "size" : "20x20",
+ "idiom" : "ipad",
+ "filename" : "[email protected]",
+ "scale" : "2x"
},
{
- "size": "29x29",
- "idiom": "ipad",
- "filename": "[email protected]",
- "scale": "1x"
+ "size" : "29x29",
+ "idiom" : "ipad",
+ "filename" : "[email protected]",
+ "scale" : "1x"
},
{
- "size": "29x29",
- "idiom": "ipad",
- "filename": "[email protected]",
- "scale": "2x"
+ "size" : "29x29",
+ "idiom" : "ipad",
+ "filename" : "[email protected]",
+ "scale" : "2x"
},
{
- "size": "40x40",
- "idiom": "ipad",
- "filename": "[email protected]",
- "scale": "1x"
+ "size" : "40x40",
+ "idiom" : "ipad",
+ "filename" : "[email protected]",
+ "scale" : "1x"
},
{
- "size": "40x40",
- "idiom": "ipad",
- "filename": "[email protected]",
- "scale": "2x"
+ "size" : "40x40",
+ "idiom" : "ipad",
+ "filename" : "[email protected]",
+ "scale" : "2x"
},
{
- "size": "76x76",
- "idiom": "ipad",
- "filename": "[email protected]",
- "scale": "1x"
+ "size" : "76x76",
+ "idiom" : "ipad",
+ "filename" : "[email protected]",
+ "scale" : "1x"
},
{
- "size": "76x76",
- "idiom": "ipad",
- "filename": "[email protected]",
- "scale": "2x"
+ "size" : "76x76",
+ "idiom" : "ipad",
+ "filename" : "[email protected]",
+ "scale" : "2x"
},
{
- "size": "83.5x83.5",
- "idiom": "ipad",
- "filename": "[email protected]",
- "scale": "2x"
+ "size" : "83.5x83.5",
+ "idiom" : "ipad",
+ "filename" : "[email protected]",
+ "scale" : "2x"
},
{
- "size": "1024x1024",
- "idiom": "ios-marketing",
- "filename": "[email protected]",
- "scale": "1x"
+ "size" : "1024x1024",
+ "idiom" : "ios-marketing",
+ "filename" : "[email protected]",
+ "scale" : "1x"
}
],
- "info": {
- "version": 1,
- "author": "xcode"
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
}
}
diff --git a/examples/flutter-user-management/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/examples/flutter-user-management/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json
index 781d7cdcac0..0bedcf2fd46 100644
--- a/examples/flutter-user-management/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json
+++ b/examples/flutter-user-management/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json
@@ -1,23 +1,23 @@
{
- "images": [
+ "images" : [
{
- "idiom": "universal",
- "filename": "LaunchImage.png",
- "scale": "1x"
+ "idiom" : "universal",
+ "filename" : "LaunchImage.png",
+ "scale" : "1x"
},
{
- "idiom": "universal",
- "filename": "[email protected]",
- "scale": "2x"
+ "idiom" : "universal",
+ "filename" : "[email protected]",
+ "scale" : "2x"
},
{
- "idiom": "universal",
- "filename": "[email protected]",
- "scale": "3x"
+ "idiom" : "universal",
+ "filename" : "[email protected]",
+ "scale" : "3x"
}
],
- "info": {
- "version": 1,
- "author": "xcode"
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
}
}
diff --git a/examples/flutter-user-management/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/examples/flutter-user-management/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md
index b5b843ad3b8..89c2725b70f 100644
--- a/examples/flutter-user-management/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md
+++ b/examples/flutter-user-management/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md
@@ -2,4 +2,4 @@
You can customize the launch screen with your own desired assets by replacing the image files in this directory.
-You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
+You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
\ No newline at end of file
diff --git a/examples/flutter-user-management/lib/screens/profile_screen.dart b/examples/flutter-user-management/lib/screens/profile_screen.dart
index 25d62890fdd..6c7c727b132 100644
--- a/examples/flutter-user-management/lib/screens/profile_screen.dart
+++ b/examples/flutter-user-management/lib/screens/profile_screen.dart
@@ -34,6 +34,7 @@ class _ProfileScreenState extends AuthRequiredState<ProfileScreen> {
String username = '';
String website = '';
String avatarUrl = '';
+ String avatarKey = '';
@override
void onAuthenticated(Session session) {
@@ -51,7 +52,7 @@ class _ProfileScreenState extends AuthRequiredState<ProfileScreen> {
try {
final response = await Supabase.instance.client
.from('profiles')
- .select('username, website, avatar_url')
+ .select('username, website, avatar_url, updated_at')
.eq('id', userId)
.maybeSingle()
.execute();
@@ -60,9 +61,12 @@ class _ProfileScreenState extends AuthRequiredState<ProfileScreen> {
}
setState(() {
+ print(response.data);
username = response.data?['username'] as String? ?? '';
website = response.data?['website'] as String? ?? '';
avatarUrl = response.data?['avatar_url'] as String? ?? '';
+ final updatedAt = response.data?['updated_at'] as String? ?? '';
+ avatarKey = '$avatarUrl-$updatedAt';
});
} catch (e) {
showMessage(e.toString());
@@ -95,23 +99,21 @@ class _ProfileScreenState extends AuthRequiredState<ProfileScreen> {
}
final bytes = await pickedFile.readAsBytes();
- final List<int> listBytes = List.from(bytes);
- final file = BinaryFile(
- bytes: listBytes,
- mime: 'image/jpeg',
- );
- final fileName = '${randomString(15)}.jpg';
-
+ final fileName = avatarUrl == '' ? '${randomString(15)}.jpg' : avatarUrl;
+ const fileOptions = FileOptions(upsert: true);
final uploadRes = await Supabase.instance.client.storage
.from('avatars')
- .uploadBinary(fileName, file);
+ .uploadBinary(fileName, bytes, fileOptions: fileOptions);
+
if (uploadRes.error != null) {
throw uploadRes.error!.message;
}
+ final updatedAt = DateTime.now().toString();
final res = await Supabase.instance.client.from('profiles').upsert({
'id': user!.id,
'avatar_url': fileName,
+ 'updated_at': updatedAt,
}).execute();
if (res.error != null) {
throw res.error!.message;
@@ -119,6 +121,7 @@ class _ProfileScreenState extends AuthRequiredState<ProfileScreen> {
setState(() {
avatarUrl = fileName;
+ avatarKey = '$fileName-$updatedAt';
});
showMessage("Avatar updated!");
} catch (e) {
@@ -186,7 +189,7 @@ class _ProfileScreenState extends AuthRequiredState<ProfileScreen> {
AvatarContainer(
url: avatarUrl,
onUpdatePressed: () => _updateAvatar(context),
- key: Key(avatarUrl),
+ key: Key(avatarKey),
),
TextFormField(
onChanged: (value) => setState(() {
diff --git a/examples/flutter-user-management/pubspec.lock b/examples/flutter-user-management/pubspec.lock
index 749527547c2..1d6e1ca5b94 100644
--- a/examples/flutter-user-management/pubspec.lock
+++ b/examples/flutter-user-management/pubspec.lock
@@ -384,7 +384,7 @@ packages:
name: storage_client
url: "https://pub.dartlang.org"
source: hosted
- version: "0.0.2"
+ version: "0.0.3"
stream_channel:
dependency: transitive
description:
@@ -405,14 +405,14 @@ packages:
name: supabase
url: "https://pub.dartlang.org"
source: hosted
- version: "0.0.2"
+ version: "0.0.3"
supabase_flutter:
dependency: "direct main"
description:
name: supabase_flutter
url: "https://pub.dartlang.org"
source: hosted
- version: "0.0.3"
+ version: "0.0.4"
term_glyph:
dependency: transitive
description:
diff --git a/examples/flutter-user-management/pubspec.yaml b/examples/flutter-user-management/pubspec.yaml
index 46a970480e6..c579f03e150 100644
--- a/examples/flutter-user-management/pubspec.yaml
+++ b/examples/flutter-user-management/pubspec.yaml
@@ -27,8 +27,8 @@ dependencies:
flutter_secure_storage: ^4.2.0
image_picker: ^0.8.2
rounded_loading_button: ^2.0.5
- supabase: ^0.0.2
- supabase_flutter: ^0.0.3
+ supabase: ^0.0.3
+ supabase_flutter: ^0.0.4
dev_dependencies:
flutter_launcher_icons: ^0.9.0
diff --git a/examples/flutter-user-management/web/manifest.json b/examples/flutter-user-management/web/manifest.json
index b9ca8e96a4f..e850c7df0a5 100644
--- a/examples/flutter-user-management/web/manifest.json
+++ b/examples/flutter-user-management/web/manifest.json
@@ -1,23 +1,23 @@
{
- "name": "supabase_demo",
- "short_name": "supabase_demo",
- "start_url": ".",
- "display": "standalone",
- "background_color": "#0175C2",
- "theme_color": "#0175C2",
- "description": "A new Flutter project.",
- "orientation": "portrait-primary",
- "prefer_related_applications": false,
- "icons": [
- {
- "src": "icons/Icon-192.png",
- "sizes": "192x192",
- "type": "image/png"
- },
- {
- "src": "icons/Icon-512.png",
- "sizes": "512x512",
- "type": "image/png"
- }
- ]
+ "name": "supabase_demo",
+ "short_name": "supabase_demo",
+ "start_url": ".",
+ "display": "standalone",
+ "background_color": "#0175C2",
+ "theme_color": "#0175C2",
+ "description": "A new Flutter project.",
+ "orientation": "portrait-primary",
+ "prefer_related_applications": false,
+ "icons": [
+ {
+ "src": "icons/Icon-192.png",
+ "sizes": "192x192",
+ "type": "image/png"
+ },
+ {
+ "src": "icons/Icon-512.png",
+ "sizes": "512x512",
+ "type": "image/png"
+ }
+ ]
}