Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseView Bottom Navigation Bar Page Change #2488

Open
abdullah017 opened this issue Aug 6, 2022 · 0 comments
Open

BaseView Bottom Navigation Bar Page Change #2488

abdullah017 opened this issue Aug 6, 2022 · 0 comments
Assignees

Comments

@abdullah017
Copy link

abdullah017 commented Aug 6, 2022

I use the bottom navigation bar in Base View, but the active icon does not change when I change the page. I am using GetX and need help on how to do the redirects. I guess when I change the pages, it can't keep the state and rebuild happens. Therefore, the active icon does not change even if the page changes. I don't know if the baseview build is correct but as far as I can tell the problem seems to be with the redrawing of the screens..

abstract class BaseView<T extends BaseController> extends StatelessWidget {
  BaseView({
    Key? key,
    this.navBarHide = true,
  }) : super(key: key);

  final bool navBarHide;
  final String? tag = null;
  final AppTextStyle appTextStyle = AppTextStyle();
  final FormValidationHelper formValidationHelper = FormValidationHelper();

  T get controller => GetInstance().find<T>(tag: tag);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<T>(
      builder: (controller) {
        return Scaffold(
          //appBar: AppBar(title: Text(appBarTitle)),

          bottomNavigationBar: !navBarHide
              ? BottomNavigationBar(
                  onTap: (index) {
                    controller.tabChange(index);

                    if (index == 0) {
                      Get.to(DashBoardView(), binding: DashBoardBinding());
                    } else if (index == 1) {
                      Get.to(BlankView(), binding: BlankBinding());
                    } else if (index == 2) {
                      Get.to(HomeView(), binding: HomeBinding());
                    } else if (index == 3) {
                      Get.to(LanguagesView(), binding: LanguagesBinding());
                    } else if (index == 4) {
                      Get.to(MenuView(), binding: MenuBinding());
                    }
                 
                  },
                  unselectedLabelStyle: TextStyle(fontSize: 0),
                  unselectedFontSize: 0,
                  unselectedIconTheme: IconThemeData(
                    size: Get.width > 390 ? 24.sp : 24.sp,
                  ),
                  selectedFontSize: 0,
                  selectedIconTheme: IconThemeData(
                    size: Get.width > 390 ? 24.sm : 24.sm,
                  ),
                  selectedLabelStyle: TextStyle(fontSize: 0),
                  type: BottomNavigationBarType.fixed,
                  landscapeLayout: BottomNavigationBarLandscapeLayout.spread,
                  unselectedItemColor: Colors.black,
                  selectedItemColor: Colors.orange,
                  showSelectedLabels: true,
                  showUnselectedLabels: true,
                  currentIndex: controller.tabIndex.value,
                  items: [
                      _bottomNavbarItem(
                        AppAssets.card_icon,
                        '',
                        0,
                      ),
                      _bottomNavbarItem(
                        AppAssets.key_icon,
                        '',
                        1,
                      ),
                      _bottomNavbarItem(
                        AppAssets.home_icon,
                        '',
                        2,
                      ),
                      _bottomNavbarItem(AppAssets.doc_icon, '', 3),
                      _bottomNavbarItem(
                        AppAssets.menu_icon,
                        '',
                        4,
                      ),
                    ])
              : null,
          body: vBuilder(),
        
        );
      },
    );
  }

  Widget vBuilder();

  _bottomNavbarItem(String assetName, String label, int index) {
    return BottomNavigationBarItem(
      icon: Image.asset(
        assetName,
        width: 24.w,
        height: 24.h,
        fit: BoxFit.contain,
      ),
      activeIcon: Container(
        height: 24.h,
        width: 24.w,
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(width: 2, color: Colors.orange),
          ),
        ),
        child: Image.asset(assetName),
      ),
      label: label,
    );
  }
}

flutter doctor -v

[✓] Flutter (Channel stable, 3.0.5, on macOS 12.5 21G72 darwin-arm, locale
    tr-TR)
    • Flutter version 3.0.5 at /Users/abdullahtas/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (3 hafta önce), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/abdullahtas/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.69.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.46.0

[✓] Connected device (3 available)
    • iPhone 13 Pro (mobile) • 389D7988-9D91-4D61-B2E8-3A1A07925D3D • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-15-5 (simulator)
    • macOS (desktop)        • macos                                •
      darwin-arm64   • macOS 12.5 21G72 darwin-arm
    • Chrome (web)           • chrome                               •
      web-javascript • Google Chrome 103.0.5060.134

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

GETX: get: ^4.6.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants