Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter – How to handle Non-Nullable Instance of widget properties

I am new to flutter and currently trying to simple animation on my component, but i keep getting a " Non-Nullable Instance " error, i checked out other video tutorials but theirs worked perfectly while mine keeps throwing errors.

Here’s my code.

class HomeScreen extends StatefulWidget {
  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {

  Animation<Offset> sbarAnimation;
  AnimationController sbarAnimationController;

  @override

  void initState() {

    super.initState();

    sbarAnimationController = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: 250),
    );

    sbarAnimation = Tween<Offset>(
      begin: Offset(-1, 0),
      end: Offset(0, 0),
    ).animate(
      CurvedAnimation(
        parent: sbarAnimationController,
        curve: Curves.easeInOut,
      ),
    );

  }

And then the code for the widget is below

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  @override
  Widget build(BuildContext context) {
    return Scaffold(

      body: Container(
        color: kBackgroundColor,
        child: Stack(

          children: [
            SafeArea(
              //so the background covers the entire app..
              child: Column(
                children: [
                  HomeScreenNavBar(),                     
                  ExploreCourseList(),
                ],
              ),
            ),

            SlideTransition(

              position: sbarAnimation,   // this is where i call the _animation

              child: SafeArea(
                child: SidebarScreen(),
                bottom: false,  
              ),
            ),
          ],

        ),
      ),
    );
  }
}

below is the errors i keep getting, and most of the solutions i’ve seen did exactly the same thing, theirs works, but mine is giving this errors.. please what am i supposed to do.

enter image description here

>Solution :

Use late keyword to initialize variables later as you are doing in your initState

late Animation<Offset> sbarAnimation;
late AnimationController sbarAnimationController;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading