I need a text field which changes its direction based on user input.
for example, I have a text field that gets the user input but this input can be sometimes an english text with left-to-right direction and sometimes an arabic text with right-to-left direction. I want text field direction to change depended on input language direction
class MyDynamicTextField extends StatelessWidget {
const MyDynamicTextField({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: TextField(),
),
),
);
}
}
How can I mimic WhatsApp chat textfield or chrome textfield text-direction behavior while entering text with different languages and text directions?
e.g: Text Direction of text field changes depended on user input language (in Chrome)
there is a built in function to determine the direction of the text.
import 'package:intl/intl.dart' as intl;
final isRTL = intl.Bidi.detectRtlDirectionality("some text")