【问题标题】:Custom buttom navigationBar flutter自定义底部导航栏颤动
【发布时间】:2021-02-07 17:32:50
【问题描述】:

https://fluttercore.com/flutter-configurable-navigation-bar/ 我正在尝试将此导航栏用作单独的类,这是我的类代码,它在图标之间移动,但它不会更改前的​​页面:当我按下配置文件图标时,它会更改它的颜色,并且该图标似乎已按下但页面没有改变

 import 'package:flutter/material.dart';
    import 'main.dart';
    import 'package:ff_navigation_bar/ff_navigation_bar.dart';
    import 'elderlyProfile.dart';
    import 'addGelu.dart';
    import 'HomepageElderly.dart';
    import 'Chat.dart';
    
    class addNavigationBarPage extends StatefulWidget {
      @override
      _addNavigationBarPageState createState() => _addNavigationBarPageState();
    }
    
    int selectedIndex = 0;
    
    List pages = [
      HomepageElderly(),
      addGeluPage(),
      chatPage(),
      elderlyProfilePage()
    ];
    
    class _addNavigationBarPageState extends State<addNavigationBarPage> {
      @override
      Widget build(BuildContext context) {
        body:
        pages[selectedIndex];
        return FFNavigationBar(
          theme: FFNavigationBarTheme(
            unselectedItemLabelColor: yellow,
            unselectedItemTextStyle: TextStyle(fontSize: 22.0),
            selectedItemTextStyle: TextStyle(fontSize: 22.0),
            barBackgroundColor: nave,
            unselectedItemIconColor: yellow,
            selectedItemBorderColor: white,
            selectedItemBackgroundColor: yellow,
            selectedItemIconColor: Colors.white,
            selectedItemLabelColor: white,
          ),
          selectedIndex: selectedIndex,
          onSelectTab: (index) {
            setState(() {
              selectedIndex = index;
            });
          },
          items: [
            FFNavigationBarItem(
              label: 'الصفحة الرئيسية',
              iconData: Icons.home,
            ),
            FFNavigationBarItem(
              label: 'إضافة',
              iconData: Icons.add_circle_outlined,
            ),
            FFNavigationBarItem(
              label: 'المحادثة',
              iconData: Icons.chat,
            ),
            FFNavigationBarItem(
              label: 'ملف التعريف',
              iconData: Icons.person,
            ),
          ],
        );
      }
    }

【问题讨论】:

    标签: flutter


    【解决方案1】:

    您正在返回您的自定义导航栏,请不要这样做。

    这样做,

    class _addNavigationBarPageState extends State<addNavigationBarPage> {
    int selectedIndex = 0;
     
     List<Widget> pages = [
       HomepageElderly(),
       addGeluPage(),
       chatPage(),
       elderlyProfilePage()
     ];
    @override
    Widget build(BuildContext context) {
    return Scaffold(
    bottomNavigationBar: FFNavigationBar(),//<-- your custom navigationbar
    body: pages.elementAt(selectedIndex),
    );
    }
    

    【讨论】:

    • 同样没有变化
    • @Reey 我已经更新了我的答案,请检查一下
    • 当我返回脚手架时,这也不起作用,包含底部栏的页面消失了
    • @Reey 你能在问题中更新你的代码吗
    猜你喜欢
    • 2020-12-05
    • 2022-09-26
    • 1970-01-01
    • 2020-03-07
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 2022-11-29
    相关资源
    最近更新 更多