Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 41814b9

Browse files
HenryRoutsonHenry Routsondshukertjr
authoredAug 15, 2024··
Feat custom email icons (#108)
* allow icons in email ui to be removed * refactor : combine identical closures into function * feat : allow custom icons or none in email sign in / up * add dark themed example * fix : format * fix : const warnings * fix : comments and add mention of theme example in README * fix : comment * fix : comment * fix : typo * Update lib/src/components/supa_email_auth.dart Co-authored-by: Tyler <[email protected]> * Update example/lib/sign_in.dart Co-authored-by: Tyler <[email protected]> * fix : update name elsewhere, add const --------- Co-authored-by: Henry Routson <[email protected]> Co-authored-by: Tyler <[email protected]>
1 parent a450e29 commit 41814b9

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@ SupaSocialsAuth(
100100
## Theming
101101

102102
This library uses bare Flutter components so that you can control the appearance of the components using your own theme.
103+
See theme example in example/lib/sign_in.dart

‎example/lib/sign_in.dart

+61-7
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,48 @@ import 'constants.dart';
66

77
class SignUp extends StatelessWidget {
88
const SignUp({Key? key}) : super(key: key);
9-
109
@override
1110
Widget build(BuildContext context) {
11+
void navigateHome(AuthResponse response) {
12+
Navigator.of(context).pushReplacementNamed('/home');
13+
}
14+
15+
final darkModeThemeData = ThemeData.dark().copyWith(
16+
colorScheme: const ColorScheme.dark(
17+
primary: Color.fromARGB(248, 183, 183, 183), // text below main button
18+
),
19+
textSelectionTheme: TextSelectionThemeData(
20+
cursorColor: Colors.blueGrey[300], // cursor when typing
21+
),
22+
inputDecorationTheme: InputDecorationTheme(
23+
fillColor: Colors.grey[800], // background of text entry
24+
filled: true,
25+
border: OutlineInputBorder(
26+
borderRadius: BorderRadius.circular(8),
27+
borderSide: BorderSide.none,
28+
),
29+
labelStyle: const TextStyle(color: Color.fromARGB(179, 255, 255, 255)), // text labeling text entry
30+
),
31+
elevatedButtonTheme: ElevatedButtonThemeData(
32+
style: ElevatedButton.styleFrom(
33+
backgroundColor: const Color.fromARGB(255, 22, 135, 188), // main button
34+
foregroundColor: const Color.fromARGB(255, 255, 255, 255), // main button text
35+
shape: RoundedRectangleBorder(
36+
borderRadius: BorderRadius.circular(8),
37+
),
38+
),
39+
),
40+
);
41+
1242
return Scaffold(
1343
appBar: appBar('Sign In'),
1444
body: ListView(
1545
padding: const EdgeInsets.all(24.0),
1646
children: [
1747
SupaEmailAuth(
1848
redirectTo: kIsWeb ? null : 'io.supabase.flutter://',
19-
onSignInComplete: (response) {
20-
Navigator.of(context).pushReplacementNamed('/home');
21-
},
22-
onSignUpComplete: (response) {
23-
Navigator.of(context).pushReplacementNamed('/home');
24-
},
49+
onSignInComplete: navigateHome,
50+
onSignUpComplete: navigateHome,
2551
metadataFields: [
2652
MetaDataField(
2753
prefixIcon: const Icon(Icons.person),
@@ -36,6 +62,34 @@ class SignUp extends StatelessWidget {
3662
),
3763
],
3864
),
65+
66+
const Divider(),
67+
optionText,
68+
spacer,
69+
70+
// Dark theme example
71+
Card(
72+
elevation: 10,
73+
color: const Color.fromARGB(255, 24, 24, 24),
74+
child: Padding(
75+
padding: const EdgeInsets.all(30),
76+
child: Theme(
77+
data: darkModeThemeData,
78+
child: SupaEmailAuth(
79+
redirectTo: kIsWeb ? null : 'io.supabase.flutter://',
80+
onSignInComplete: navigateHome,
81+
onSignUpComplete: navigateHome,
82+
prefixIconEmail: null,
83+
prefixIconPassword: null,
84+
localization: const SupaEmailAuthLocalization(
85+
enterEmail: "email",
86+
enterPassword: "password",
87+
dontHaveAccount: "sign up",
88+
forgotPassword: "forgot password"),
89+
),
90+
),
91+
)),
92+
3993
const Divider(),
4094
optionText,
4195
spacer,

‎lib/src/components/supa_email_auth.dart

+8-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ class SupaEmailAuth extends StatefulWidget {
9595
/// Localization for the form
9696
final SupaEmailAuthLocalization localization;
9797

98+
/// Icons or custom prefix widgets for email UI
99+
final Widget? prefixIconEmail;
100+
final Widget? prefixIconPassword;
101+
98102
/// {@macro supa_email_auth}
99103
const SupaEmailAuth({
100104
super.key,
@@ -109,6 +113,8 @@ class SupaEmailAuth extends StatefulWidget {
109113
this.metadataFields,
110114
this.extraMetadata,
111115
this.localization = const SupaEmailAuthLocalization(),
116+
this.prefixIconEmail = const Icon(Icons.email),
117+
this.prefixIconPassword = const Icon(Icons.lock),
112118
});
113119

114120
@override
@@ -176,7 +182,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
176182
return null;
177183
},
178184
decoration: InputDecoration(
179-
prefixIcon: const Icon(Icons.email),
185+
prefixIcon: widget.prefixIconEmail,
180186
label: Text(localization.enterEmail),
181187
),
182188
controller: _emailController,
@@ -203,7 +209,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
203209
return null;
204210
},
205211
decoration: InputDecoration(
206-
prefixIcon: const Icon(Icons.lock),
212+
prefixIcon: widget.prefixIconPassword,
207213
label: Text(localization.enterPassword),
208214
),
209215
obscureText: true,

0 commit comments

Comments
 (0)