I am very new to Dart, and coding in general. I have produced this code after watching tutorials on YouTube. For the most part, I have been able to troubleshoot most of my problems on my own, here I feel I need some help. I wanted to add a BottomNavigationBar. After I set it as the initial root I am getting the following error:-
Null check operator used on a null value
Here it is:-
The code of page with Bottom nav bar is here:-
class LandingPage extends StatelessWidget {
LandingPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GetBuilder<LandingPageController>(
builder: (controller) {
return Scaffold(
body: SafeArea(
child:IndexedStack(
index: controller.tabIndex,
children: const [
HomeScreen(),
CourseScreen(),
ProfileScreen(),
],
),
),
bottomNavigationBar: BottomNavigationBar(
// onTap: Controller.changeTabIndex,
// currentIndex: controller.tabIndex,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
backgroundColor: Color(0xff2AA8A1),
),
BottomNavigationBarItem(
icon: Icon(Icons.play_arrow),
label: 'Course',
backgroundColor: Color(0xff2AA8A1),
),
BottomNavigationBarItem(
icon: Icon(Icons.person_sharp),
label: 'Profile',
backgroundColor: Color(0xff2AA8A1),
),
],
), //BottomNavBar().BottomNavigationBar(),
);
}
);
}
}
My LandingPage Controller:-
import 'package:get/get.dart';
class LandingPageController extends GetxController {
var tabIndex = 0;
void changeTabIndex(int index) {
tabIndex = index;
update();
}
}
here is my initial Screen:-
_setInitialScreen(User? user) {
if (user == null) {
Get.offAll(() => LoginScreen());
} else {
Get.offAll(() => LandingPage());
}
}
Please Help me understand why I am getting this error
Check the value of controller.tabindex value. May be that's where you are getting null.