【问题标题】:Failed assertion: line 190 pos 15: 'items!= null': is not true断言失败:第 190 行 pos 15:'items!= null':不正确
【发布时间】:2019-11-16 11:19:41
【问题描述】:

我正在尝试在颤振中构建一个底部弯曲导航栏,我尝试了很多示例,但对我没有任何帮助。即使我使用了与他们官方网站上相同的示例,但什么也没发生。 我正在尝试在颤振中构建一个底部弯曲的导航栏,我尝试了很多示例,但对我没有任何帮助。即使我使用了与他们官方网站上相同的示例,但什么也没发生。

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();
}

class _BottomNavBarState extends State<BottomNavBar> {
  int _page = 0;
  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),
            Icon(Icons.compare_arrows, size: 30),
            Icon(Icons.call_split, size: 30),
            Icon(Icons.perm_identity, size: 30),
          ],
          color: Colors.white,
          buttonBackgroundColor: Colors.white,
          backgroundColor: Colors.blueAccent,
          animationCurve: Curves.easeInOut,
          animationDuration: Duration(milliseconds: 600),
          onTap: (index) {
            setState(() {
              _page = index;
            });
          },
        ),
        body: Container(
          color: Colors.blueAccent,
          child: Center(
            child: Column(
              children: <Widget>[
                Text(_page.toString(), textScaleFactor: 10.0),
                RaisedButton(
                  child: Text('Go To Page of index 1'),
                  onPressed: () {
                    final CurvedNavigationBarState navBarState =
                        _bottomNavigationKey.currentState;
                    navBarState.setPage(1);
                  },
                )
              ],
            ),
          ),
        ));
  }
}

【问题讨论】:

  • 对我来说一切正常。我在 iOS 虚拟设备上试用了 Flutter 1.9.1+hotfix.6 • 通道稳定。你有什么配置?
  • assert(items != null), assert(items.length >= 2), assert( items.every((BottomNavigationBarItem item) => item.title != null) == true, '每个项目都必须有一个非空标题',
  • 这是个例外
  • 您使用哪个版本的库?库版本 0.3.1 中没有 assert(items.length &gt;= 2),因此请尝试使用 flutter pub get 更新您的库,并让我知道发生错误的文件是什么。
  • 我正在使用 ^0.3.1

标签: android ios flutter dart navigation


【解决方案1】:

我使用了curved_navigation_bar plugin 当前文档中的相同示例,它运行良好。我使用的是 1.0.1 版本,输出如下:

【讨论】:

    猜你喜欢
    • 2021-05-12
    • 2019-05-24
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 2020-12-14
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    相关资源
    最近更新 更多