'LateInitializationError: Field '_instance@141084504' has not been initialized
When using getX and Flutter I get following error:
LateInitializationError: Field '_instance@141084504' has not been initialized
This is the code:
import 'dart:async';
import 'package:auth/view/signup_screen.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class SplashScreen extends StatelessWidget {
const SplashScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
Timer(Duration(seconds: 3), () {
Get.to(() => SignUPScreen());
});
return Scaffold(
body: Center(
child: CircleAvatar(),
),
);
}
}
Solution 1:[1]
It looks like you want to navigate to another screen and having an issue on the timer. What I would suggest is to convert your StatelessWidget to StatefulWidget and putting the timer inside the initState()
.
Here's the code:
void initState() {
Timer(Duration(seconds: 3), () {
Get.to(() => SignUPScreen());
});
super.initState();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kei Credo |