代码之家  ›  专栏  ›  技术社区  ›  Mohsen Emami

使TextFormField的labelText在flatter中从右向左[复制]

  •  0
  • Mohsen Emami  · 技术社区  · 7 年前

    我使用Flutter已经一个多星期了,我想创建一个阿拉伯语(从右到左)的应用程序。

    我在看书 Internationalizing Flutter Apps ,但没有提到如何设置布局方向。

    那么,如何在flatter中显示从右到左(RTL)的布局呢?

    0 回复  |  直到 8 年前
        1
  •  115
  •   mohammad    5 年前

    您有两个选择:

    1.在所有设备上强制设置区域设置(和方向)

    -- 方法1:

    添加 flutter_localizations 打包到您的 pubspec.yml

    dependencies:
      flutter:
        sdk: flutter
      flutter_localizations:
        sdk: flutter
    

    import 'package:flutter/material.dart';
    import 'package:flutter_localizations/flutter_localizations.dart';
    
    MaterialApp(
      localizationsDelegates: [
        GlobalCupertinoLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: [
        Locale("fa", "IR"), // OR Locale('ar', 'AE') OR Other RTL locales
      ],
      locale: Locale("fa", "IR") // OR Locale('ar', 'AE') OR Other RTL locales,
      .
      .
      .
    );
    

    -- 方法2: 无本地化

    MaterialApp(
      .
      .
      .
      builder: (context, child) {
        return Directionality(
          textDirection: TextDirection.rtl,
          child: child,
        );
      },
      .
      .
      .
    );
    

    2.根据设备区域设置布局方向 (如果用户电话区域设置是 RTL supportedLocales RTL公司 模式,否则你的应用程序 LTR )

    颤振局部化 出版规范yml

    依赖项:
    颤振:
    sdk:颤振
    sdk:颤振
    

    然后

    import 'package:flutter/material.dart';
    import 'package:flutter_localizations/flutter_localizations.dart';
    
    MaterialApp(
      localizationsDelegates: [
        GlobalCupertinoLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: [
        Locale("en", "US"),
        Locale("fa", "IR"), // OR Locale('ar', 'AE') OR Other RTL locales
      ],
      .
      .
      .
    );
    

    :颤振中的rtl语言是:

    [
      'ar', // Arabic
      'fa', // Farsi
      'he', // Hebrew
      'ps', // Pashto
      'ur', // Urdu
    ];
    
        2
  •  28
  •   AbdulMomen عبدالمؤمن    8 年前

    你需要创建一个 Builder 并使用 TextDirection.rtl

    new MaterialApp(
              title: 'Flutter RTL',
              color: Colors.grey,
              builder: (BuildContext context, Widget child) {
                  return new Directionality(
                    textDirection: TextDirection.rtl,
                    child: new Builder(
                      builder: (BuildContext context) {
                        return new MediaQuery(
                          data: MediaQuery.of(context).copyWith(
                                textScaleFactor: 1.0,
                              ),
                          child: child,
                        );
                      },
                    ),
                  );
                },
              .
              .
              .
            );
    
        3
  •  22
  •   CopsOnRoad    6 年前

    最好最短的方法 RTL 整个应用程序的配置 .

    void main() {
      runApp(
        MaterialApp(
          home: Directionality( // add this
            textDirection: TextDirection.rtl, // set this property 
            child: HomePage(),
          ),
        ),
      );
    }
    
        4
  •  4
  •   Son of Stackoverflow Nagendra Nigade    5 年前

    textdirection 属性到 TextDirection.rtl .

    TextField小部件的示例代码,

    TextField(
      textDirection: TextDirection.rtl,
      decoration: InputDecoration(
        labelText: "Enter Pashto Name",
      ),
    ),
    

    文本小部件的示例代码,

        Text(
          "This text is in the other direction!"
          textDirection: TextDirection.rtl,
        ),
    
        5
  •  3
  •   Paresh Mangukiya    5 年前

    SfRangeSelector支持通过设置 textDirection rtl Directionality 小装置。

    SfRangeValues _initialValues = SfRangeValues(4.0, 8.0);
    
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
          home: Scaffold(
              body: Directionality(
                textDirection: TextDirection.rtl,
                child: Center(
                  child: SfRangeSelector(
                    min: 2.0,
                    max: 10.0,
                    interval: 1,
                    showLabels: true,
                    showTicks: true,
                    initialValues: _initialValues,
                    child: Container(
                        color: Colors.pink[200],
                        height: 150,
                     ),
                  ),
                )
             ),
          )
      );
    }
    

    enter image description here

    https://help.syncfusion.com/flutter/range-selector/right-to-left