计划外的应用栏

Unscheduled appbar

我找不到信息来启动我的应用栏 运行,你能帮帮我吗? 当我单击另一个图标时,屏幕保持不变!

import 'package:flutter/material.dart';
import 'package:curved_navigation_bar/curved_navigation_bar.dart';

void main() => runApp(MaterialApp(home: BottomNavBar()));

class BottomNavBar extends StatefulWidget {
  @override
  _BottomNavBarState createState() => _BottomNavBarState();

}
  bool selected = false;

class _BottomNavBarState extends State<BottomNavBar> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: CurvedNavigationBar(
        index: 0,
        height: 50.0,
        items: <Widget>[
            Icon(Icons.home, size: 30, color: Colors.white),
            Icon(Icons.camera, size: 30, color: Colors.white),
            Icon(Icons.remove_red_eye, size: 30, color: Colors.white),
        ],
        color: selected ? Colors.green.withOpacity(0.90) : Colors.red.withOpacity(0.90),
        buttonBackgroundColor: selected ? Colors.green.withOpacity(0.90) : Colors.red.withOpacity(0.90),
        backgroundColor: Colors.black12,
        animationCurve: Curves.easeInOut,
        animationDuration: Duration(
            milliseconds: 550),
      ),

下次 post 一些代码而不是代码的屏幕截图,但在我看来你缺少 onTap 参数和小部件调用。

尝试根据这个小示例调整您的代码:

class _BottomNavBarState extends State<BottomNavBar> {
  int _page = 0;
  Widget myWidgets = [WidgetA(),WidgetB()];
  GlobalKey _bottomNavigationKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        bottomNavigationBar: CurvedNavigationBar(
          key: _bottomNavigationKey,
          index: 0,
          height: 50.0,
          items: <Widget>[
            Icon(Icons.add, size: 30),
            Icon(Icons.list, size: 30),
          ],
          color: Colors.white,
          buttonBackgroundColor: Colors.white,
          backgroundColor: Colors.blueAccent,
          animationCurve: Curves.easeInOut,
          animationDuration: Duration(milliseconds: 600),
          onTap: (index) {
            setState(() {
              _page = index;
            });
          },
        ),
        body: myWidgets[_page];
  }
}