2022-11-01 09:19:20 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Iconica
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2022-09-22 10:09:45 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_registration/flutter_registration.dart';
|
|
|
|
|
|
|
|
class AuthTextField extends AuthField {
|
|
|
|
AuthTextField({
|
|
|
|
required super.name,
|
2023-03-09 09:12:05 +01:00
|
|
|
TextEditingController? textEditingController,
|
2023-02-16 15:02:03 +01:00
|
|
|
super.title,
|
2022-09-22 10:09:45 +02:00
|
|
|
super.validators = const [],
|
|
|
|
super.value = '',
|
2022-09-22 10:22:32 +02:00
|
|
|
this.obscureText = false,
|
2022-09-26 15:09:01 +02:00
|
|
|
this.hintText,
|
2023-02-16 15:02:03 +01:00
|
|
|
this.label,
|
|
|
|
this.textStyle,
|
|
|
|
this.onChange,
|
2023-03-09 09:12:05 +01:00
|
|
|
this.hidden,
|
|
|
|
this.onPassChanged,
|
2024-02-02 11:19:21 +01:00
|
|
|
this.textFieldDecoration,
|
2022-09-22 10:09:45 +02:00
|
|
|
}) {
|
2023-03-09 09:12:05 +01:00
|
|
|
textController =
|
|
|
|
textEditingController ?? TextEditingController(text: value);
|
2022-09-22 10:09:45 +02:00
|
|
|
}
|
|
|
|
|
2023-03-09 09:12:05 +01:00
|
|
|
late TextEditingController textController;
|
2022-09-22 10:22:32 +02:00
|
|
|
final bool obscureText;
|
2022-09-26 15:09:01 +02:00
|
|
|
final String? hintText;
|
2023-02-16 15:02:03 +01:00
|
|
|
final Widget? label;
|
|
|
|
final TextStyle? textStyle;
|
|
|
|
final Function(String value)? onChange;
|
2023-03-09 09:12:05 +01:00
|
|
|
final bool? hidden;
|
|
|
|
final Function(bool value)? onPassChanged;
|
2024-02-02 11:19:21 +01:00
|
|
|
final InputDecoration? textFieldDecoration;
|
2022-09-22 10:09:45 +02:00
|
|
|
|
|
|
|
@override
|
2023-03-09 09:12:05 +01:00
|
|
|
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),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-02 22:18:03 +01:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: TextFormField(
|
|
|
|
style: textStyle,
|
|
|
|
decoration: textFieldDecoration ??
|
|
|
|
InputDecoration(
|
|
|
|
label: label,
|
|
|
|
hintText: hintText,
|
|
|
|
suffix: suffix,
|
|
|
|
),
|
|
|
|
controller: textController,
|
|
|
|
obscureText: hidden ?? obscureText,
|
|
|
|
onChanged: (v) {
|
|
|
|
value = v;
|
|
|
|
onChange?.call(value);
|
|
|
|
},
|
|
|
|
validator: (value) {
|
|
|
|
for (var validator in validators) {
|
|
|
|
var output = validator(value);
|
|
|
|
if (output != null) {
|
|
|
|
return output;
|
|
|
|
}
|
2022-09-22 10:09:45 +02:00
|
|
|
}
|
|
|
|
|
2024-02-02 22:18:03 +01:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
),
|
2023-03-09 09:12:05 +01:00
|
|
|
);
|
|
|
|
}
|
2022-09-22 10:09:45 +02:00
|
|
|
}
|