0
votes

I'm getting an error on my IOS simulator when I run my flutter app.

The offending widget is: FutureBuilder Build functions must never return null. To return an empty space that causes the building widget to fill available room, return "Container()". To return an empty space that takes as little room as possible, return "new Container(width: 0.0, height: 0.0)

void main(){
  WidgetsFlutterBinding.ensureInitialized();
  runApp(App());
}

class App extends StatelessWidget {
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
          theme: ThemeData(
            primaryColor: Color(0xFF6A8D73),
            primaryColorDark: Color(0xFF475E4D),
            accentColor: Color(0xffCFE8D5),
            primaryColorLight: Colors.white
          ),
          home: FutureBuilder(
            future: _initialization,
            builder: (context, snapshot){
              if (snapshot.hasError) {
                print(snapshot.error);
                return null;
              }
              if (snapshot.connectionState == ConnectionState.done) {
                return HomePage();
              }
              return Splash();
            },
          )
    );
  }
}
class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
        create: (_) => UserRepository.instance(),
        child: Consumer(
          builder: (context, UserRepository user, _){
            switch(user.status){
              case Status.Uninitialized:
                return Splash();
              case Status.Unauthenticated:
              case Status.Authenticating:
                return LoginPage();
              case Status.Authenticated:
                return TaskBar();
              default:
                return null;
            }
          },
        ),
    );
  }
}

class Splash extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Material(
      child: Center(
        child: Text("Splash Screen"),
      ),
    );
  }
}
1
You return null when snapshot has error. You need to return an error widget - cs guy

1 Answers

0
votes

You just have to replace the following code where you are checking for error-

if (snapshot.hasError) {
            print(snapshot.error);
            return SizedBox();
          }