2

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


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. 在控制台中清理干净
  3. 在 Android Studio 中启动调试
4

2 回答 2

1

你可以试试这个

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

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,
      );

在此处输入图像描述

于 2020-02-18T04:18:52.330 回答
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 图像?

再见

于 2020-02-17T23:53:50.663 回答