TabBar 反转标签滚动方向

TabBar invert tabs scroll direction

我有以下简单的 TabBar,顶部的选项卡是可滚动的,对于 RTL 用户,我需要从 从右到左 开始选项卡列表而不是从左到右,因为从左边开始对他们来说看起来是一种不好的行为。

这在 Flutter 中是否可行?

这是我试过的代码:

body: SafeArea(
          child: GestureDetector(
              onTap: () => FocusScope.of(context).unfocus(),
              child: DefaultTabController(
                length: 7,
                initialIndex: 0,
                child: Column(
                  children: const [
                    TabBar(
                      isScrollable: true,
                      labelColor: Color(0xFFE41E26),
                      // labelStyle: Colors.blue,
                      indicatorColor: Colors.green,
                      tabs: [
                        Tab(
                          text: 'Title 1',
                        ),
                        Tab(
                          text: 'Title 2',
                        ),
                        Tab(
                          text: 'Title 3',
                        ),
                        Tab(
                          text: 'Title 4',
                        ),
                        Tab(
                          text: 'Title 5',
                        ),
                        Tab(
                          text: 'Title 6',
                        ),
                        Tab(
                          text: 'Title 7',
                        ),
                      ],
                    ),
                    Expanded(
                      child: TabBarView(
                        children: [
                          Text(
                            'Tab View 1',
                          ),
                          Text(
                            'Tab View 2',
                          ),
                          Text(
                            'Tab View 3',
                          ),
                          Text(
                            'Tab View 4',
                          ),
                          Text(
                            'Tab View 5',
                          ),
                          Text(
                            'Tab View 6',
                          ),
                          Text(
                            'Tab View 7',
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              )))

添加所需的本地化代码后解决:

return const MaterialApp(
  title: 'Localizations Sample App',
  localizationsDelegates: [
    AppLocalizations.delegate, // Add this line
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
  ],
  supportedLocales: [
    Locale('en', ''), // English, no country code
    Locale('ar', ''), // Arabic, no country code
  ],
  home: MyHomePage(),
);

更多信息:https://docs.flutter.dev/development/accessibility-and-localization/internationalization