首页 > 解决方案 > 如何使浮动操作按钮:快速拨号从右到左(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',
                  ),
            ],
          ),


        ),

      );

    }
  }
}


标签: flutter

解决方案


您可以包装ScaffoldDirectionality检查语言是否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',
        ),
      ],
    ),
    
  ),
);

推荐阅读