Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get current layout direction in Flutter?

I'm working on an application that should also work with RTL layout direction (Arabic and Hebrew languages).

I also need to perform some changes in the layout in case the layout direction is RTL.

How can I determine what is the current layout direction of the app?

like image 955
Emil Adz Avatar asked Dec 13 '22 09:12

Emil Adz


1 Answers

You can get the current direction using Directionality.of.

final TextDirection currentDirection = Directionality.of(context);
final bool isRTL = currentDirection == TextDirection.rtl;

which determines `the direction of the selctedlanguage but if need you to set it manually, probably this can work for you.

Widget build(BuildContext context) {
  return MaterialApp(
    debugShowCheckedModeBanner: false,
    theme: ThemeData(),
    home: Directionality(
      textDirection: TextDirection.rtl,
      child: Home(),
    ),
  );
}
like image 168
isacjunior Avatar answered Feb 01 '23 06:02

isacjunior