flutter - 如何使浮动操作按钮:快速拨号从右到左(RTL)随着更改应用程序语言而颤动
问题描述
我试图在更改应用程序语言时更改 SpeedDial 图标的位置,但它不起作用。如果在不使用 SpeedDial 的情况下使用普通的 floatingActionButton,则位置更改成功。附图显示了 floatingActionButton 的正常使用:
但是如果使用 SpeedDial,它会是这样的:
我需要更改 SpeedDial 图标的位置,同时将阿拉伯语更改为左侧。
我不知道问题是什么。现在它不响应语言的变化。
return MaterialApp(
localizationsDelegates:EasyLocalization.of(context).delegates,
supportedLocales: EasyLocalization.of(context).supportedLocales,
locale: EasyLocalization.of(context).locale,
)
完整代码:
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
void main() {
runApp(
EasyLocalization(
saveLocale: true,
supportedLocales: [
Locale('en', 'US'),
Locale('ar', 'SA')],
path: 'assets/translations',
fallbackLocale: Locale('en', 'US'),
child: SecondScreens(),
),
);
}
class SecondScreens extends StatefulWidget {
@override
mainStates createState() => new mainStates();
}
class mainStates extends State<SecondScreens> {
@override
Widget build(BuildContext context) {
{
return MaterialApp(
localizationsDelegates:EasyLocalization.of(context).delegates,
supportedLocales: EasyLocalization.of(context).supportedLocales,
locale: EasyLocalization.of(context).locale,
home: Scaffold(
floatingActionButton:
SpeedDial(
animatedIcon: AnimatedIcons.menu_close,
shape: CircleBorder(),
children: [
SpeedDialChild(
child: Icon(Icons.edit),
backgroundColor: const Color(0xFFf6c626),
label: 'Edit',
),
],
),
),
);
}
}
}
解决方案
您可以包装Scaffold
并Directionality
检查语言是否rtl
镜像屏幕,如下所示:
Directionality(
textDirection: (context.locale=='ar')?TextDirection.rtl:TextDirection.ltr,
child: Scaffold(
floatingActionButton:
SpeedDial(
animatedIcon: AnimatedIcons.menu_close,
shape: CircleBorder(),
children: [
SpeedDialChild(
child: Icon(Icons.edit),
backgroundColor: const Color(0xFFf6c626),
label: 'Edit',
),
],
),
),
);
推荐阅读
- python - Altair 用于机场之间连接的交互式图(时间序列)
- c++ - 我如何系统地检查可能的错误以使设置成为可能?
- c++ - 控制到达 C++ 中非 void 函数的结尾
- python - 基于组重采样数据并计算滚动和
- deployment - 如何在公共场所确保 Coral Dev Board 的安全?
- neural-network - 这是计算二维特征图协方差矩阵的正确方法吗?
- javascript - 如何在 AJAX 和 JSON 中显示多个 HTML 实体?
- flutter - Flutter - 如何将 TextStyle 添加到 BottomNavigationBarItem 中的标签?
- python - 从两个不同的变量中找到平均值
- mongodb - Mongodb (code=exited, status=14) 失败但没有任何明确的错误