mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
* Refactor login_page with a _showSnackBar function * Add an onError block to onAuthStateChange Errors get swallowed without this error handler, I noticed it when I had requested too many magic link emails, there was no feedback in the ui, nor in the logs in the console. * Fix SnackBars not being displayed and add a _showSnackBar function * Fix code samples for login_page.dart and account_page.dart to reflect fixes in #27104 * Fix isError not being passed for an Unexpected Error in login_page * Update flutter user management example to a more modern code * Update the guide to match the new content * run formatter * got rid of excess code and minor format fix --------- Co-authored-by: dshukertjr <dshukertjr@gmail.com>
59 lines
1.6 KiB
Dart
59 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
|
import 'package:supabase_quickstart/pages/account_page.dart';
|
|
import 'package:supabase_quickstart/pages/login_page.dart';
|
|
|
|
Future<void> main() async {
|
|
await dotenv.load();
|
|
|
|
await Supabase.initialize(
|
|
url: dotenv.env['SUPABASE_URL']!,
|
|
anonKey: dotenv.env['SUPABASE_ANON_KEY']!,
|
|
);
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
final supabase = Supabase.instance.client;
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Supabase Flutter',
|
|
theme: ThemeData.dark().copyWith(
|
|
primaryColor: Colors.green,
|
|
textButtonTheme: TextButtonThemeData(
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: Colors.green,
|
|
),
|
|
),
|
|
elevatedButtonTheme: ElevatedButtonThemeData(
|
|
style: ElevatedButton.styleFrom(
|
|
foregroundColor: Colors.white,
|
|
backgroundColor: Colors.green,
|
|
),
|
|
),
|
|
),
|
|
home: supabase.auth.currentSession == null
|
|
? const LoginPage()
|
|
: const AccountPage(),
|
|
);
|
|
}
|
|
}
|
|
|
|
extension ContextExtension on BuildContext {
|
|
void showSnackBar(String message, {bool isError = false}) {
|
|
ScaffoldMessenger.of(this).showSnackBar(
|
|
SnackBar(
|
|
content: Text(message),
|
|
backgroundColor: isError
|
|
? Theme.of(this).colorScheme.error
|
|
: Theme.of(this).snackBarTheme.backgroundColor,
|
|
),
|
|
);
|
|
}
|
|
}
|