initState() not show in Autosuggetion

Viewed 1568

I try to override initState() inside _SplashScreenState, but it not show in suggestions list, i try invalid catches/Restart too.

import 'package:coupfferapp/screen/home.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart';

class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();

  }

   class _SplashScreenState extends State<SplashScreen> {



@override
 void initState() {
 super.initState();
_checkLoginSession().then((status) {
  _navigateToHome();
  });
}

Future<bool> _checkLoginSession() async {
await Future.delayed(Duration(microseconds: 5000), () {});
return true;
   }

void _navigateToHome() {
Navigator.of(context).pushReplacement(
    MaterialPageRoute(builder: (BuildContext context) => Home()));
}

 @override
 Widget build(BuildContext context) {
  return Scaffold(
  body: Container(
    child: Stack(
      alignment: Alignment.center,
      children: <Widget>[
        Container(
          color: Colors.white,
        ),
  //            Opacity(
  //                    opacity: .9,
  //                    child: Image.asset('images/splash.png', fit: 
   BoxFit.cover)),
        Shimmer.fromColors(
            child: Container(
              padding: EdgeInsets.all(16.0),
              child: Text(
                "Mayur",
                style: TextStyle(
                    fontSize: 90.0,
                    fontFamily: 'Calistoga',
                    shadows: <Shadow>[
                      Shadow(
                          blurRadius: 18.0,
                          color: Colors.black26,
                          offset: Offset.fromDirection(120, 12))
                    ]),
              ),
            ),
            baseColor: Colors.orange,
            highlightColor: Colors.red)
      ],
     ),
    ),
   );
  }
}
4 Answers

I had the same issue and I have just call my initState function from right above the build function. Let nothing comes between your initState() and build function.

 @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }
  
  @override
  Widget build(BuildContext context) {
    return isAuth ? buildAuthScreen() : buildUnAuthScreen();
  }

you need to type right above the build method otherwise the snippet won't appear.

This is the way you have it in suggestion, maybe you put it in the wrong sort. It has to be outside the build function:

class _SplashScreenState extends State<SplashScreen> {

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

 @override
 Widget build(BuildContext context) {

       }
}

Hope it helps!

Maybe sometimes it does not show you the overridden methods maybe you have type initial letters and click Ctrl+Space for windows and Cmd +space for Mac which forces it to find the methods. Let me know if it works

Related