Flutter RTL (локализация) не работает для виджета вида сетки - арабский язык - PullRequest
0 голосов
/ 28 августа 2018

Мое приложение флаттера имеет поддержку RTL (локализация) для арабского языка. У меня есть экран во флаттере, в котором есть виджет GridView внутри виджета столбца ... который показывает данные абсолютно нормально для английского языка, но не совсем, когда я переключаюсь на арабский. Ниже приведены скриншоты

когда английский язык:

enter image description here

Когда язык переводится на арабский

enter image description here When language is switched to arabic, it is disturbing the overall look and feel of screen

мой код:

class TransactionSummary extends StatelessWidget {
  final String name;
  final String settlementDate;
  final int transactionCount;
  final String credit;
  final String debit;
  final String discount;

  TransactionSummary(
      {this.name,
      this.settlementDate,
      this.transactionCount,
      this.credit,
      this.debit,
      this.discount});

  @override
  Widget build(BuildContext context) {
    final ThemeData theme = Theme.of(context);
    final TextTheme textTheme = theme.textTheme.copyWith(
        title: theme.textTheme.title.copyWith(
            fontSize: 18.0,
            color: kMaximusBlue900,
            fontWeight: FontWeight.w600),
        subhead: theme.textTheme.subhead
            .copyWith(color: Colors.black, fontSize: 16.0),
        caption: theme.textTheme.caption
            .copyWith(color: theme.hintColor, fontSize: 14.0));

return Column(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: <Widget>[
    Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.only(left: 24.0),
          child: Text(
            '$name',
            style: textTheme.title,
          ),
        ),
        Container(
          child: Padding(
            padding: const EdgeInsets.only(right: 8.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  '$settlementDate',
                  style: TextStyle(fontSize: 12.0),
                ),
                Text(Translations.of(context).settlementDate,
                    style:
                        TextStyle(color: theme.hintColor, fontSize: 10.0)),
              ],
            ),
          ),
        ),
      ],
    ),
    Padding(
      padding: const EdgeInsets.all(8.0),
      child: Divider(
        color: Colors.grey,
        height: 2.0,
      ),
    ),
    IgnorePointer(
        child: GridView.count(
      padding: EdgeInsets.only(left: 24.0),
      shrinkWrap: true,
      crossAxisCount: 2,
      childAspectRatio: 2.5,
      mainAxisSpacing: 10.0,
      crossAxisSpacing: 50.0,
      children: [
        buildGridViewCell(transactionCount.toString(),
            Translations.of(context).transactions, textTheme),
        buildGridViewCell(
            discount, Translations.of(context).discount, textTheme),
        buildGridViewCell(
            debit, Translations.of(context).debit, textTheme),
        buildGridViewCell(
            credit, Translations.of(context).credit, textTheme),
      ],
    ))
  ],
);


 }

  Widget buildGridViewCell(String data, String caption, TextTheme textTheme) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Text(
          data,
          style: textTheme.subhead,
        ),
        Text(caption, style: textTheme.caption),
      ],
    );
  }
}

Что-то не так в коде GridView?

Ответы [ 2 ]

0 голосов
/ 30 августа 2018

Вы должны использовать класс EdgeInsetsDirectional

Например, используйте код

  EdgeInsetsDirectional.only(end: 8.0)

вместо

  EdgeInsets.only(right: 8.0)

кстати, вы также должны использовать AlignmentDirectional вместо Alignment

0 голосов
/ 29 августа 2018

Это исправлено также путем предоставления эквивалентного отступа справа

`

return Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: <Widget>[
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(left: 24.0,right: 24.0),
            child: Text(
              '$name',
              style: textTheme.title,
            ),
          ),
          Container(
            child: Padding(
              padding: const EdgeInsets.only(right: 8.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    '$settlementDate',
                    style: TextStyle(fontSize: 12.0),
                  ),
                  Text(Translations.of(context).settlementDate,
                      style:
                          TextStyle(color: theme.hintColor, fontSize: 10.0)),
                ],
              ),
            ),
          ),
        ],
      ),
      Padding(
        padding: const EdgeInsets.all(8.0),
        child: Divider(
          color: Colors.grey,
          height: 2.0,
        ),
      ),
      IgnorePointer(
          child: GridView.count(
        padding: EdgeInsets.only(left: 24.0,right: 24.0),
        shrinkWrap: true,
        crossAxisCount: 2,
        childAspectRatio: 2.5,
        children: [
          buildGridViewCell(transactionCount.toString(),
              Translations.of(context).transactions, textTheme),
          buildGridViewCell(
              discount, Translations.of(context).discount, textTheme),
          buildGridViewCell(
              debit, Translations.of(context).debit, textTheme),
          buildGridViewCell(
              credit, Translations.of(context).credit, textTheme),
        ],
      ))
    ],
  );
}

Widget buildGridViewCell(String data, String caption, TextTheme textTheme) {
  return Wrap(
    direction: Axis.vertical,
    children: <Widget>[
      Text(
        data,
        style: textTheme.subhead,
      ),
      Text(caption, style: textTheme.caption),
    ],
  );
}
}

`

также мне пришлось удалить mainAxisSpacing: 10.0, crossAxisSpacing: 50,0,

...