mirror of
https://github.com/Iconica-Development/flutter_registration.git
synced 2025-05-19 13:23:45 +02:00
feat: Added the abilty to show and hide the passwords
This commit is contained in:
parent
67d4aa1c45
commit
84d7519da6
4 changed files with 86 additions and 31 deletions
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_registration/src/model/auth_field.dart';
|
import 'package:flutter_registration/flutter_registration.dart';
|
||||||
import 'package:flutter_registration/src/model/auth_step.dart';
|
|
||||||
|
|
||||||
class AuthScreen extends StatefulWidget {
|
class AuthScreen extends StatefulWidget {
|
||||||
const AuthScreen({
|
const AuthScreen({
|
||||||
|
@ -73,7 +72,8 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||||
|
|
||||||
for (var step in widget.steps) {
|
for (var step in widget.steps) {
|
||||||
for (var field in step.fields) {
|
for (var field in step.fields) {
|
||||||
values[field.name] = field.value;
|
values[field.name] =
|
||||||
|
(field as AuthTextField).textController.value.text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,12 @@ class RegistrationOptions {
|
||||||
previousButtonBuilder;
|
previousButtonBuilder;
|
||||||
|
|
||||||
static List<AuthStep> getDefaultSteps({
|
static List<AuthStep> getDefaultSteps({
|
||||||
|
TextEditingController? emailController,
|
||||||
|
TextEditingController? pass1Controller,
|
||||||
|
bool pass1Hidden = true,
|
||||||
|
TextEditingController? pass2Controller,
|
||||||
|
bool pass2Hidden = true,
|
||||||
|
Function(bool mainPass, bool value)? passHideOnChange,
|
||||||
RegistrationTranslations translations = const RegistrationTranslations(),
|
RegistrationTranslations translations = const RegistrationTranslations(),
|
||||||
Function(String title)? titleBuilder,
|
Function(String title)? titleBuilder,
|
||||||
Function(String label)? labelBuilder,
|
Function(String label)? labelBuilder,
|
||||||
|
@ -40,6 +46,7 @@ class RegistrationOptions {
|
||||||
fields: [
|
fields: [
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
name: 'email',
|
name: 'email',
|
||||||
|
textEditingController: emailController,
|
||||||
value: initialEmail ?? '',
|
value: initialEmail ?? '',
|
||||||
title: titleBuilder?.call(
|
title: titleBuilder?.call(
|
||||||
translations.defaultEmailTitle,
|
translations.defaultEmailTitle,
|
||||||
|
@ -76,6 +83,7 @@ class RegistrationOptions {
|
||||||
fields: [
|
fields: [
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
name: 'password1',
|
name: 'password1',
|
||||||
|
textEditingController: pass1Controller,
|
||||||
title: titleBuilder?.call(
|
title: titleBuilder?.call(
|
||||||
translations.defaultPassword1Title,
|
translations.defaultPassword1Title,
|
||||||
) ??
|
) ??
|
||||||
|
@ -103,18 +111,36 @@ class RegistrationOptions {
|
||||||
onChange: (value) {
|
onChange: (value) {
|
||||||
password1 = value;
|
password1 = value;
|
||||||
},
|
},
|
||||||
|
hidden: pass1Hidden,
|
||||||
|
onPassChanged: (value) {
|
||||||
|
passHideOnChange?.call(true, value);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
name: 'password2',
|
name: 'password2',
|
||||||
|
textEditingController: pass2Controller,
|
||||||
label: labelBuilder?.call(translations.defaultPassword2Label),
|
label: labelBuilder?.call(translations.defaultPassword2Label),
|
||||||
hintText: translations.defaultPassword2Hint,
|
hintText: translations.defaultPassword2Hint,
|
||||||
textStyle: textStyle,
|
textStyle: textStyle,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
validators: [
|
validators: [
|
||||||
(value) => (value != password1)
|
(value) {
|
||||||
? translations.defaultPassword2ValidatorMessage
|
if (pass1Controller != null) {
|
||||||
: null,
|
if (value != pass1Controller.value.text) {
|
||||||
|
return translations.defaultPassword2ValidatorMessage;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (value != password1) {
|
||||||
|
return translations.defaultPassword2ValidatorMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
],
|
],
|
||||||
|
hidden: pass2Hidden,
|
||||||
|
onPassChanged: (value) {
|
||||||
|
passHideOnChange?.call(false, value);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -8,6 +8,7 @@ import 'package:flutter_registration/flutter_registration.dart';
|
||||||
class AuthTextField extends AuthField {
|
class AuthTextField extends AuthField {
|
||||||
AuthTextField({
|
AuthTextField({
|
||||||
required super.name,
|
required super.name,
|
||||||
|
TextEditingController? textEditingController,
|
||||||
super.title,
|
super.title,
|
||||||
super.validators = const [],
|
super.validators = const [],
|
||||||
super.value = '',
|
super.value = '',
|
||||||
|
@ -16,26 +17,53 @@ class AuthTextField extends AuthField {
|
||||||
this.label,
|
this.label,
|
||||||
this.textStyle,
|
this.textStyle,
|
||||||
this.onChange,
|
this.onChange,
|
||||||
|
this.hidden,
|
||||||
|
this.onPassChanged,
|
||||||
}) {
|
}) {
|
||||||
_textEditingController = TextEditingController(text: value);
|
textController =
|
||||||
|
textEditingController ?? TextEditingController(text: value);
|
||||||
}
|
}
|
||||||
|
|
||||||
late TextEditingController _textEditingController;
|
late TextEditingController textController;
|
||||||
final bool obscureText;
|
final bool obscureText;
|
||||||
final String? hintText;
|
final String? hintText;
|
||||||
final Widget? label;
|
final Widget? label;
|
||||||
final TextStyle? textStyle;
|
final TextStyle? textStyle;
|
||||||
final Function(String value)? onChange;
|
final Function(String value)? onChange;
|
||||||
|
final bool? hidden;
|
||||||
|
final Function(bool value)? onPassChanged;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build() => TextFormField(
|
Widget build() {
|
||||||
|
Widget? suffix;
|
||||||
|
|
||||||
|
if (hidden != null) {
|
||||||
|
if (hidden!) {
|
||||||
|
suffix = GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
onPassChanged?.call(!hidden!);
|
||||||
|
},
|
||||||
|
child: const Icon(Icons.visibility),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
suffix = GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
onPassChanged?.call(!hidden!);
|
||||||
|
},
|
||||||
|
child: const Icon(Icons.visibility_off),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TextFormField(
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
label: label,
|
label: label,
|
||||||
hintText: hintText,
|
hintText: hintText,
|
||||||
|
suffix: suffix,
|
||||||
),
|
),
|
||||||
controller: _textEditingController,
|
controller: textController,
|
||||||
obscureText: obscureText,
|
obscureText: hidden ?? obscureText,
|
||||||
onChanged: (v) {
|
onChanged: (v) {
|
||||||
value = v;
|
value = v;
|
||||||
onChange?.call(value);
|
onChange?.call(value);
|
||||||
|
@ -51,4 +79,5 @@ class AuthTextField extends AuthField {
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
name: flutter_registration
|
name: flutter_registration
|
||||||
description: A Flutter Registration package
|
description: A Flutter Registration package
|
||||||
version: 0.3.0
|
version: 0.4.0
|
||||||
repository: https://github.com/Iconica-Development/flutter_registration
|
repository: https://github.com/Iconica-Development/flutter_registration
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|
Loading…
Reference in a new issue