My code is giving the Null check operator used on a null value
error although I can't found any null value in the code.
I don't know which screen is actually causing the error but surely it is out of these two screens only which are
- Splash Screen
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tajicEasy/ui/auth/landingPage.dart';
import 'mySharedPreferences.dart';
import 'onBoarding_page.dart';
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
loadSplashScreen();
myAppState();
}
bool isFirstTimeOpen = false;
myAppState() {
MySharedPreferences.instance
.getBooleanValue("firstTimeOpen")
.then((value) => setState(() {
isFirstTimeOpen = value;
}));
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Image.asset(
"assets/images/logo.png",
width: double.infinity,
),
),
);
}
Future<Timer> loadSplashScreen() async {
return Timer(Duration(seconds: 3), onDoneLoadind);
}
onDoneLoadind() async {
Get.offAll(() => isFirstTimeOpen ? LandingPage() : OnBoardingPage());
}
}
- LoadingScreen
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:tajicEasy/controller/authController.dart';
import 'package:tajicEasy/controller/userController.dart';
import 'package:tajicEasy/ui/auth/login_in.dart';
import 'package:tajicEasy/ui/widgets/bottomNavigationBar.dart';
class LandingPage extends GetWidget<AuthController> {
@override
Widget build(BuildContext context){
return GetX(initState: maininit(),
builder: (_) {
print("here1");
if (Get.find<AuthController>().user!=null) {
print("here1");
return Login();
} else {
print("here1");
return AppMain();
}
});
}
maininit() {
print("here");
Get.put<UserController>(UserController());
print("here");
Get.put<AuthController>(AuthController());
print("here");
}
}
I have tried placing loadSplashScreen();
after setState in myAppState()
but after that I getting the same error
checked that isFirstTimeOpen
is not null
bang
operator, which is!
on a null value. But there seems to be no such code here. Check your other widgets – Legislatorbang
) operator is not used in any widget – Petrie