0

I am updating my app to comply the null safety right now. Still new and trying to figure things out. However, I am stuck on the if & else if statement.

return Container(
  child: 
      if (_dashboardViewController.currentPage() == 'home') {
        return HomeView();
      } else if (_dashboardViewController.currentPage() == 'profile') {
        return ProfileView();
      } else if (_dashboardViewController.currentPage() == 'game') {
        return GameView();
      }

They are all Container widgets. But, I am receiving

The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type. Try adding either a return or a throw statement at the end.

It worked before the null safety. I am quite lost where I can make this null safety. And, also, where can I put ? to allow to have null value in this case?

1 Answer 1

1
   if (_dashboardViewController.currentPage() == 'home') {
        return HomeView();
      } else if (_dashboardViewController.currentPage() == 'profile') {
        return ProfileView();
      } else if (_dashboardViewController.currentPage() == 'game') {
        return GameView();
      }
   else return Container() // it has to return something, can't return null/nothing

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.