VB10 / vboverflow

Yes you can always ask to me anything but do you search problem or can you write any solutions?
123 stars 3 forks source link

BaseView BottomNavigationBar Sorunu #98

Closed abdullah017 closed 2 years ago

abdullah017 commented 2 years ago

Baseview yapımda bottomnavbar kullanıyorum, ancak sayfayı değiştirdiğimde aktif simge değişmiyor. GetX kullanıyorum ve yönlendirmelerin nasıl yapılacağı konusunda yardıma ihtiyacım var. Sanırım sayfaları değiştirdiğimde state durumunu koruyamıyor ve yeniden inşa oluyor. Bu nedenle sayfa değişse bile aktif simge değişmiyor. Baseview yapısı doğru mu bilmiyorum ama anladığım kadarıyla sorun ekranların yeniden çizilmesinde.. Bu konuda yardımcı olabilirseniz sevinirim.

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,
    );
  }
}
VB10 commented 2 years ago

bu tarz soruları oncelıkle stack overflowa acıp oradan buraya acmanı tavsiye ederim kolay gelsin

abdullah017 commented 2 years ago

Hocam maalesef sormadığım yer kalmadı, en son yer olarak buraya açıyorum. Diğer platformlardan arkadaşlar bağlanıp baktılar onlarda anlamadılar,bir çözüm üretemediler... Teşekkür ederim :)