相关的引起错误的小部件是Scaffold

时间:2020-10-16 12:28:18

标签: android ios flutter dart cross-platform

class _NavBarState extends State<NavBar> {
  int _currentIndex = 0;
  final List<Widget> _children = [
    HomeScreen(),
    SignUpScreen(),
    ForgetPassword(),
    LoginScreen(),
  ];

  void onTappedBar(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _children[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        onTap: onTappedBar,
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(
              icon: Icon(
                Icons.search,
              ),
              label: 'Search',
              backgroundColor: Colors.black),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.favorite,
              ),
              label: 'Favorites',
              backgroundColor: Colors.black),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.notifications,
              ),
              label: 'Notifications',
              backgroundColor: Colors.black),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.more,
              ),
              label: 'More',
              backgroundColor: Colors.black),
        ],
        selectedItemColor: Color(0xffFFDA3A),
      ),
    );
  }
}

'package:flutter / src / widgets / framework.dart':失败的断言:4345行pos 14:'owner._debugCurrentBuildTarget == this':不正确。 相关的引起错误的小部件是 脚手架

为什么会出现此错误?

link to the error

1 个答案:

答案 0 :(得分:0)

我认为错误来自HomeScreen小部件。错误消息显示lib/.../home/home.dart

我确实没有发现当前代码片段有问题,实际上您可以检查运行here的代码。该答案的末尾提供了源代码。

我仅重命名了_NavBarState类,并且children小部件实例被模拟。查看评论以指导您。

可能使用应用程序MainScreen和HomeScreen类的完整代码,可以提供更准确的答案。

Containers