mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
remove constants.dart
This commit is contained in:
1 parent
1b2361c099
commit
a6d5f2e60b
6 files changed
+67
-40
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'package:supabase_quickstart/constants.dart';
|
||||
import 'package:supabase_quickstart/main.dart';
|
||||
|
||||
class Avatar extends StatefulWidget {
|
||||
const Avatar({
|
||||
@@ -76,11 +76,21 @@ class _AvatarState extends State<Avatar> {
|
||||
widget.onUpload(imageUrlResponse);
|
||||
} on StorageException catch (error) {
|
||||
if (mounted) {
|
||||
context.showErrorSnackBar(message: error.message);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error.message),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (mounted) {
|
||||
context.showErrorSnackBar(message: 'Unexpected error occurred');
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text('Unexpected error occurred'),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
final supabase = Supabase.instance.client;
|
||||
|
||||
extension ShowSnackBar on BuildContext {
|
||||
void showSnackBar({
|
||||
required String message,
|
||||
Color backgroundColor = Colors.white,
|
||||
}) {
|
||||
ScaffoldMessenger.of(this).showSnackBar(SnackBar(
|
||||
content: Text(message),
|
||||
backgroundColor: backgroundColor,
|
||||
));
|
||||
}
|
||||
|
||||
void showErrorSnackBar({required String message}) {
|
||||
showSnackBar(message: message, backgroundColor: Colors.red);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ Future<void> main() async {
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
final supabase = Supabase.instance.client;
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'package:supabase_quickstart/components/avatar.dart';
|
||||
import 'package:supabase_quickstart/constants.dart';
|
||||
import 'package:supabase_quickstart/main.dart';
|
||||
|
||||
class AccountPage extends StatefulWidget {
|
||||
const AccountPage({super.key});
|
||||
@@ -33,9 +33,15 @@ class _AccountPageState extends State<AccountPage> {
|
||||
_websiteController.text = (data['website'] ?? '') as String;
|
||||
_avatarUrl = (data['avatar_url'] ?? '') as String;
|
||||
} on PostgrestException catch (error) {
|
||||
context.showErrorSnackBar(message: error.message);
|
||||
SnackBar(
|
||||
content: Text(error.message),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
} catch (error) {
|
||||
context.showErrorSnackBar(message: 'Unexpected exception occurred');
|
||||
SnackBar(
|
||||
content: const Text('Unexpected error occurred'),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
@@ -60,12 +66,20 @@ class _AccountPageState extends State<AccountPage> {
|
||||
try {
|
||||
await supabase.from('profiles').upsert(updates);
|
||||
if (mounted) {
|
||||
context.showSnackBar(message: 'Successfully updated profile!');
|
||||
const SnackBar(
|
||||
content: Text('Successfully updated profile!'),
|
||||
);
|
||||
}
|
||||
} on PostgrestException catch (error) {
|
||||
context.showErrorSnackBar(message: error.message);
|
||||
SnackBar(
|
||||
content: Text(error.message),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
} catch (error) {
|
||||
context.showErrorSnackBar(message: 'Unexpeted error occurred');
|
||||
SnackBar(
|
||||
content: const Text('Unexpected error occurred'),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
setState(() {
|
||||
_loading = false;
|
||||
@@ -76,9 +90,15 @@ class _AccountPageState extends State<AccountPage> {
|
||||
try {
|
||||
await supabase.auth.signOut();
|
||||
} on AuthException catch (error) {
|
||||
context.showErrorSnackBar(message: error.message);
|
||||
SnackBar(
|
||||
content: Text(error.message),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
} catch (error) {
|
||||
context.showErrorSnackBar(message: 'Unexpected error occurred');
|
||||
SnackBar(
|
||||
content: const Text('Unexpected error occurred'),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
if (mounted) {
|
||||
Navigator.of(context).pushReplacementNamed('/');
|
||||
@@ -94,12 +114,20 @@ class _AccountPageState extends State<AccountPage> {
|
||||
'avatar_url': imageUrl,
|
||||
});
|
||||
if (mounted) {
|
||||
context.showSnackBar(message: 'Updated your profile image!');
|
||||
const SnackBar(
|
||||
content: Text('Updated your profile image!'),
|
||||
);
|
||||
}
|
||||
} on PostgrestException catch (error) {
|
||||
context.showErrorSnackBar(message: error.message);
|
||||
SnackBar(
|
||||
content: Text(error.message),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
} catch (error) {
|
||||
context.showErrorSnackBar(message: 'Unexpected error has occurred');
|
||||
SnackBar(
|
||||
content: const Text('Unexpected error occurred'),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
if (!mounted) {
|
||||
return;
|
||||
|
||||
@@ -3,8 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
import 'package:supabase_quickstart/constants.dart';
|
||||
import 'package:supabase_quickstart/main.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
@@ -30,13 +29,21 @@ class _LoginPageState extends State<LoginPage> {
|
||||
kIsWeb ? null : 'io.supabase.flutterquickstart://login-callback/',
|
||||
);
|
||||
if (mounted) {
|
||||
context.showSnackBar(message: 'Check your email for login link!');
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Check your email for login link!')),
|
||||
);
|
||||
_emailController.clear();
|
||||
}
|
||||
} on AuthException catch (error) {
|
||||
context.showErrorSnackBar(message: error.message);
|
||||
SnackBar(
|
||||
content: Text(error.message),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
} catch (error) {
|
||||
context.showErrorSnackBar(message: 'Unexpected error occurred');
|
||||
SnackBar(
|
||||
content: const Text('Unexpected error occurred'),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:supabase_quickstart/constants.dart';
|
||||
import 'package:supabase_quickstart/main.dart';
|
||||
|
||||
class SplashPage extends StatefulWidget {
|
||||
const SplashPage({super.key});
|
||||
|
||||
Reference in new issue
Block a user