2020-07-27 20:43:58 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
|
|
|
|
2022-01-20 16:35:39 +00:00
|
|
|
/// 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,
|
|
|
|
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,
|
2020-08-31 23:32:40 +00:00
|
|
|
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;
|
2022-01-18 16:58:26 +00:00
|
|
|
final MaxLengthEnforcement maxLengthEnforcement;
|
2020-07-27 20:43:58 +00:00
|
|
|
final Widget suffix;
|
|
|
|
final TextStyle style;
|
|
|
|
final TextInputType keyboardType;
|
|
|
|
final Brightness keyboardAppearance;
|
|
|
|
|
|
|
|
final TextInputAction textInputAction;
|
|
|
|
final TextCapitalization textCapitalization;
|
|
|
|
final TextAlign textAlign;
|
|
|
|
final TextAlignVertical textAlignVertical;
|
|
|
|
|
|
|
|
final bool autofocus;
|
|
|
|
final ValueChanged<String> onChanged;
|
2020-08-31 23:32:40 +00:00
|
|
|
final bool enabled;
|
2020-07-27 20:43:58 +00:00
|
|
|
final List<TextInputFormatter> inputFormatters;
|
|
|
|
final bool expands;
|
|
|
|
|
|
|
|
@override
|
|
|
|
_SpecialTextFieldState createState() => _SpecialTextFieldState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SpecialTextFieldState extends State<SpecialTextField> {
|
|
|
|
List<TextInputFormatter> formatters;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
formatters = widget.inputFormatters;
|
|
|
|
if (formatters == null || formatters.length == 0) {
|
2021-04-23 17:33:28 +00:00
|
|
|
formatters = [FilteringTextInputFormatter.allow(RegExp(r'[^\t]'))];
|
2020-07-27 20:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-01-20 16:35:39 +00:00
|
|
|
return PlatformTextField(
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|