【问题标题】:Impossible to display BottomNavigationBar in flutter无法在颤动中显示 BottomNavigationBar
【发布时间】:2020-02-17 23:32:23
【问题描述】:

我有一个关于显示底部导航栏的问题。我不明白为什么控制台没有问题。


class MyApp extends StatefulWidget {
  @override

  State<StatefulWidget> createState(){
    return _MyAppState();
  }

}

class _MyAppState extends State<MyApp>  {

  int _selectedPage =0;
  final _pageOptions = [
    HomeScreen(),
    ProfileScreen(),
  ];


  @override
  Widget build(BuildContext context) {
    var localizationDelegate = LocalizedApp.of(context).delegate;
    return  LocalizationProvider(
      state: LocalizationProvider.of(context).state,
      child: MaterialApp(
          localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          localizationDelegate
        ],
        initialRoute: '',
        onGenerateRoute: MyRoutes().getRoute,
        supportedLocales: localizationDelegate.supportedLocales,
//        locale: localizationDelegate.currentLocale,
        theme: ThemeData( primarySwatch: Colors.red),
        home:  Scaffold(
          body: _pageOptions[_selectedPage],
          bottomNavigationBar: BottomNavigationBar(
              type: BottomNavigationBarType.fixed,
              currentIndex: _selectedPage,
              onTap: (int index){
                setState(() {
                  _selectedPage = index;
                });
              },
              items: [
                BottomNavigationBarItem(
                  icon: Icon(Icons.home),
                  title: Text('Home'),
                ),
                BottomNavigationBarItem(
                  icon: Icon(Icons.account_circle),
                  title: Text('Me'),
                ),
              ]
          ),
        ),
      ),
    );

  }
}


我使用 flutter_translate。我知道这是一个非常简单的案例,但我坚持下去。我在谷歌搜索,但没有找到适合我的情况。

谢谢。

已解决

  1. 从我的设备(移动设备)中删除应用程序
  2. 控制台中的 Flutter clean
  3. 在 Android Studio 中启动调试

【问题讨论】:

  • 这里是实现基本底部导航的教程的链接tutorial

标签: flutter dart android-bottomappbar


【解决方案1】:

没有位置代码,可以正常工作,您是否正确设置了 flutter_translate?设置委托和资产如下:

  var delegate = await LocalizationDelegate.create(
        fallbackLocale: 'en_US',
        supportedLocales: ['en_US', 'es', 'fa']);

  runApp(LocalizedApp(delegate, MyApp()));

https://github.com/bratan/flutter_translate/wiki/1.-Installation,-Configuration-&-Usage

在我看来,您在该设置中遗漏了一些东西。

你能详细描述一下到底发生了什么吗?显示一些带有行为的打印或 gif?

再见

【讨论】:

  • 嗨,在我的 main.dart 我把这个信息放在 `````` void main() async { Stetho.initialize(); var delegate = await LocalizationDelegate.create(fallbackLocale: 'en', // 首选项: TranslatePreferences(), supportedLocales: ['fr_DZ', 'ar_DZ', 'en']); runApp(LocalizedApp(delegate, MyApp())); } `````` 事实上,我有 HomePage() 但导航栏没有显示。一开始,当我添加导航栏时,我对路线“路线路线设置生成器......处于_widgetsapp状态”有一些问题。
  • 我已经更改了这段代码的位置 `initialRoute: '', onGenerateRoute: MyRoutes().getRoute,` 我得到了没有导航栏的 HomePage()
  • 是的,你是对的,没有 LocalizationProvider 它可以正常工作。我已经跟着tuto了。
  • 很好,可能是设置中缺少某些东西,或者只是将您的脚手架放在 Builder 小部件下以隔离并创建新的上下文,可以是一个选项...如果对您有帮助,请投票给 awnser ^^ 谢谢!
【解决方案2】:

你可以试试这个,

底部导航栏是脚手架的属性。

bottomNavigationBar: BottomAppBar(
        shape: CircularNotchedRectangle(),
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 48.0, vertical: 3),
          child: new Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              IconButton(
                icon: Icon(Icons.home),
                color: Colors.white,
                onPressed: () {},
              ),
              IconButton(
                icon: Icon(Icons.contact_phone),
                color: Colors.white,
                onPressed: () {},
              ),
            ],
          ),
        ),
        color: Colors.blueGrey,
      );

【讨论】:

  • 你好,我会在几个小时内试试 谢谢
  • 好的,如果可行,请点赞我的回答,谢谢。
猜你喜欢
  • 2021-11-27
  • 2021-03-16
  • 2021-08-12
  • 2018-11-20
  • 1970-01-01
  • 1970-01-01
  • 2019-04-13
  • 2020-01-25
  • 1970-01-01
相关资源
最近更新 更多