2024-02-06 09:40:43 +01:00
|
|
|
// SPDX-FileCopyrightText: 2024 Iconica
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_input_library/flutter_input_library.dart';
|
|
|
|
import 'package:flutter_registration/flutter_registration.dart';
|
|
|
|
|
2024-02-19 13:31:12 +01:00
|
|
|
/// A field for capturing password inputs in a Flutter form.
|
|
|
|
///
|
|
|
|
/// Extends [AuthField].
|
2024-02-06 09:40:43 +01:00
|
|
|
class AuthPassField extends AuthField {
|
2024-02-19 13:31:12 +01:00
|
|
|
/// Constructs an [AuthPassField] object.
|
|
|
|
///
|
|
|
|
/// [name] specifies the name of the field.
|
|
|
|
///
|
|
|
|
/// [textEditingController] controller for the password input (optional).
|
|
|
|
///
|
|
|
|
/// [title] specifies the title widget of the field (optional).
|
|
|
|
///
|
|
|
|
/// [validators] defines a list of validation functions for the field (optional).
|
|
|
|
///
|
|
|
|
/// [value] specifies the initial value of the field (default is an empty string).
|
|
|
|
///
|
|
|
|
/// [textStyle] defines the text style for the password input.
|
|
|
|
///
|
|
|
|
/// [onChange] is a callback function triggered when the value of the field changes.
|
|
|
|
///
|
|
|
|
/// [iconSize] specifies the size of the icon displayed with the password input (optional).
|
|
|
|
///
|
|
|
|
/// [textFieldDecoration] defines the decoration for the password input field (optional).
|
|
|
|
///
|
|
|
|
/// [padding] defines the padding around the password input field (default is EdgeInsets.all(8.0)).
|
2024-02-06 09:40:43 +01:00
|
|
|
AuthPassField({
|
|
|
|
required super.name,
|
|
|
|
TextEditingController? textEditingController,
|
|
|
|
super.title,
|
|
|
|
super.validators = const [],
|
|
|
|
super.value = '',
|
|
|
|
this.textStyle,
|
|
|
|
this.onChange,
|
2024-02-08 15:33:41 +01:00
|
|
|
this.iconSize,
|
2024-02-06 09:40:43 +01:00
|
|
|
this.textFieldDecoration,
|
2024-02-06 09:51:25 +01:00
|
|
|
this.padding = const EdgeInsets.all(8.0),
|
2024-02-06 09:40:43 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
final TextStyle? textStyle;
|
2024-02-08 15:33:41 +01:00
|
|
|
final double? iconSize;
|
2024-02-06 09:40:43 +01:00
|
|
|
final Function(String value)? onChange;
|
|
|
|
final InputDecoration? textFieldDecoration;
|
2024-02-06 09:51:25 +01:00
|
|
|
final EdgeInsets padding;
|
2024-02-06 09:40:43 +01:00
|
|
|
|
|
|
|
@override
|
2024-02-09 18:36:22 +01:00
|
|
|
Widget build(BuildContext context, Function onValueChanged) {
|
2024-02-06 09:40:43 +01:00
|
|
|
return Padding(
|
2024-02-06 09:51:25 +01:00
|
|
|
padding: padding,
|
2024-02-06 09:40:43 +01:00
|
|
|
child: FlutterFormInputPassword(
|
|
|
|
style: textStyle,
|
2024-02-08 15:33:41 +01:00
|
|
|
iconSize: iconSize ?? 24.0,
|
2024-02-06 09:40:43 +01:00
|
|
|
decoration: textFieldDecoration,
|
|
|
|
onChanged: (v) {
|
|
|
|
value = v;
|
|
|
|
onChange?.call(value);
|
2024-02-09 18:36:22 +01:00
|
|
|
onValueChanged();
|
2024-02-06 09:40:43 +01:00
|
|
|
},
|
|
|
|
validator: (value) {
|
|
|
|
for (var validator in validators) {
|
|
|
|
var output = validator(value);
|
|
|
|
if (output != null) {
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|