How to solve: The argument type 'Stream<MyUser?>' can't be assigned to the parameter type 'Stream<MyUser?>?'

Question

Asked by Tim's on December 07, 2021 (source).

I'm trying to create a user system with assistment of this playlist. But, it's kind of outdated so I'm trying to keeping up with today. I'm a totally beginner. I read few things from the stackoverflow but I couldn't keep up. Here is what error it gave:

The argument type 'Stream<MyUser?>' can't be assigned to the parameter type 'Stream<MyUser?>?'.

And here is the main.dart: (To be specific error is right in the "value: AuthService().user," line. The "AuthService().user" part is underline in red.)

import 'package:flutter/material.dart';
import 'package:unistuff_main/screens/wrapper.dart';
import 'package:provider/provider.dart';
import 'package:unistuff_main/services/auth.dart';
import 'package:unistuff_main/models/myuser.dart';

void main() {
  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return StreamProvider<MyUser?>.value(
      initialData: null,
      value: AuthService().user,
      child: MaterialApp(
        home: Wrapper(),
      ),
    );
  }
}

And here is my myuser.dart file:

class MyUser {
  final String? uid;

  MyUser({this.uid});
}

And here is auth.dart: (If you noticed I didn't add any login method yet. Is that can cause the problem?)

import 'package:firebase_auth/firebase_auth.dart';
import 'package:unistuff_main/models/MyUser.dart';

class AuthService {
  final FirebaseAuth _auth = FirebaseAuth.instance; //private data member

  //create MyUser object based on FirebaseUser
  MyUser? _userfromFirebase(User user) {
    return user != null ? MyUser(uid: user.uid) : null;
  }

  //auth change user stream
  Stream<MyUser?> get user {
    return _auth
        .authStateChanges()
        .map((User? user) => _userfromFirebase(user!));
  }

  //sign in with email & password
  Future signInWithMail() async {
    try {} catch (e) {}
  }

  //register with email & password

  //sign out
}

Thanks for any help..

Answer

Question answered by Nitrodon (source).

Library URIs are case sensitive. AuthService imports MyUser from MyUser.dart, while MyApp imports MyUser from myuser.dart. Even though these are the same file (assuming a case-insensitive file system), they are considered different libraries, so the types don't match.

You will need to change one of the import statements to match the other.

DART FIREBASE FIREBASE-AUTHENTICATION FLUTTER
SHARE: