0

I get the following error in my Dart Analysis:

error: The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type. (body_might_complete_normally at [the_book_club] lib\main.dart:28)

This is my lib/main.dart:

   Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(App());
}

class App extends StatefulWidget {
  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: _initialization,
      builder: (context, snapshot) {
        if (snapshot.hasError) {
          return SomethingWentWrong();
        }
        if (snapshot.connectionState == ConnectionState.done) {
          return AnimatedSplashScreen(
            duration: 3000,
            splash: const FaIcon(
              FontAwesomeIcons.bookOpen,
              size: 200,
            ),
            nextScreen: HomePage(),
            splashTransition: SplashTransition.fadeTransition,
            backgroundColor: const Color.fromARGB(255, 96, 125, 139),
          );
        }
      },
    );
  }
}

class SomethingWentWrong extends StatelessWidget {
  const SomethingWentWrong({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Row(
        children: <Widget>[Text('something went wrong!')],
      ),
    );
  }
}
  • Where are you defining `SomethingWentWrong`? – enzo Oct 25 '21 at 05:54
  • Also, think of what would be returned in the `builder` callback of `FutureBuilder` if `!snapshot.hasError` and `snapshot.connectionState != ConnectionState.done`. You must return a widget in this case. – enzo Oct 25 '21 at 05:55
  • I have updated with the define of SomethingWentWrong. 1 error remains though, see updated original post. – Måns Björn Oct 25 '21 at 10:41

0 Answers0