0

I am working on Flutter Firebase send verification email page, but I am getting the Undefined name Utils error after adding a catch error exception. Below is the snippet of the code:

Future sendVerificationEmail() async {
    try {
        final user = FirebaseAuth.instance.currentUser!;
        await user.sendEmailVerification();

        setState(() => canResendEmail =` false);
        await Future.delayed(const Duration(seconds: 5));
        setState(() => canResendEmail = true);
    }
    catch (e) {
        Utils.showSnackBar(e.toString());
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Muema
  • 57
  • 1
  • 5
  • Why the [backtick](https://en.wiktionary.org/wiki/backtick#Noun) in line *"setState(() => "canResendEmail =` false);"*? – Peter Mortensen Jun 22 '22 at 21:55
  • It isn't in the [indicated source](https://serveanswer.com/issue/how-to-use-google-login-in-flutter-and-bypass-emailverification). Neither is the double quote before *"canResendEmail"*. – Peter Mortensen Jun 22 '22 at 22:10

2 Answers2

0

I could be wrong, but I think whoever wrote that code also wrote a Utils class with that function as well. It's not part of any standard library. And the exact implementation we can't know. Obviously it's some helper method to show a Snackbar. It usually requires a BuildContext, but you could check out How to show snackBar without Scaffold to see alternatives.

And a quick Google search makes me think that you simple copied that code from How to use google login in flutter and bypass emailverification since it has the exact same method. I apologize if that's not the case. My advice is to not simply copy pasting code without understanding what's happening. Especially code that is not part of a guide.

In any case, the code that doesn't work shows a message to the user through a Snackbar in case an exception happens. Which isn't really a user-friendly message, so it might be not that great to write it like that anyway.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ivo
  • 18,659
  • 2
  • 23
  • 35
-1

I think you haven't added

import 'package:basic_utils/basic_utils.dart';

Or, make sure you added this in your pubspec.yaml file:

dependencies:
  basic_utils: ^4.2.2
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hitesh
  • 1
  • 3