benyaminbeyzaie / circular_bottom_navigation

Circular bottom navigation is a bottom navigation library for flutter with circular indicator and cool animations.
BSD 3-Clause "New" or "Revised" License
654 stars 97 forks source link

Exception caught by foundation library #16

Closed raegartargarian closed 2 years ago

raegartargarian commented 4 years ago

I did not do much and I was trying to use this library as I got this error:

════════ Exception caught by foundation library ════════════════════════════════ The following NoSuchMethodError was thrown while dispatching notifications for CircularBottomNavigationController: The getter 'value' was called on null. Receiver: null Tried calling: value

here is my page:

import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:visitor_app/screens/add_user_page/screen/add_user_page.dart'; import 'package:visitor_app/screens/home_page/screen/home_page.dart'; import 'package:visitor_app/screens/map_page/screen/map_page.dart'; import 'package:visitor_app/screens/my_users_page/screen/my_users_page.dart'; import 'package:visitor_app/screens/profile_page/screen/profile_page.dart'; import 'package:visitor_app/utils/screen_utils/connection_alert_widget.dart'; import 'package:visitor_app/utils/screen_utils/connection_service.dart'; import 'package:circular_bottom_navigation/circular_bottom_navigation.dart'; import 'package:circular_bottom_navigation/tab_item.dart';

class MainPage extends StatefulWidget { final int tab; MainPage({this.tab}); @override _MainPageState createState() => _MainPageState(); }

class _MainPageState extends State { AddUserPage addUserPage; MapPage mapPage; MyUsersPage myUsersPage; ProfilePage profilePage; HomePage homePage; List pages; Widget currentPage;

@override void initState() { final connectionStatus = ConnectionStatusSingleton.getInstance(); addUserPage = new AddUserPage(); mapPage = new MapPage(); myUsersPage = new MyUsersPage(); profilePage = new ProfilePage(); homePage = new HomePage(); pages = [mapPage, addUserPage, homePage, myUsersPage, profilePage]; currentPage = widget.tab == null ? homePage : pages[widget.tab]; connectionStatus.initialize(); super.initState(); }

@override Widget build(BuildContext context) { return WillPopScope( onWillPop: () {}, child: Scaffold( body: Stack( children: [currentPage, ConnectionAlertWidget()], ), bottomNavigationBar: CircularBottomNavigation( List.of([ TabItem(Icons.home, "Home", Colors.black, labelStyle: TextStyle(fontFamily: "Ir")), TabItem(Icons.search, "Search", Colors.black, labelStyle: TextStyle(fontFamily: "Ir")), TabItem(Icons.shopping_cart, "Basket", Colors.black, labelStyle: TextStyle(fontFamily: "Ir")), TabItem(Icons.search, "Search", Colors.black, labelStyle: TextStyle(fontFamily: "Ir")), TabItem(Icons.search, "Search", Colors.black, labelStyle: TextStyle(fontFamily: "Ir")), ]), selectedCallback: (position) { print(position); // setState(() { // currentPage = pages[position]; // }); }, ))); }

}

makss68 commented 4 years ago

You need to attach an existing CircularBottomNavigationController to the controller of the CircularBottomNavigation