[FLUTTER]:PersistentBottomNavBar软件包出了点问题 [英] [FLUTTER]: Something is wrong with PersistentBottomNavBar package

查看:149
本文介绍了[FLUTTER]:PersistentBottomNavBar软件包出了点问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前还有另外一个

我的VCode中还有调试控制台错误:

解决方案

问题似乎是您没有将navBarStyle传递给PersistentTabView.有多种NavBarStyle可供选择,并且每个都有其所需的其他值.请参阅' persistent_bottom_nav_bar 文档以获取更多信息.请对您的代码进行以下更改并检查.注意NavBarStyle.style7可能不是您想要的navBarStyle,因此请尝试其他人.

  .....返回脚手架(正文:PersistentTabView(语境,控制器:_tabController,屏幕:_buildScreens(),项目:_navBarsItems(),navBarStyle:NavBarStyle.style7,),.... 

I had an another issue before using 'Provider' package with 'PersistentBottomNavBar' package in my flutter app. So after solving that issue, immediately I got another one. There is my source code. When I run this code my Android emulator crushes. With the following error message: The method 'map' was called on null. Receiver: null. Tried calling: map(Closure: (PersistentBottomNavBarItem) => Flexible)

import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:persistent_bottom_nav_bar/persistent-tab-view.dart';

import './screens/products_list_screen.dart';
import './screens/add_product_screen.dart';
import './screens/profile_screen.dart';

import './providers/products.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);

  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (_) => Products(),
        ),
      ],
      child: MaterialApp(
        title: 'Sample App',
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          primarySwatch: Colors.blueGrey,
          accentColor: Colors.grey[700],
        ),
        home: MyApp(),
      ),
    ),
  );
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  PersistentTabController _tabController =
      PersistentTabController(initialIndex: 0);
  bool _hideNavBar = false;

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _tabController.dispose();
  }

  List<Widget> _buildScreens() {
    return [ProductsListScreen(), AddProductScreen(), ProfileScreen()];
  }

  List<PersistentBottomNavBarItem> _navBarItems() {
    return [
      PersistentBottomNavBarItem(
        icon: Icon(CupertinoIcons.list_bullet),
        title: 'Products',
        activeColor: CupertinoColors.activeBlue,
        inactiveColor: CupertinoColors.systemGrey,
      ),
      PersistentBottomNavBarItem(
        icon: Icon(CupertinoIcons.add),
        title: 'Add',
        activeColor: CupertinoColors.activeBlue,
        inactiveColor: CupertinoColors.systemGrey,
      ),
      PersistentBottomNavBarItem(
        icon: Icon(CupertinoIcons.profile_circled),
        title: 'Profile',
        activeColor: CupertinoColors.activeBlue,
        inactiveColor: CupertinoColors.systemGrey,
      ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return PersistentTabView(
      context,
      controller: _tabController,
      screens: _buildScreens(),
      items: _navBarItems(),
    );
  }
}

There is the error in my Android Emulator:

And the Debug console error in my VCode:

解决方案

The issue seems to be that you are not passing the navBarStyle to PersistentTabView. There are various NavBarStyle's to select and each of them have other values that they require. Please refer to 'persistent_bottom_nav_bar' documentation for more information. Kindly make the following changes to your code and check. Note NavBarStyle.style7 might not be the navBarStyle you were looking for, so please try others.

.....
return Scaffold(
  body: PersistentTabView(
    context,
    controller: _tabController,
    screens: _buildScreens(),
    items: _navBarsItems(),
    navBarStyle: NavBarStyle.style7,
  ),
....

这篇关于[FLUTTER]:PersistentBottomNavBar软件包出了点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆