Flutter 颤振文本和文本字段小部件中的自动文本方向(基于输入的文本)

Flutter 颤振文本和文本字段小部件中的自动文本方向(基于输入的文本),flutter,Flutter,我正在用flatter(ar/en)制作一个多语言应用程序,所以我想用这些语言显示我的内容,我的问题是文本方向是基于ui语言的,如果ar应该是rtl,我想根据内容动态更改方向,其他方面是ltr 我目前的看法 预期效果 class ArticleCard扩展了无状态小部件{ 常数卡片({ 关键点, @本条规定, @需要此。i作者, @需要此.onDelete, @需要此.onEdit, this.allowComments=true, }):super(key:key); 最后条款示范条款;

我正在用flatter(ar/en)制作一个多语言应用程序,所以我想用这些语言显示我的内容,我的问题是文本方向是基于ui语言的,如果ar应该是rtl,我想根据内容动态更改方向,其他方面是ltr

我目前的看法

预期效果

class ArticleCard扩展了无状态小部件{
常数卡片({
关键点,
@本条规定,
@需要此。i作者,
@需要此.onDelete,
@需要此.onEdit,
this.allowComments=true,
}):super(key:key);
最后条款示范条款;
最后一本书的作者;
最终布尔允许值;
最终删除;
最终作废;
@凌驾
小部件构建(构建上下文){
回程卡(
页边距:仅限边集(底部:10),
子:列(
儿童:[
墨水池(
onTap:(){
ExtendedNavigator.ofRouter().PushName(
文章,,
论点:ArticleScreenArguments(文章:article),
);
},
子:列(
儿童:[
列表砖(
领先:CircleAvatar(
背景图片:
CachedNetworkImageProvider(article.owner.avatar),
),
标题:文本(文章标题),
字幕:文本(
article.owner.name,
textScaleFactor:.75,
),
尾随:文本(
“${DateFormat('d,MMMM y h:mm a','ar').format(article.createdAt)}”,
textScaleFactor:.7,
),
),
大小盒子(
宽度:MediaQuery.of(context).size.width,
孩子:填充(
填充:边缘组。对称(水平:8),
子:文本(
第1条内容,
textAlign:textAlign.start,
),
),
),
],
),
),
尺寸箱(高度:10),
划船(
mainAxisAlignment:mainAxisAlignment.spaceAround,
儿童:[
收藏夹按钮(
isFavorite:article.isFavorite,
计数:article.favoriteCount,
类型:FavoriteType.article,
targetId:article.id,
),
_建筑标签电子(
图标:图标(Icons.message),
标签:“${article.commentsCount}”,
),
_建筑标签电子(
图标:图标(Icons.share),
标签:“${article.shares}”,
),
_建筑标签电子(
图标:图标(图标。去掉红色的眼睛),
标签:“${article.views}”,
),
],
),
尺寸箱(高度:10),
容器(
身高:1.5,
颜色:颜色。黑色,
),
如果(作者)
_buildAuthorRow(),
//分隔符(),
如果(允许项)[
尺寸箱(高度:10),
_buildCommentsSection(上下文),
]
],
),
);
}
行_buildauthorow(){
返回行(
儿童:[
扩大(
孩子:InkWell(
onTap:onEdit,
子:容器(
身高:50,
对齐:对齐.center,
子:文本(
'تعديل',
样式:TextStyle(
颜色:appTheme.accentColor,
fontWeight:fontWeight.bold,
),
),
),
),
),
容器(
宽度:1.5,
身高:50,
颜色:颜色。黑色,
),
扩大(
孩子:InkWell(
onTap:onDelete,
子:容器(
身高:50,
对齐:对齐.center,
子:文本(
'حذف',
样式:TextStyle(
颜色:appTheme.errorColor,
fontWeight:fontWeight.bold,
),
),
),
),
),
],
);
}
行_buildLabeledIcon({小部件图标,字符串标签}){
返回行(
crossAxisAlignment:crossAxisAlignment.end,
儿童:[
偶像
尺寸箱(宽度:5),
正文(
标签,
textScaleFactor:.75,
),
],
);
}
小部件_buildCommentsSection(BuildContext上下文){
返回列(
儿童:[
if(article.comments.isNotEmpty)
CommentTile(注释:article.comments.first),
_buildCommentTextInput(上下文),
],
);
}
小部件_buildCommentTextInput(BuildContext上下文){
返回填充(
填充:常数边集全部(8.0),
孩子:排(
儿童:[
图标按钮(
图标:图标(FontAwesomeIcons.paperPlane),
按下:(){},
),
灵活的(
孩子:TextField(
装饰:输入装饰(
hintText:‘كتبتتعليق’,
是的,
fillColor:Color(0xFFEFEFEF),
边框:大纲输入边框(
borderRadius:borderRadius.all(半径.圆形(50)),
borderSide:borderSide.none,
),
contentPadding:EdgeInsets.all(12),
),
提交:({}),
onTap:(){},
),
),
],
),
);
}
}
类CommentTile扩展了无状态小部件{
最终评论模型评论;
const CommentTile({Key-Key,this.comment}):super(Key:Key);
@凌驾
class ArticleCard extends StatelessWidget {
  const ArticleCard({
    Key key,
    @required this.article,
    @required this.isAuthor,
    @required this.onDelete,
    @required this.onEdit,
    this.allowComments = true,
  }) : super(key: key);
  final ArticleModel article;
  final bool isAuthor;
  final bool allowComments;
  final VoidCallback onDelete;
  final VoidCallback onEdit;

  @override
  Widget build(BuildContext context) {
    return Card(
      margin: EdgeInsets.only(bottom: 10),
      child: Column(
        children: <Widget>[
          InkWell(
            onTap: () {
              ExtendedNavigator.ofRouter<Router>().pushNamed(
                Routes.article,
                arguments: ArticleScreenArguments(article: article),
              );
            },
            child: Column(
              children: <Widget>[
                ListTile(
                  leading: CircleAvatar(
                    backgroundImage:
                        CachedNetworkImageProvider(article.owner.avatar),
                  ),
                  title: Text(article.title),
                  subtitle: Text(
                    article.owner.name,
                    textScaleFactor: .75,
                  ),
                  trailing: Text(
                    '${DateFormat('d, MMMM y  h:mm a', 'ar').format(article.createdAt)}',
                    textScaleFactor: .7,
                  ),
                ),
                SizedBox(
                  width: MediaQuery.of(context).size.width,
                  child: Padding(
                    padding: EdgeInsets.symmetric(horizontal: 8),
                    child: Text(
                      article.content,
                      textAlign: TextAlign.start,
                    ),
                  ),
                ),
              ],
            ),
          ),
          SizedBox(height: 10),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
              FavoriteButton(
                isFavorite: article.isFavorite,
                count: article.favoriteCount,
                type: FavoriteType.article,
                targetId: article.id,
              ),
              _buildLabeledIcon(
                icon: Icon(Icons.message),
                label: '${article.commentsCount}',
              ),
              _buildLabeledIcon(
                icon: Icon(Icons.share),
                label: '${article.shares}',
              ),
              _buildLabeledIcon(
                icon: Icon(Icons.remove_red_eye),
                label: '${article.views}',
              ),
            ],
          ),
          SizedBox(height: 10),
          Container(
            height: 1.5,
            color: Colors.black12,
          ),
          if (isAuthor)
            _buildAuthorRow(),
          // Divider(),
          if (allowComments) ...[
            SizedBox(height: 10),
            _buildCommentsSection(context),
          ]
        ],
      ),
    );
  }

  Row _buildAuthorRow() {
    return Row(
      children: <Widget>[
        Expanded(
          child: InkWell(
            onTap: onEdit,
            child: Container(
              height: 50,
              alignment: Alignment.center,
              child: Text(
                'تعديل',
                style: TextStyle(
                  color: appTheme.accentColor,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
          ),
        ),
        Container(
          width: 1.5,
          height: 50,
          color: Colors.black12,
        ),
        Expanded(
          child: InkWell(
            onTap: onDelete,
            child: Container(
              height: 50,
              alignment: Alignment.center,
              child: Text(
                'حذف',
                style: TextStyle(
                  color: appTheme.errorColor,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }

  Row _buildLabeledIcon({Widget icon, String label}) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.end,
      children: <Widget>[
        icon,
        SizedBox(width: 5),
        Text(
          label,
          textScaleFactor: .75,
        ),
      ],
    );
  }

  Widget _buildCommentsSection(BuildContext context) {
    return Column(
      children: [
        if (article.comments.isNotEmpty)
          CommentTile(comment: article.comments.first),
        _buildCommentTextInput(context),
      ],
    );
  }

  Widget _buildCommentTextInput(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Row(
        children: <Widget>[
          IconButton(
            icon: Icon(FontAwesomeIcons.paperPlane),
            onPressed: () {},
          ),
          Flexible(
            child: TextField(
              decoration: InputDecoration(
                hintText: 'كتابة تعليق',
                filled: true,
                fillColor: Color(0xFFEFEFEF),
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.all(Radius.circular(50)),
                  borderSide: BorderSide.none,
                ),
                contentPadding: EdgeInsets.all(12),
              ),
              onSubmitted: (_) {},
              onTap: () {},
            ),
          ),
        ],
      ),
    );
  }
}

class CommentTile extends StatelessWidget {
  final CommentModel comment;

  const CommentTile({Key key, this.comment}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        ListTile(
          leading: CircleAvatar(
            backgroundImage: CachedNetworkImageProvider(comment.user.avatar),
          ),
          title: Text(comment.user.name),
          subtitle: Text(
            DateFormat.yMEd().format(comment.createdAt),
            textScaleFactor: .75,
          ),
        ),
        SizedBox(
          width: MediaQuery.of(context).size.width,
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 8),
            child: Text(
              comment.text,
              textAlign: TextAlign.end,
            ),
          ),
        ),
      ],
    );
  }
}
Text("$content", textAlign: lang=='ar'?TextAlign.right:TextAlign.left )