mirror of
https://github.com/DefinedNet/mobile_nebula.git
synced 2025-03-06 16:46:35 +00:00
* Enable `flutter_lints` linting * Fix unmarked deps, we aren't on web so we don't need a URL strategy * ` dart fix --apply --code=use_super_parameters` * `dart fix --apply --code=use_key_in_widget_constructors` * `dart fix --apply --code=use_function_type_syntax_for_parameters` * Ignore code-generated `lib/services/theme.dart` file * `dart fix --apply --code=unnecessary_this` * `dart fix --apply --code=unnecessary_null_in_if_null_operators` * `dart fix --apply --code=unnecessary_new` * `dart fix --apply --code=sort_child_properties_last` * `dart fix --apply --code=sized_box_for_whitespace` * `dart fix --apply --code=prefer_typing_uninitialized_variables` * `dart fix --apply --code=prefer_is_empty` * `dart fix --apply --code=prefer_interpolation_to_compose_strings` * `dart fix --apply --code=prefer_final_fields` * `dart fix --apply --code=prefer_const_constructors_in_immutables` * `dart fix --apply --code=prefer_collection_literals` * `dart fix --apply --code=no_leading_underscores_for_local_identifiers` * `dart fix --apply --code=curly_braces_in_flow_control_structures` * `dart fix --apply --code=avoid_function_literals_in_foreach_calls` * `dart fix --apply --code=annotate_overrides` * Add CI for dart linting * `dart format lib/` * Re-enable the `usePathUrlStrategy` call, with proper deps https://docs.flutter.dev/ui/navigation/url-strategies#configuring-the-url-strategy
123 lines
3.5 KiB
Dart
123 lines
3.5 KiB
Dart
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
|
|
class SpecialTextField extends StatefulWidget {
|
|
const SpecialTextField({
|
|
super.key,
|
|
this.placeholder,
|
|
this.suffix,
|
|
this.controller,
|
|
this.focusNode,
|
|
this.nextFocusNode,
|
|
this.autocorrect,
|
|
this.minLines,
|
|
this.maxLines,
|
|
this.maxLength,
|
|
this.maxLengthEnforcement,
|
|
this.style,
|
|
this.keyboardType,
|
|
this.textInputAction,
|
|
this.textCapitalization,
|
|
this.textAlign,
|
|
this.autofocus,
|
|
this.onChanged,
|
|
this.enabled,
|
|
this.expands,
|
|
this.keyboardAppearance,
|
|
this.textAlignVertical,
|
|
this.inputFormatters,
|
|
});
|
|
|
|
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;
|
|
|
|
final TextInputAction? textInputAction;
|
|
final TextCapitalization? textCapitalization;
|
|
final TextAlign? textAlign;
|
|
final TextAlignVertical? textAlignVertical;
|
|
|
|
final bool? autofocus;
|
|
final ValueChanged<String>? onChanged;
|
|
final bool? enabled;
|
|
final List<TextInputFormatter>? inputFormatters;
|
|
final bool? expands;
|
|
|
|
@override
|
|
_SpecialTextFieldState createState() => _SpecialTextFieldState();
|
|
}
|
|
|
|
class _SpecialTextFieldState extends State<SpecialTextField> {
|
|
List<TextInputFormatter> formatters = [];
|
|
|
|
@override
|
|
void initState() {
|
|
if (widget.inputFormatters == null || formatters.isEmpty) {
|
|
formatters = [FilteringTextInputFormatter.allow(RegExp(r'[^\t]'))];
|
|
} else {
|
|
formatters = widget.inputFormatters!;
|
|
}
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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 ?? true,
|
|
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,
|
|
);
|
|
}
|
|
}
|