Skip to content

Commit

Permalink
Add BooleanMetaDataField for checkbox inputs in SupaEmailAuth
Browse files Browse the repository at this point in the history
This commit introduces a new BooleanMetaDataField class to support checkbox inputs
in the SupaEmailAuth component. This enhancement allows for more versatile form
creation, particularly useful for consent checkboxes or boolean preferences.

Key changes:

1. New BooleanMetaDataField class:
   - Extends MetaDataField to maintain compatibility
   - Supports both simple text labels and rich text labels with interactive elements
     (allowing links to be inserted within the text)
   - Supports semantic labeling for accessability
   - Allows customization of checkbox position (leading or trailing)
   - Includes a 'required' option for mandatory fields

2. Updates to SupaEmailAuth:
   - Modified to handle both MetaDataField and BooleanMetaDataField
   - Implemented rendering logic for checkbox fields
   - Added support for rich text labels in checkboxes
   - Implemented validation for required checkbox fields

3. Styling improvements:
   - Ensured checkbox styling matches other form elements
   - Added support for dark mode theming
   - Implemented error message display for invalid checkbox fields
   - Error message added to localization class

4. Documentation:
   - Added comprehensive documentation for BooleanMetaDataField
   - Updated existing documentation to reflect new capabilities

5. Example updates:
   - Modified example code to demonstrate usage of BooleanMetaDataField
   - Included examples of both simple and rich text labels

6. Backward compatibility:
   - Maintained support for existing MetaDataField usage
   - No breaking changes to public API

This enhancement provides developers with more flexibility in creating
sign-up forms, particularly for scenarios requiring user consent or
boolean preferences, while maintaining the existing functionality
of the SupaEmailAuth component.
  • Loading branch information
bcorman committed Oct 3, 2024
1 parent a5c75b8 commit e5f4e7f
Show file tree
Hide file tree
Showing 3 changed files with 296 additions and 42 deletions.
96 changes: 82 additions & 14 deletions example/lib/sign_in.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:supabase_auth_ui/supabase_auth_ui.dart';

Expand Down Expand Up @@ -26,12 +27,16 @@ class SignUp extends StatelessWidget {
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide.none,
),
labelStyle: const TextStyle(color: Color.fromARGB(179, 255, 255, 255)), // text labeling text entry
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
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),
),
Expand Down Expand Up @@ -60,6 +65,32 @@ class SignUp extends StatelessWidget {
return null;
},
),
// Checkbox on the right
BooleanMetaDataField(
label: 'I agree to a checkbox on the right',
key: 'right_checkbox',
),

// Checkbox on the left
BooleanMetaDataField(
key: 'terms_agreement',
required: 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 = () {
//ignore: avoid_print
print('Terms and Conditions');
},
),
],
),
],
),

Expand All @@ -76,17 +107,54 @@ class SignUp extends StatelessWidget {
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"),
),
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"),
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: 'I wish to receive marketing emails',
key: 'marketing_consent',
checkboxPosition: ListTileControlAffinity.leading,
),
BooleanMetaDataField(
key: 'terms_agreement',
required: 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 = () {
//ignore: avoid_print
print('Terms and Conditions');
},
),
],
),
]),
),
)),

Expand Down
Loading

0 comments on commit e5f4e7f

Please sign in to comment.