diff --git a/example/lib/main.dart b/example/lib/main.dart index ad28ebd..922c5ac 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -3,10 +3,11 @@ import 'package:flutter/material.dart'; import 'package:supabase_auth_ui/supabase_auth_ui.dart'; import './home.dart'; -import './sign_in.dart'; import './magic_link.dart'; +import './phone_sign_in.dart'; +import './sign_in.dart'; +import './sign_in_prefilled.dart'; import './update_password.dart'; -import 'phone_sign_in.dart'; import './verify_phone.dart'; void main() async { @@ -34,7 +35,7 @@ class MyApp extends StatelessWidget { border: OutlineInputBorder(), ), ), - initialRoute: '/', + initialRoute: '/prefilled', routes: { '/': (context) => const SignUp(), '/magic_link': (context) => const MagicLink(), @@ -42,6 +43,7 @@ class MyApp extends StatelessWidget { '/phone_sign_in': (context) => const PhoneSignIn(), '/phone_sign_up': (context) => const PhoneSignUp(), '/verify_phone': (context) => const VerifyPhone(), + '/prefilled': (context) => const SignInPrefilled(), '/home': (context) => const Home(), }, onUnknownRoute: (RouteSettings settings) { diff --git a/example/lib/sign_in_prefilled.dart b/example/lib/sign_in_prefilled.dart new file mode 100644 index 0000000..68f6238 --- /dev/null +++ b/example/lib/sign_in_prefilled.dart @@ -0,0 +1,68 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:supabase_auth_ui/supabase_auth_ui.dart'; + +import 'constants.dart'; + +class SignInPrefilled extends StatelessWidget { + const SignInPrefilled({Key? key}) : super(key: key); + @override + Widget build(BuildContext context) { + void navigateHome(AuthResponse response) { + Navigator.of(context).pushReplacementNamed('/home'); + } + + return Scaffold( + appBar: appBar('Sign In (Prefilled)'), + body: ListView( + padding: const EdgeInsets.all(24.0), + children: [ + SupaEmailAuth( + prefilledEmail: "mail@example.com", + prefilledPassword: "password", + redirectTo: kIsWeb ? null : 'io.supabase.flutter://', + onSignInComplete: navigateHome, + onSignUpComplete: navigateHome, + metadataFields: [ + MetaDataField( + prefixIcon: const Icon(Icons.person), + label: 'Username', + key: 'username', + validator: (val) { + if (val == null || val.isEmpty) { + return 'Please enter something'; + } + return null; + }, + ), + BooleanMetaDataField( + label: 'Keep me up to date with the latest news and updates.', + key: 'marketing_consent', + checkboxPosition: ListTileControlAffinity.leading, + ), + BooleanMetaDataField( + key: 'terms_agreement', + isRequired: true, + checkboxPosition: ListTileControlAffinity.leading, + richLabelSpans: [ + const TextSpan(text: 'I have read and agree to the '), + TextSpan( + text: 'Terms and Conditions', + style: const TextStyle( + color: Colors.blue, + ), + recognizer: TapGestureRecognizer() + ..onTap = () { + // Handle tap on Terms and Conditions + }, + ), + ], + ), + ], + ), + ], + ), + ); + } +} diff --git a/lib/src/components/supa_email_auth.dart b/lib/src/components/supa_email_auth.dart index 0fd2396..50aa70b 100644 --- a/lib/src/components/supa_email_auth.dart +++ b/lib/src/components/supa_email_auth.dart @@ -220,6 +220,12 @@ class SupaEmailAuth extends StatefulWidget { /// Whether the confirm password field should be displayed final bool showConfirmPasswordField; + /// Pre-filled email for the form + final String? prefilledEmail; + + /// Pre-filled password for the form + final String? prefilledPassword; + /// {@macro supa_email_auth} const SupaEmailAuth({ super.key, @@ -240,6 +246,8 @@ class SupaEmailAuth extends StatefulWidget { this.prefixIconEmail = const Icon(Icons.email), this.prefixIconPassword = const Icon(Icons.lock), this.showConfirmPasswordField = false, + this.prefilledEmail, + this.prefilledPassword, }); @override @@ -265,6 +273,8 @@ class _SupaEmailAuthState extends State { @override void initState() { super.initState(); + _emailController.text = widget.prefilledEmail ?? ''; + _passwordController.text = widget.prefilledPassword ?? ''; _isSigningIn = widget.isInitiallySigningIn; _metadataControllers = Map.fromEntries((widget.metadataFields ?? []).map( (metadataField) => MapEntry( diff --git a/pubspec.yaml b/pubspec.yaml index 880ca10..f21c691 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: supabase_auth_ui description: UI library to implement auth forms using Supabase and Flutter -version: 0.5.5 +version: 0.5.6 homepage: https://supabase.com repository: 'https://github.com/supabase-community/flutter-auth-ui' @@ -12,10 +12,10 @@ dependencies: flutter: sdk: flutter supabase_flutter: ^2.5.6 - email_validator: ^2.0.1 + email_validator: ^3.0.0 font_awesome_flutter: ^10.6.0 google_sign_in: ^6.2.1 - sign_in_with_apple: ^6.1.0 + sign_in_with_apple: ^7.0.1 crypto: ^3.0.3 dev_dependencies: