Flutter-GetX-Navigation:加载初始屏幕时出现空检查操作员错误
我是DART的新手,一般而言。在YouTube上观看教程后,我制作了此代码。在大多数情况下,我能够自己解决大多数问题,在这里我觉得我需要一些帮助。我想添加一个底部绘制栏。将其设置为初始根后,我会收到以下错误: -
Null check operator used on a null value
在这里是: -
栏的页面代码:
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(),
);
}
);
}
}
带有底部导航
import 'package:get/get.dart';
class LandingPageController extends GetxController {
var tabIndex = 0;
void changeTabIndex(int index) {
tabIndex = index;
update();
}
}
=“ https://i.sstatic.net/toxfi.png 屏幕: -
_setInitialScreen(User? user) {
if (user == null) {
Get.offAll(() => LoginScreen());
} else {
Get.offAll(() => LandingPage());
}
}
请帮助我理解为什么我会遇到此错误
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查controller.tabindex值的值。可能这就是你变得空的地方。
Check the value of controller.tabindex value. May be that's where you are getting null.