方向性(textDirection:TextDirection.rtl,)在颤动中不起作用
Posted
技术标签:
【中文标题】方向性(textDirection:TextDirection.rtl,)在颤动中不起作用【英文标题】:the Directionality( textDirection: TextDirection.rtl, ) doesn't work in flutter 【发布时间】:2021-07-12 20:26:35 【问题描述】:在我的应用程序中,我在前 4 个页面中使用 rtl 方向,它工作正常,但在添加 BottomNavigationBar 及其小部件后,小部件不会响应任何方向或任何列效果
这是我的底部导航栏代码
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
child: Container(
// height: MediaQuery.of(context).size.height * .1,
child: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
selectedItemColor: Colors.orange,
selectedFontSize: 0,
unselectedFontSize: 0,
showSelectedLabels: false,
showUnselectedLabels: false,
//iconSize: 22,
elevation: 0,
backgroundColor: Colors.transparent,
// selectedIconTheme: IconThemeData(
// color: Colors.orange,
// ),
// unselectedItemColor: Colors.grey,
currentIndex: widget.currentTab,
onTap: (int i)
print(i);
this._selectTab(i);
,
// this will be set when a new tab is tapped
items: [
BottomNavigationBarItem(
icon: Container(
margin: EdgeInsets.all(0),
padding: EdgeInsets.only(left: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
children: [
new Image.asset(
"assets/images/home.png",
height: 20,
width: 20,
fit: BoxFit.contain,
color: Colors.grey,
),
Text(
'الرئيسية',
style: TextStyle(color: Colors.grey, fontSize: 10),
)
],
),
),
activeIcon: Container(
margin: EdgeInsets.all(0),
padding: EdgeInsets.only(left: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
children: [
new Image.asset(
"assets/images/home.png",
height: 20,
width: 20,
fit: BoxFit.contain,
color: Color.fromRGBO(255, 187, 17, 1),
),
Text(
'الرئيسية',
style: TextStyle(
color: Color.fromRGBO(255, 187, 17, 1),
fontSize: 12),
)
],
),
),
label: '',
),
],
),
),
),
第一页的代码
Directionality(
textDirection: TextDirection.rtl,
child: Scaffold(
//backgroundColor: Colors.white,
//resizeToAvoidBottomInset: false,
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
// mainAxisAlignment: MainAxisAlignment.end,
// crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: Column(
children: [
SizedBox(
height: MediaQuery.of(context).size.height * .05,
),
Text(
", أهلا محمود",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
Text(
"اختر الخدمة المناسبة لك",
style: TextStyle(
fontSize: 14, color: Color.fromRGBO(138, 138, 138, 1)),
),
SizedBox(
height: MediaQuery.of(context).size.height * .05,
),
],
))
],
),
),
),
);
所以任何人都知道这个问题!!!
【问题讨论】:
【参考方案1】:尝试使用flutter_localizations
将此添加到您的 pubspec:
flutter_localizations:
sdk: flutter
然后在您的主文件中将它们添加到您的 MaterialApp 小部件中
localizationsDelegates: [
GlobalCupertinoLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
Locale("ar", "YE"), // OR Locale('ar', 'AE') OR Other RTL locales
],
【讨论】:
【参考方案2】:清理并重新安装应用程序后,小部件可以正常工作,谢谢
【讨论】:
以上是关于方向性(textDirection:TextDirection.rtl,)在颤动中不起作用的主要内容,如果未能解决你的问题,请参考以下文章