TF-1884 Support RTL mode for TextFormField
(cherry picked from commit 7c12f65a037bb5a1b6cef91938af1ec1dac20a9b)
This commit is contained in:
@@ -46,6 +46,7 @@ export 'utils/platform_info.dart';
|
||||
// Views
|
||||
export 'presentation/views/text/slogan_builder.dart';
|
||||
export 'presentation/views/text/text_field_builder.dart';
|
||||
export 'presentation/views/text/text_form_field_builder.dart';
|
||||
export 'presentation/views/text/input_decoration_builder.dart';
|
||||
export 'presentation/views/text/rich_text_builder.dart';
|
||||
export 'presentation/views/responsive/responsive_widget.dart';
|
||||
|
||||
@@ -102,10 +102,10 @@ class EditTextDialogBuilder {
|
||||
textAlign: TextAlign.center),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 20),
|
||||
child: TextFormField(
|
||||
child: TextFormFieldBuilder(
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
onChanged: (value) => _onTextChanged(value, setState),
|
||||
autofocus: true,
|
||||
onTextChange: (value) => _onTextChanged(value, setState),
|
||||
autoFocus: true,
|
||||
controller: _textController,
|
||||
decoration: InputDecoration(
|
||||
errorText: _error,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/presentation/views/text/text_form_field_builder.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
@@ -126,10 +127,10 @@ class EditTextModalSheetBuilder {
|
||||
textAlign: TextAlign.center),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 20),
|
||||
child: TextFormField(
|
||||
child: TextFormFieldBuilder(
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
onChanged: (value) => _onTextChanged(value, setState),
|
||||
autofocus: true,
|
||||
onTextChange: (value) => _onTextChanged(value, setState),
|
||||
autoFocus: true,
|
||||
controller: _textController,
|
||||
decoration: InputDecoration(
|
||||
errorText: _error,
|
||||
|
||||
@@ -7,7 +7,7 @@ abstract class InputDecorationBuilder {
|
||||
TextStyle? labelStyle;
|
||||
String? hintText;
|
||||
TextStyle? hintStyle;
|
||||
EdgeInsets? contentPadding;
|
||||
EdgeInsetsGeometry? contentPadding;
|
||||
OutlineInputBorder? enabledBorder;
|
||||
OutlineInputBorder? errorBorder;
|
||||
OutlineInputBorder? focusBorder;
|
||||
@@ -43,7 +43,7 @@ abstract class InputDecorationBuilder {
|
||||
hintStyle = newHintStyle;
|
||||
}
|
||||
|
||||
void setContentPadding(EdgeInsets? newContentPadding) {
|
||||
void setContentPadding(EdgeInsetsGeometry? newContentPadding) {
|
||||
contentPadding = newContentPadding;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/utils/direction_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TextFormFieldBuilder extends StatefulWidget {
|
||||
|
||||
final ValueChanged<String>? onTextChange;
|
||||
final ValueChanged<String>? onTextSubmitted;
|
||||
final VoidCallback? onTap;
|
||||
final TextStyle? textStyle;
|
||||
final TextInputAction? textInputAction;
|
||||
final InputDecoration? decoration;
|
||||
final bool obscureText;
|
||||
final int? maxLines;
|
||||
final int? minLines;
|
||||
final TextEditingController? controller;
|
||||
final TextInputType? keyboardType;
|
||||
final Color cursorColor;
|
||||
final bool autoFocus;
|
||||
final FocusNode? focusNode;
|
||||
final String? fromValue;
|
||||
final Brightness? keyboardAppearance;
|
||||
final bool autocorrect;
|
||||
final TextDirection textDirection;
|
||||
final bool readOnly;
|
||||
final MouseCursor? mouseCursor;
|
||||
final List<String>? autofillHints;
|
||||
|
||||
const TextFormFieldBuilder({
|
||||
super.key,
|
||||
this.cursorColor = AppColor.primaryColor,
|
||||
this.autocorrect = false,
|
||||
this.obscureText = false,
|
||||
this.autoFocus = false,
|
||||
this.readOnly = false,
|
||||
this.textStyle = const TextStyle(color: AppColor.textFieldTextColor),
|
||||
this.textDirection = TextDirection.ltr,
|
||||
this.textInputAction,
|
||||
this.decoration,
|
||||
this.maxLines = 1,
|
||||
this.minLines,
|
||||
this.controller,
|
||||
this.keyboardType,
|
||||
this.focusNode,
|
||||
this.fromValue,
|
||||
this.keyboardAppearance,
|
||||
this.mouseCursor,
|
||||
this.autofillHints,
|
||||
this.onTap,
|
||||
this.onTextChange,
|
||||
this.onTextSubmitted,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TextFormFieldBuilder> createState() => _TextFieldFormBuilderState();
|
||||
}
|
||||
|
||||
class _TextFieldFormBuilderState extends State<TextFormFieldBuilder> {
|
||||
|
||||
late TextEditingController _controller;
|
||||
late TextDirection _textDirection;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
if (widget.fromValue != null) {
|
||||
_controller = TextEditingController.fromValue(TextEditingValue(text: widget.fromValue!));
|
||||
} else if (widget.controller != null) {
|
||||
_controller = widget.controller!;
|
||||
} else {
|
||||
_controller = TextEditingController();
|
||||
}
|
||||
_textDirection = widget.textDirection;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextFormField(
|
||||
key: widget.key,
|
||||
controller: _controller,
|
||||
cursorColor: widget.cursorColor,
|
||||
autocorrect: widget.autocorrect,
|
||||
textInputAction: widget.textInputAction,
|
||||
decoration: widget.decoration,
|
||||
maxLines: widget.maxLines,
|
||||
minLines: widget.minLines,
|
||||
keyboardAppearance: widget.keyboardAppearance,
|
||||
style: widget.textStyle,
|
||||
obscureText: widget.obscureText,
|
||||
keyboardType: widget.keyboardType,
|
||||
autofocus: widget.autoFocus,
|
||||
focusNode: widget.focusNode,
|
||||
textDirection: _textDirection,
|
||||
readOnly: widget.readOnly,
|
||||
mouseCursor: widget.mouseCursor,
|
||||
autofillHints: widget.autofillHints,
|
||||
onChanged: (value) {
|
||||
widget.onTextChange?.call(value);
|
||||
if (value.isNotEmpty) {
|
||||
final directionByText = DirectionUtils.getDirectionByEndsText(value);
|
||||
if (directionByText != _textDirection) {
|
||||
setState(() {
|
||||
_textDirection = directionByText;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
onFieldSubmitted: widget.onTextSubmitted,
|
||||
onTap: widget.onTap,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (widget.fromValue == null && widget.controller == null) {
|
||||
_controller.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user