3
0
Fork 0
trifid_mobile/lib/components/SpecialTextField.dart

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

118 lines
3.6 KiB
Dart
Raw Normal View History

2020-07-27 20:43:58 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
/// A normal TextField or CupertinoTextField that looks the same on all platforms
2020-07-27 20:43:58 +00:00
class SpecialTextField extends StatefulWidget {
const SpecialTextField(
{Key? key,
2020-07-27 20:43:58 +00:00
this.placeholder,
this.suffix,
this.controller,
this.focusNode,
this.nextFocusNode,
this.autocorrect,
this.minLines,
this.maxLines,
this.maxLength,
2022-01-18 16:58:26 +00:00
this.maxLengthEnforcement,
2020-07-27 20:43:58 +00:00
this.style,
this.keyboardType,
this.textInputAction,
this.textCapitalization,
this.textAlign,
this.autofocus,
this.onChanged,
this.enabled,
2020-07-27 20:43:58 +00:00
this.expands,
this.keyboardAppearance,
this.textAlignVertical,
this.inputFormatters})
: super(key: key);
final String? placeholder;
final TextEditingController? controller;
final FocusNode? focusNode;
final FocusNode? nextFocusNode;
final bool? autocorrect;
final int? minLines;
final int? maxLines;
final int? maxLength;
final MaxLengthEnforcement? maxLengthEnforcement;
final Widget? suffix;
final TextStyle? style;
final TextInputType? keyboardType;
final Brightness? keyboardAppearance;
2020-07-27 20:43:58 +00:00
final TextInputAction? textInputAction;
final TextCapitalization? textCapitalization;
final TextAlign? textAlign;
final TextAlignVertical? textAlignVertical;
2020-07-27 20:43:58 +00:00
final bool? autofocus;
final ValueChanged<String>? onChanged;
final bool? enabled;
final List<TextInputFormatter>? inputFormatters;
final bool? expands;
2020-07-27 20:43:58 +00:00
@override
_SpecialTextFieldState createState() => _SpecialTextFieldState();
}
class _SpecialTextFieldState extends State<SpecialTextField> {
List<TextInputFormatter> formatters = [];
2020-07-27 20:43:58 +00:00
@override
void initState() {
if (widget.inputFormatters == null || formatters.length == 0) {
2021-04-23 17:33:28 +00:00
formatters = [FilteringTextInputFormatter.allow(RegExp(r'[^\t]'))];
} else {
formatters = widget.inputFormatters!;
2020-07-27 20:43:58 +00:00
}
super.initState();
}
@override
Widget build(BuildContext context) {
return PlatformTextField(
2022-07-27 16:38:02 +00:00
autocorrect: widget.autocorrect,
minLines: widget.minLines,
maxLines: widget.maxLines,
maxLength: widget.maxLength,
maxLengthEnforcement: widget.maxLengthEnforcement,
keyboardType: widget.keyboardType,
keyboardAppearance: widget.keyboardAppearance,
textInputAction: widget.textInputAction,
textCapitalization: widget.textCapitalization,
textAlign: widget.textAlign,
textAlignVertical: widget.textAlignVertical,
autofocus: widget.autofocus,
focusNode: widget.focusNode,
onChanged: widget.onChanged,
enabled: widget.enabled,
onSubmitted: (_) {
if (widget.nextFocusNode != null) {
FocusScope.of(context).requestFocus(widget.nextFocusNode);
}
},
expands: widget.expands,
inputFormatters: formatters,
material: (_, __) => MaterialTextFieldData(
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.zero,
isDense: true,
hintText: widget.placeholder,
counterText: '',
suffix: widget.suffix)),
cupertino: (_, __) => CupertinoTextFieldData(
decoration: BoxDecoration(),
padding: EdgeInsets.zero,
placeholder: widget.placeholder,
suffix: widget.suffix),
style: widget.style,
controller: widget.controller);
2020-07-27 20:43:58 +00:00
}
}