Flutter 使用持久导航栏给出空值错误

问题描述 投票:0回答:0

当我为持久性导航栏运行代码时,我不断收到空值错误....但是当我使用底部导航栏时......一切正常......有人可以帮助修复持久性导航栏

请帮帮我....我今天必须提交

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:persistent_bottom_nav_bar_v2/persistent-tab-view.dart';
import 'package:rent_a_room/screens/bottom%20nav/chat.dart';
import 'package:rent_a_room/screens/bottom%20nav/home.dart';
import 'package:rent_a_room/screens/bottom%20nav/profile.dart';
import 'package:rent_a_room/screens/bottom%20nav/settings.dart';
import 'package:rent_a_room/screens/registeration.dart';

class BottomNavBar extends StatelessWidget {
  const BottomNavBar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    PersistentTabController controller;
    controller = PersistentTabController(initialIndex: 0);

    List<Widget> _buildScreens() {
      return [
        HomePage(),
        settings(),
        RegisterPage(),
        chat(),
        profile(),
      ];
    }

    List<PersistentBottomNavBarItem> _navBarsItems() {
      return [
        PersistentBottomNavBarItem(
            icon: ImageIcon(
              AssetImage("assets/images/Splash/homeBtm.png"),
              color: Color(0xff303147),
            ),
            // title: ("Home"),
            activeColorPrimary: Color(0xff878787),
            inactiveColorPrimary: Color(0xff303147)),
        PersistentBottomNavBarItem(
            icon: ImageIcon(
              AssetImage("assets/images/Splash/settingsBtm.png"),
              color: Color(0xff303147),
            ),
            // title: ("Explore"),
            activeColorPrimary: Color(0xff878787),
            inactiveColorPrimary: Color(0xff303147)),
        PersistentBottomNavBarItem(
            icon: ImageIcon(
              AssetImage("assets/images/Splash/addBtm.png"),
              color: Color(0xff303147),
            ),
            activeColorPrimary: Color(0xff878787),
            inactiveColorPrimary: Color(0xff303147)),
        PersistentBottomNavBarItem(
            icon: ImageIcon(
              AssetImage("assets/images/Splash/chatBtm.png"),
              color: Color(0xff303147),
            ),
            // title: ("Inbox"),
            activeColorPrimary: Color(0xff878787),
            inactiveColorPrimary: Color(0xff303147)),
        PersistentBottomNavBarItem(
            icon: ImageIcon(
              AssetImage("assets/images/Splash/profileBtm.png"),
              color: Color(0xff303147),
            ),
            // title: ("Shop"),
            activeColorPrimary: Color(0xff878787),
            inactiveColorPrimary: Color(0xff303147)),
      ];
    }

    return PersistentTabView(
      context,
      controller: controller,
      screens: _buildScreens(),
      items: _navBarsItems(),
      confineInSafeArea: true,
      backgroundColor: Colors.white, // Default is Colors.white.
      handleAndroidBackButtonPress: true, // Default is true.
      resizeToAvoidBottomInset:
          true, // This needs to be true if you want to move up the screen when keyboard appears. Default is true.
      stateManagement: true, // Default is true.
      hideNavigationBarWhenKeyboardShows:
          true, // Recommended to set 'resizeToAvoidBottomInset' as true while using this argument. Default is true.
      decoration: NavBarDecoration(
        boxShadow: [BoxShadow(blurRadius: 20.0)],
        borderRadius: BorderRadius.circular(10.0),
        colorBehindNavBar: Colors.white,
      ),
      popAllScreensOnTapOfSelectedTab: true,
      popActionScreens: PopActionScreensType.all,
      itemAnimationProperties: const ItemAnimationProperties(
        // Navigation Bar's items animation properties.
        duration: Duration(milliseconds: 200),
        curve: Curves.ease,
      ),
      screenTransitionAnimation: const ScreenTransitionAnimation(
        // Screen transition animation on change of selected tab.
        animateTabTransition: true,
        curve: Curves.ease,
        duration: Duration(milliseconds: 200),
      ),
      navBarStyle:
          NavBarStyle.style2, // Choose the nav bar style with this property.
    );
  }
}
[enter image description here](https://i.stack.imgur.com/tZfUw.png)

快帮忙 我必须今晚提交 请快帮忙 我必须今晚提交 请快帮忙 我必须今晚提交 请快帮忙 我必须今晚提交 请快帮忙 我必须今晚提交 请快帮忙 我必须今晚提交 请快帮忙 我必须今晚提交 请快帮忙 我今晚必须提交

flutter flutter-dependencies flutter-animation
© www.soinside.com 2019 - 2024. All rights reserved.