Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat custom email icons #108

Merged
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ SupaSocialsAuth(
## Theming

This library uses bare Flutter components so that you can control the appearance of the components using your own theme.
See theme example in example/lib/sign_in.dart
68 changes: 61 additions & 7 deletions example/lib/sign_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,48 @@ import 'constants.dart';

class SignUp extends StatelessWidget {
const SignUp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
void navigateHome(AuthResponse response) {
Navigator.of(context).pushReplacementNamed('/home');
}

final darkModeThemeData = ThemeData.dark().copyWith(
colorScheme: const ColorScheme.dark(
primary: Color.fromARGB(248, 183, 183, 183), // text below main button
),
textSelectionTheme: TextSelectionThemeData(
cursorColor: Colors.blueGrey[300], // cursor when typing
),
inputDecorationTheme: InputDecorationTheme(
fillColor: Colors.grey[800], // background of text entry
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide.none,
),
labelStyle: const TextStyle(color: Color.fromARGB(179, 255, 255, 255)), // text labeling text entry
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: const Color.fromARGB(255, 22, 135, 188), // main button
foregroundColor: const Color.fromARGB(255, 255, 255, 255), // main button text
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
);

return Scaffold(
appBar: appBar('Sign In'),
body: ListView(
padding: const EdgeInsets.all(24.0),
children: [
SupaEmailAuth(
redirectTo: kIsWeb ? null : 'io.supabase.flutter://',
onSignInComplete: (response) {
Navigator.of(context).pushReplacementNamed('/home');
},
onSignUpComplete: (response) {
Navigator.of(context).pushReplacementNamed('/home');
},
onSignInComplete: navigateHome,
onSignUpComplete: navigateHome,
metadataFields: [
MetaDataField(
prefixIcon: const Icon(Icons.person),
Expand All @@ -36,6 +62,34 @@ class SignUp extends StatelessWidget {
),
],
),

const Divider(),
optionText,
spacer,

// Dark theme example
Card(
elevation: 10,
color: const Color.fromARGB(255, 24, 24, 24),
child: Padding(
padding: const EdgeInsets.all(30),
child: Theme(
data: darkModeThemeData,
child: SupaEmailAuth(
redirectTo: kIsWeb ? null : 'io.supabase.flutter://',
onSignInComplete: navigateHome,
onSignUpComplete: navigateHome,
prefixIconEmail: null,
prefixIconPassword: null,
localization: const SupaEmailAuthLocalization(
enterEmail: "email",
enterPassword: "password",
dontHaveAccount: "sign up",
forgotPassword: "forgot password"),
),
),
)),

const Divider(),
optionText,
spacer,
Expand Down
10 changes: 8 additions & 2 deletions lib/src/components/supa_email_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class SupaEmailAuth extends StatefulWidget {
/// Localization for the form
final SupaEmailAuthLocalization localization;

/// Icons or custom prefix widgets for email UI
final Widget? prefixIconEmail;
final Widget? prefixIconPassword;

/// {@macro supa_email_auth}
const SupaEmailAuth({
super.key,
Expand All @@ -109,6 +113,8 @@ class SupaEmailAuth extends StatefulWidget {
this.metadataFields,
this.extraMetadata,
this.localization = const SupaEmailAuthLocalization(),
this.prefixIconEmail = const Icon(Icons.email),
this.prefixIconPassword = const Icon(Icons.lock),
});

@override
Expand Down Expand Up @@ -176,7 +182,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
return null;
},
decoration: InputDecoration(
prefixIcon: const Icon(Icons.email),
prefixIcon: widget.prefixIconEmail,
label: Text(localization.enterEmail),
),
controller: _emailController,
Expand All @@ -203,7 +209,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
return null;
},
decoration: InputDecoration(
prefixIcon: const Icon(Icons.lock),
prefixIcon: widget.prefixIconPassword,
label: Text(localization.enterPassword),
),
obscureText: true,
Expand Down
Loading