Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected text "return"

I'm trying to implement an AuthService from a tutorial of Fireship (https://fireship.io/lessons/flutter-firebase-google-oauth-firestore/)

I copied exactly his AuthService:

  AuthService() {
    user = Observable(_auth.onAuthStateChanged);

    profile = user.switchMap((FirebaseUser u) => {
      if (u != null) {
        return _db.collection("users").document(u.uid).snapshots().map((snap) => snap.data);
      } else {
        return Observable.just({});
      }
    });
  }

I get these errors:

enter image description here

enter image description here

If I copy the code from his website (it's exactly the same) there are no errors. wtf? Can someone explain this or help? Thanks!

like image 940
filip Avatar asked Apr 08 '26 20:04

filip


1 Answers

Change this:

    profile = user.switchMap((FirebaseUser u) => {

into this:

    profile = user.switchMap((FirebaseUser u) {

From the docs:

For functions that contain just one expression, you can use a shorthand syntax:

bool isNoble(int atomicNumber) => _nobleGases[atomicNumber] != null;

The => expr syntax is a shorthand for { return expr; }. The => notation is sometimes referred to as arrow syntax.

like image 109
Peter Haddad Avatar answered Apr 11 '26 13:04

Peter Haddad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!