flutterlayoutflutter-layoutdirection

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?


Solution

  • 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(),
        ),
      );
    }