简体   繁体   English

flutter 如何创建从右到左 (rtl) 应用程序

[英]flutter how to Create right to left (rtl) App

I start an App in Flutter with GetX .我使用 GetX 在 Flutter 中启动了一个应用程序。 I want to Create a rtl App and I used flutter_localizations package as this post .我想创建一个 rtl 应用程序,我使用 flutter_localizations 包作为这篇文章

This is my main() code这是我的 main() 代码

void main() => runApp(
      GetMaterialApp(
        localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
        ],
        supportedLocales: [
          Locale('fa', 'IR'),
        ],
        locale: Locale('fa', 'IR'),
        home: HomeScreen(),
      ),
    );

and this is my HomeScreen Code这是我的主屏幕代码

return Scaffold(
      backgroundColor: Colors.white,
      body: SafeArea(
        child: Text(
          "Some Text",
          style: TextStyle(
            color: Colors.black,
            fontSize: 20,
            fontWeight: FontWeight.bold,
          ),
        ),
      ),
    );

and as you see in this picture , debug banner has gone to left side but text steel is in left正如你在这张图片中看到的,调试横幅已移至左侧,但文本钢在左侧

在此处输入图片说明

The App is already rtl.该应用程序已经是rtl。 it is just that the widget under the safeArea puts the widget to the left with minimum size, I dont' know why this happens try wrapping your text widget with a row or with a container and give it a width then you can see that the default is now to the right not left.只是 safeArea 下的小部件将小部件以最小尺寸放在左侧,我不知道为什么会发生这种情况尝试用一行或一个容器包裹你的文本小部件并给它一个宽度然后你可以看到默认的现在是在右边而不是左边。

在此处输入图片说明

your app is rtl correctly, your problem is current body widget, test this as body widget :您的应用程序正确无误,您的问题是当前的正文小部件,将其作为正文小部件进行测试:

body: SafeArea(
  child: Row(
    mainAxisSize: MainAxisSize.max,
    children: [
      Text("Some Text"),
    ],
  ),
),

Use textDirection property and set it to TextDirection.rtl使用textDirection属性并将其设置为TextDirection.rtl

Local TextDirection本地文本方向

Text(
  "Some Text",
  textDirection: TextDirection.rtl,
),

Global TextDirection全局文本方向

MaterialApp(
      home: Directionality(
        textDirection: TextDirection.rtl, 
        child: UserDetailsScreen(),
      ),
    ),

Complete Example:完整示例:

void main() => runApp(
      MaterialApp(
        home: Directionality(
            // add this
            textDirection: TextDirection.rtl,
            child: HomeScreen()),
      ),
    );

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: SafeArea(
        child: Text(
          "ہائے میں فلاں دنیا ہوں !!! امید ہے کہ آپ اچھا کر رہے ہیں۔ کوڈنگ مبارک ہو :)",
          style: TextStyle(
            color: Colors.black,
            fontSize: 20,
            fontWeight: FontWeight.bold,
          ),
        ),
      ),
    );
  }
}

Output:输出:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 颤动中的从右到左(RTL) - right-to-left (RTL) in flutter 如何在 flutter 中显示文本,以便 RTL 语言右对齐,LTR 左对齐? - How to display text in flutter so that RTL language is aligned right and LTR is aligned left? 如何使浮动操作按钮:快速拨号从右到左(RTL)随着更改应用程序语言而颤动 - How to make floatingActionButton: SpeedDial right-to-left (RTL) in flutter with changing the application language 如何创建一个小部件可以在颤动中向上/向下/向左/向右滑动? - How to create a widget can swipe up/down/left/right in flutter? 如何在 Flutter 中创建从左到右或从上到下的覆盖飞溅 animation - How to create the left to right or top to bottom overlay splattering animation in Flutter 如何在 flutter 中创建左右 slider 的动画堆叠卡? - How to create animated stacked card with left and right slider in flutter? 基于flutter在应用程序中从左到右滚动 - Left to right scrolling in app based on flutter Flutter从右到左的rtl包装的多行文字隐藏第一个字母 - Flutter Right-to-Left rtl wrapped multiline text hide first letter 如何在应用程序中心创建具有左/右页边距的列? - How to create Column in Center of App with Left/Right margins? 如何在 Flutter gridview 中从右到左填充数据 - How to fill data right to left in Flutter gridview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM