简体   繁体   English

flutter项目中RTL支持的最佳实践

[英]best practices of RTL support in the flutter project

I am working on one existing Flutter project.我正在研究一个现有的 Flutter 项目。 In which, We want to add RTL support in the flutter project, I went through some of the stuff on the internet but was unable to figure out the best possible way or best practice to do that.其中,我们想在 flutter 项目中添加 RTL 支持,我浏览了互联网上的一些东西,但无法找出最好的方法或最佳实践来做到这一点。 Please share your thoughts.请分享您的想法。

Well Flutter takes care of that. Flutter 负责解决这个问题。 However, some widgets may not look nice or wouldn't be as designed to be so you could manipulate it when its RTL and keep it as is if it's LTR.但是,某些小部件可能看起来不太好或设计得不那么好,因此您可以在其 RTL 时对其进行操作并保持其原样,就好像它是 LTR 一样。

What I did in similar scenario is:我在类似场景中所做的是:

First create a builder class like so首先像这样创建一个构建器类

class DirectionBuilder extends StatelessWidget {  
final Widget Function(bool) builder;

const DirectionBuilder({Key? key, required this.builder})
    : assert(builder != null),
      super(key: key);
@override
Widget build(BuildContext context) =>
  builder(Directionality.of(context) == TextDirection.ltr);
}

The boolean value will be true if device alignment is RTL如果设备对齐为 RTL,则布尔值将为真

Then you can use it like so:然后你可以像这样使用它:

DirectionBuilder(
   builder: (bool isLTR) => Align(
       alignment: isLTR
          ? Alignment.centerRight 
          : Alignment.centerLeft,
                child: Text('bool value is $isLTR')))

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM