1
votes

Actually I am new to flutter. Here is my code for splash screen.

  void main() async {
     WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    runApp(MyApp());
    }

 class MyApp extends StatelessWidget {

 @override
 Widget build(BuildContext context) {
 return MaterialApp(
 debugShowCheckedModeBanner: false,
 title: 'Meet Up',
 theme: ThemeData(
   primarySwatch: Colors.blue,
 ),
   home: IntroScreen(),);

}
}

class IntroScreen extends StatefulWidget{

@override
_IntroScreenState createState() => _IntroScreenState();
}

class _IntroScreenState extends State<IntroScreen> {

@override
void initState() {
super.initState();

FirebaseAuth auth =  FirebaseAuth.instance;
if (auth.currentUser != null)
  {
    Navigator.pushReplacement(
      context,
      MaterialPageRoute(builder: (context) => Home(uid: auth.currentUser.uid)),
    );
  }
else
  {
    Navigator.pushReplacement(
      context,
      MaterialPageRoute(builder: (context) => SignUp()),
    );
   }

 }

 @override
 Widget build(BuildContext context) {
 return new SplashScreen(
      seconds: 5,
      title: new Text('Welcome To Meet up!',
      style: new TextStyle(
          fontWeight: FontWeight.bold,
          fontSize: 20.0
      ),),
    image: Image.asset('assets/images/dart.png',fit:BoxFit.scaleDown),
    backgroundColor: Colors.white,
    styleTextUnderTheLoader: new TextStyle(),
    photoSize: 100.0,
    onClick: ()=>print("flutter"),
    loaderColor: Colors.red
);
}
}

I am getting below error:

The following assertion was thrown building Builder: setState() or markNeedsBuild() called during build. This Overlay widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase. The widget on which setState() or markNeedsBuild() was called was: Overlay-[LabeledGlobalKey#5e01c]

Please help me to resolve this error.

1
@SingleSoul any solution to this problem?Technosoft Patel

1 Answers

1
votes

try to add a timer inside initState like

  @override
  void initState() {
    Timer(new Duration(seconds: 2), () {
     .
     .
     .
    });
    super.initState();
  }