The return type 'HomePage' isn't a 'Future, as required by the closure's context

Viewed 30

I try to use the class that I made in another file as a class. but it occures error that 'The return type 'HomePage' isn't a 'Future', as required by the closure's context.'

I used to use the class as a function shape like this when similar situation that I show picture below 'stream builder function'. I don't understand to compare with this(In stream builder, return HomePage is okay.) that why in 'if~ replacesnackBar', HomePage() is not valid.

Could you explain what is the problem in this case? I'll really appreciate about that.. Thanks.

--code below-- Case1: In stream builder function.

return SizedBox.expand(
    child: StreamBuilder(
      stream: FirebaseAuth.instance.authStateChanges(),
      builder: (context, snapshot){
        if(!snapshot.hasData){
          return SignInScreen(providerConfigs: [
            EmailProviderConfiguration()
          ]);
        }

        return HomePage();

Case2: In 'if~ replacesnackBar' that I said above.

if (pattern != null) ...[
        SizedBox(height: 16),
        MaterialButton(
          color: Colors.green,
          child:
          Text("Check Pattern", style: TextStyle(color: Colors.white)),
          onPressed: () async {
            final result = await Navigator.pushNamed(
              context,
              "/check_pattern",
              arguments: pattern,
            );
            if (result == true) {
              context.replaceSnackbar(
                content: Text(
                  "it's correct",
                  style: TextStyle(color: Colors.green),
                ),
              );
              return HomePage();
0 Answers
Related