title: Flutter - Listening for data changes in user profile (Firestore) of Firebase user using provider package
body: <p>By now I successfully react on auth-changes of my Firebase user to map it to my own custom user class</p>
  <pre class="lang-dart prettyprint-override"><code>import 'package:mypckg/models/user.dart' as local;
  import 'package:firebase_auth/firebase_auth.dart' as auth;
  import 'package:mypckg/services/database.dart';
  
  class AuthService {
    final auth.FirebaseAuth _auth = auth.FirebaseAuth.instance;
  
    // create user obj based on firebase user
    Future&lt;local.User&gt; _userFromFirebaseUser(auth.User user) async {
      return user != null
          ? local.User(/* ... init user properties ... */)
          : null;
    }
  
    // auth change user stream
    Stream&lt;local.User&gt; get user {
      return _auth.authStateChanges().asyncMap(_userFromFirebaseUser);
    }
  
  ...
  
  </code></pre>
  <p>In Cloud Firestore I store additional values of that user which are not covered by Firebase user e.g.</p>
  <p><img src="https://i.stack.imgur.com/jm3Bo.png" alt="users collection in Cloud Firestore" /></p>
  <p>In <strong>main.dart</strong> the provider is set to provide my app with the local user in case he signed in or signed out (authStateChanges). My idea was to subscribe to another stream which will listen to changes on the 'users' document in Cloud Firestore.</p>
  <pre class="lang-dart prettyprint-override"><code>class MyPckg extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      final i18n = I18n.delegate;
      //AuthService().signInAnon();
      return MultiProvider(
        providers: [
          StreamProvider&lt;User&gt;(
            create: (_) =&gt; AuthService().user,
          ),
          /* my idea to subscribe to another stream which will listen to changes on user details in Firestore */
          StreamProvider&lt;User&gt;(
            create: (_) =&gt; AuthService().customUser,
          ),
        ],
        child: DynamicTheme(
          defaultBrightness: Brightness.light,
          data: (brightness) {
  
  ...
  
  </code></pre>
  <p>I have a profile view where the user may edit those values, e.g. the locale and it gets written to the Firestore correctly with</p>
  <pre class="lang-dart prettyprint-override"><code>Future&lt;void&gt; updateUserLanguage(String language) async {
      return await usersCollection.doc(uid).update({
        'language': language,
      });
    }
  </code></pre>
  <p>But the view is not rebuild as the current stream only reacts to authStateChanges.</p>
  <p>Does anyone have a working example how to setup the link from users in Firestore collection that my app will listen to changes done there? What will my customUser method have to look like?</p>
  <p>Thank you!</p>