[英]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.