I start an App in Flutter with GetX . I want to Create a rtl App and I used flutter_localizations package as this post .
This is my main() code
void main() => runApp(
GetMaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
Locale('fa', 'IR'),
],
locale: Locale('fa', 'IR'),
home: HomeScreen(),
),
);
and this is my HomeScreen Code
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Text(
"Some Text",
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
);
and as you see in this picture , debug banner has gone to left side but text steel is in left
Use textDirection
property and set it to TextDirection.rtl
Local TextDirection
Text(
"Some Text",
textDirection: TextDirection.rtl,
),
Global TextDirection
MaterialApp(
home: Directionality(
textDirection: TextDirection.rtl,
child: UserDetailsScreen(),
),
),
Complete Example:
void main() => runApp(
MaterialApp(
home: Directionality(
// add this
textDirection: TextDirection.rtl,
child: HomeScreen()),
),
);
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Text(
"ہائے میں فلاں دنیا ہوں !!! امید ہے کہ آپ اچھا کر رہے ہیں۔ کوڈنگ مبارک ہو :)",
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
);
}
}
Output:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With