Skip to content

Commit 69a229d

Browse files
committed
feat: Add prefilled email, password to SupaEmailAuth
1 parent d67dc94 commit 69a229d

File tree

4 files changed

+86
-6
lines changed

4 files changed

+86
-6
lines changed

example/lib/main.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import 'package:flutter/material.dart';
33
import 'package:supabase_auth_ui/supabase_auth_ui.dart';
44

55
import './home.dart';
6-
import './sign_in.dart';
76
import './magic_link.dart';
7+
import './phone_sign_in.dart';
8+
import './sign_in.dart';
9+
import './sign_in_prefilled.dart';
810
import './update_password.dart';
9-
import 'phone_sign_in.dart';
1011
import './verify_phone.dart';
1112

1213
void main() async {
@@ -34,14 +35,15 @@ class MyApp extends StatelessWidget {
3435
border: OutlineInputBorder(),
3536
),
3637
),
37-
initialRoute: '/',
38+
initialRoute: '/prefilled',
3839
routes: {
3940
'/': (context) => const SignUp(),
4041
'/magic_link': (context) => const MagicLink(),
4142
'/update_password': (context) => const UpdatePassword(),
4243
'/phone_sign_in': (context) => const PhoneSignIn(),
4344
'/phone_sign_up': (context) => const PhoneSignUp(),
4445
'/verify_phone': (context) => const VerifyPhone(),
46+
'/prefilled': (context) => const SignInPrefilled(),
4547
'/home': (context) => const Home(),
4648
},
4749
onUnknownRoute: (RouteSettings settings) {

example/lib/sign_in_prefilled.dart

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'package:flutter/foundation.dart';
2+
import 'package:flutter/gestures.dart';
3+
import 'package:flutter/material.dart';
4+
import 'package:supabase_auth_ui/supabase_auth_ui.dart';
5+
6+
import 'constants.dart';
7+
8+
class SignInPrefilled extends StatelessWidget {
9+
const SignInPrefilled({Key? key}) : super(key: key);
10+
@override
11+
Widget build(BuildContext context) {
12+
void navigateHome(AuthResponse response) {
13+
Navigator.of(context).pushReplacementNamed('/home');
14+
}
15+
16+
return Scaffold(
17+
appBar: appBar('Sign In (Prefilled)'),
18+
body: ListView(
19+
padding: const EdgeInsets.all(24.0),
20+
children: [
21+
SupaEmailAuth(
22+
prefilledEmail: "mail@example.com",
23+
prefilledPassword: "password",
24+
redirectTo: kIsWeb ? null : 'io.supabase.flutter://',
25+
onSignInComplete: navigateHome,
26+
onSignUpComplete: navigateHome,
27+
metadataFields: [
28+
MetaDataField(
29+
prefixIcon: const Icon(Icons.person),
30+
label: 'Username',
31+
key: 'username',
32+
validator: (val) {
33+
if (val == null || val.isEmpty) {
34+
return 'Please enter something';
35+
}
36+
return null;
37+
},
38+
),
39+
BooleanMetaDataField(
40+
label: 'Keep me up to date with the latest news and updates.',
41+
key: 'marketing_consent',
42+
checkboxPosition: ListTileControlAffinity.leading,
43+
),
44+
BooleanMetaDataField(
45+
key: 'terms_agreement',
46+
isRequired: true,
47+
checkboxPosition: ListTileControlAffinity.leading,
48+
richLabelSpans: [
49+
const TextSpan(text: 'I have read and agree to the '),
50+
TextSpan(
51+
text: 'Terms and Conditions',
52+
style: const TextStyle(
53+
color: Colors.blue,
54+
),
55+
recognizer: TapGestureRecognizer()
56+
..onTap = () {
57+
// Handle tap on Terms and Conditions
58+
},
59+
),
60+
],
61+
),
62+
],
63+
),
64+
],
65+
),
66+
);
67+
}
68+
}

lib/src/components/supa_email_auth.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ class SupaEmailAuth extends StatefulWidget {
220220
/// Whether the confirm password field should be displayed
221221
final bool showConfirmPasswordField;
222222

223+
/// Pre-filled email for the form
224+
final String? prefilledEmail;
225+
226+
/// Pre-filled password for the form
227+
final String? prefilledPassword;
228+
223229
/// {@macro supa_email_auth}
224230
const SupaEmailAuth({
225231
super.key,
@@ -240,6 +246,8 @@ class SupaEmailAuth extends StatefulWidget {
240246
this.prefixIconEmail = const Icon(Icons.email),
241247
this.prefixIconPassword = const Icon(Icons.lock),
242248
this.showConfirmPasswordField = false,
249+
this.prefilledEmail,
250+
this.prefilledPassword,
243251
});
244252

245253
@override
@@ -265,6 +273,8 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
265273
@override
266274
void initState() {
267275
super.initState();
276+
_emailController.text = widget.prefilledEmail ?? '';
277+
_passwordController.text = widget.prefilledPassword ?? '';
268278
_isSigningIn = widget.isInitiallySigningIn;
269279
_metadataControllers = Map.fromEntries((widget.metadataFields ?? []).map(
270280
(metadataField) => MapEntry(

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: supabase_auth_ui
22
description: UI library to implement auth forms using Supabase and Flutter
3-
version: 0.5.5
3+
version: 0.5.6
44
homepage: https://supabase.com
55
repository: 'https://github.com/supabase-community/flutter-auth-ui'
66

@@ -12,10 +12,10 @@ dependencies:
1212
flutter:
1313
sdk: flutter
1414
supabase_flutter: ^2.5.6
15-
email_validator: ^2.0.1
15+
email_validator: ^3.0.0
1616
font_awesome_flutter: ^10.6.0
1717
google_sign_in: ^6.2.1
18-
sign_in_with_apple: ^6.1.0
18+
sign_in_with_apple: ^7.0.1
1919
crypto: ^3.0.3
2020

2121
dev_dependencies:

0 commit comments

Comments
 (0)