1

我无法找到让我的 appbar 启动和运行的信息,您能帮帮我吗?当我单击另一个图标时,屏幕保持不变! F

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

1 回答 1

0

下次发布一些代码而不是代码的屏幕截图,但在我看来,您缺少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];
  }
}
于 2020-05-16T21:33:41.623 回答