如何在特定屏幕上隐藏 flutter 中的持久导航栏?

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

我在 flutter 中使用持久性导航栏包。 包装。它试图使用 getx 隐藏它。就像当我导航到仪表板时,我调用 getx 函数将导航设置为 true,当我到达登录屏幕时,我将 itt 设置为 false。但它不工作。我看到很多人都遇到过这个问题,但没有人给出正确的解决方案。

这是我的代码。

主页画面

import 'package:flutter/cupertino.dart';
import 'package:newmart/Order/order.dart';
import 'package:newmart/Screens/dashboard.dart';
import 'package:newmart/Recharge/recharge.dart';
import 'package:newmart/Company/support.dart';
import 'package:flutter/material.dart';
import 'package:newmart/mpin/set_mpin.dart';
import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:get/get.dart';
import 'package:newmart/getxcontrollers/navController.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key, required this.mobileNumber});
  final String mobileNumber;
  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  // String mb = "";
  // late PersistentTabController _controller;
 

  final NavigationBarController _navigationBarController =
      Get.put(NavigationBarController());

  List<PersistentBottomNavBarItem> _navBarsItems() {
    return [
      PersistentBottomNavBarItem(
        icon: const Icon(CupertinoIcons.home),
        title: ("Home"),
        activeColorPrimary: CupertinoColors.activeGreen,
        inactiveColorPrimary: CupertinoColors.systemGrey,
      ),
     ...rest
    ];
  }

  final controler = PersistentTabController();
  List<Widget> _buildScreens() {
    return [
      const Dashboard(),
      const Order(),
      const SetMpin(),
      const Recharge(),
      const Support(),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return PersistentTabView(
      context,
      screens: _buildScreens(),
      hideNavigationBar: _navigationBarController.showNavigationBar.value,
      controller: controler,
      items: _navBarsItems(),
      decoration: NavBarDecoration(borderRadius: BorderRadius.circular(1)),
      navBarStyle: NavBarStyle.style1,
    );
  }
}

控制器

import 'package:get/get.dart';

class NavigationBarController extends GetxController {
  var showNavigationBar = true.obs;

  void toggleNavigationBar(bool value) {
    showNavigationBar.value = value;
  }
}

登录页面

 final NavigationBarController _navigationBarController =
      Get.put(NavigationBarController());
  @override
  void initState() {
    super.initState();
    _getCurrentPosition();
    _navigationBarController.showNavigationBar.value = false;
    setState(() {});
  }
rest code...//

我该如何解决这个问题?

android flutter dart material-design
© www.soinside.com 2019 - 2024. All rights reserved.