forked from hiddify/hiddify-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_text_form_field.dart
77 lines (73 loc) · 2.34 KB
/
custom_text_form_field.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hiddify/utils/text_utils.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
class CustomTextFormField extends HookConsumerWidget {
const CustomTextFormField({
super.key,
this.onChanged,
this.validator,
this.controller,
this.inputFormatters,
this.initialValue = '',
this.suffixIcon,
this.label,
this.hint,
this.maxLines,
this.isDense = false,
this.autoValidate = false,
this.autoCorrect = false,
});
final ValueChanged<String>? onChanged;
final String? Function(String? value)? validator;
final TextEditingController? controller;
final List<TextInputFormatter>? inputFormatters;
final String initialValue;
final Widget? suffixIcon;
final String? label;
final String? hint;
final int? maxLines;
final bool isDense;
final bool autoValidate;
final bool autoCorrect;
@override
Widget build(BuildContext context, WidgetRef ref) {
final textController =
controller ?? useTextEditingController(text: initialValue);
final effectiveConstraints =
isDense ? const BoxConstraints(maxHeight: 56) : null;
final effectiveBorder = isDense
? OutlineInputBorder(
borderRadius: BorderRadius.circular(36),
borderSide: BorderSide.none,
)
: null;
return TextFormField(
controller: textController,
textCapitalization: TextCapitalization.sentences,
maxLines: maxLines,
onChanged: onChanged,
textDirection: textController.textDirection,
validator: validator,
textInputAction: TextInputAction.next,
inputFormatters: inputFormatters,
autovalidateMode:
autoValidate ? AutovalidateMode.always : AutovalidateMode.disabled,
autocorrect: autoCorrect,
decoration: InputDecoration(
isDense: true,
label: label != null ? Text(label!) : null,
hintText: hint,
hintStyle: Theme.of(context).textTheme.bodySmall,
constraints: effectiveConstraints,
suffixIcon: suffixIcon,
border: effectiveBorder,
enabledBorder: effectiveBorder,
errorBorder: effectiveBorder,
focusedBorder: effectiveBorder,
focusedErrorBorder: effectiveBorder,
),
);
}
}