我用了一个多星期的Flitter,想创建一个阿拉伯语(从右到左)应用程序.
我读的是Internationalizing Flutter Apps,但没有提到如何设置布局方向.
那么,如何在Flutter 中显示从右到左(RTL)的布局呢?
我用了一个多星期的Flitter,想创建一个阿拉伯语(从右到左)应用程序.
我读的是Internationalizing Flutter Apps,但没有提到如何设置布局方向.
那么,如何在Flutter 中显示从右到左(RTL)的布局呢?
您有两个 Select :
1. force a locale ( and direction ) on all devices个
--100与本地化
将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,
.
.
.
);
--100无本地化
MaterialApp(
.
.
.
builder: (context, child) {
return Directionality(
textDirection: TextDirection.rtl,
child: child,
);
},
.
.
.
);
2. set layout direction according to device locale ( if user phone locale is a 100 language and exist in 101, your app run in 100 mode, otherwise your app is 103 )
将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("en", "US"),
Locale("fa", "IR"), // OR Locale('ar', 'AE') OR Other RTL locales
],
.
.
.
);
Flutter 中的note:RTL语言包括:
[
'ar', // Arabic
'fa', // Farsi
'he', // Hebrew
'ps', // Pashto
'ur', // Urdu
];