I am working on a flutter project with GetX features in it but certainly I got some irrelevant and also according to me surprising error which is mentioned above.
the first error causing code is
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 == "") {
print("here1");
return Login();
} else {
print("here1");
return AppMain();
}
});
}
maininit() async {
print("here");
await Get.put<UserController>(UserController());
print("here");
await Get.put<AuthController>(AuthController());
print("here");
}
}
I am getting error after first here is printed that is in
await Get.put<UserController>(UserController());
Auth controller is initializing absolutely fine my code for usercontroller is:
import 'package:get/get.dart';
import 'package:tajicEasy/model/userModel.dart';
import 'package:tajicEasy/services/database.dart';
class UserController extends GetxController{
var _userModel = UserModel().obs;
UserModel get user => _userModel.value;
set user(UserModel value) => this._userModel.value;
Database _db = Database();
bool enable = false;
enabled(bool value) {
print("here u");
enable = !value;
update();
}
void clear() {
print("here u");
_userModel.value = UserModel();
}
}
I don't know much about GetX as I am working on it for the first time so please be lenient on me.
After this I am getting following error this error was removed as per the first answer from jahangir
my code of splash activity is
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tajicEasy/ui/auth/landingPage.dart';
import 'package:tajicEasy/ui/pages/home_page.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();
myAppState();
}
bool isFirstTimeOpen = false;
myAppState() {
MySharedPreferences.instance
.getBooleanValue("firstTimeOpen")
.then((value) => setState(() {
isFirstTimeOpen = value;
})).then((value) => loadSplashScreen());
}
@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(){
Get.offAll(() => {
if(isFirstTimeOpen == true){
LandingPage()
}else{
HomePage()
}
});
}
}