TF-1884 Support RTL mode for TypeAheadFormField
(cherry picked from commit e375d87d5d485ecb717b1a8afee2b7bf741fbeac)
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
import 'package:core/utils/direction_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||
|
||||
class TypeAheadFormFieldBuilder<T> extends StatefulWidget {
|
||||
|
||||
final TextDirection textDirection;
|
||||
final Duration debounceDuration;
|
||||
final SuggestionsCallback<T> suggestionsCallback;
|
||||
final ItemBuilder<T> itemBuilder;
|
||||
final SuggestionSelectionCallback<T> onSuggestionSelected;
|
||||
final SuggestionsBoxDecoration suggestionsBoxDecoration;
|
||||
final WidgetBuilder? noItemsFoundBuilder;
|
||||
final bool hideOnEmpty;
|
||||
final bool hideOnError;
|
||||
final bool hideOnLoading;
|
||||
final TextEditingController? controller;
|
||||
final FocusNode? focusNode;
|
||||
final ValueChanged<String>? onTextChange;
|
||||
final ValueChanged<String>? onTextSubmitted;
|
||||
final TextInputAction? textInputAction;
|
||||
final bool autocorrect;
|
||||
final List<String>? autofillHints;
|
||||
final TextInputType keyboardType;
|
||||
final InputDecoration decoration;
|
||||
|
||||
const TypeAheadFormFieldBuilder({
|
||||
super.key,
|
||||
required this.suggestionsCallback,
|
||||
required this.itemBuilder,
|
||||
required this.onSuggestionSelected,
|
||||
this.suggestionsBoxDecoration = const SuggestionsBoxDecoration(),
|
||||
this.textDirection = TextDirection.ltr,
|
||||
this.debounceDuration = const Duration(milliseconds: 300),
|
||||
this.decoration = const InputDecoration(),
|
||||
this.noItemsFoundBuilder,
|
||||
this.hideOnEmpty = false,
|
||||
this.hideOnError = false,
|
||||
this.hideOnLoading = false,
|
||||
this.autocorrect = false,
|
||||
this.keyboardType = TextInputType.text,
|
||||
this.controller,
|
||||
this.focusNode,
|
||||
this.autofillHints,
|
||||
this.textInputAction,
|
||||
this.onTextChange,
|
||||
this.onTextSubmitted,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TypeAheadFormFieldBuilder<T>> createState() => _TypeAheadFormFieldBuilderState<T>();
|
||||
}
|
||||
|
||||
class _TypeAheadFormFieldBuilderState<T> extends State<TypeAheadFormFieldBuilder<T>> {
|
||||
|
||||
late TextEditingController _controller;
|
||||
late TextDirection _textDirection;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_textDirection = widget.textDirection;
|
||||
_controller = widget.controller ?? TextEditingController();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TypeAheadFormField<T>(
|
||||
key: widget.key,
|
||||
textFieldConfiguration: TextFieldConfiguration(
|
||||
controller: widget.controller,
|
||||
textInputAction: widget.textInputAction,
|
||||
autocorrect: widget.autocorrect,
|
||||
autofillHints: widget.autofillHints,
|
||||
keyboardType: widget.keyboardType,
|
||||
decoration: widget.decoration,
|
||||
textDirection: _textDirection,
|
||||
onChanged: (value) {
|
||||
widget.onTextChange?.call(value);
|
||||
if (value.isNotEmpty) {
|
||||
final directionByText = DirectionUtils.getDirectionByEndsText(value);
|
||||
if (directionByText != _textDirection) {
|
||||
setState(() {
|
||||
_textDirection = directionByText;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
onSubmitted: widget.onTextSubmitted
|
||||
),
|
||||
debounceDuration: widget.debounceDuration,
|
||||
suggestionsCallback: widget.suggestionsCallback,
|
||||
itemBuilder: widget.itemBuilder,
|
||||
onSuggestionSelected: widget.onSuggestionSelected,
|
||||
suggestionsBoxDecoration: widget.suggestionsBoxDecoration,
|
||||
noItemsFoundBuilder: widget.noItemsFoundBuilder,
|
||||
hideOnEmpty: widget.hideOnEmpty,
|
||||
hideOnError: widget.hideOnError,
|
||||
hideOnLoading: widget.hideOnLoading,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (widget.controller == null) {
|
||||
_controller.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
+10
-2
@@ -194,10 +194,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_keyboard_visibility
|
||||
sha256: "86b71bbaffa38e885f5c21b1182408b9be6951fd125432cf6652c636254cef2d"
|
||||
sha256: "4983655c26ab5b959252ee204c2fffa4afeb4413cd030455194ec0caa3b8e7cb"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.4.0"
|
||||
version: "5.4.1"
|
||||
flutter_keyboard_visibility_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -259,6 +259,14 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_typeahead:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_typeahead
|
||||
sha256: f31211a8536f87908c3dcbdb88666e2f4d77f5f06c2b3a48eaad5599969ff32d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.6.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
|
||||
@@ -73,6 +73,8 @@ dependencies:
|
||||
# flutter_localizations depends on intl 0.17.0
|
||||
intl: 0.17.0
|
||||
|
||||
flutter_typeahead: 4.6.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
@@ -83,6 +85,10 @@ dev_dependencies:
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
dependency_overrides:
|
||||
|
||||
flutter_keyboard_visibility: 5.4.1
|
||||
|
||||
flutter:
|
||||
# The following line ensures that the Material Icons font is
|
||||
# included with your application, so that you can use the icons in
|
||||
|
||||
Reference in New Issue
Block a user