title: Integrating a ChangeNotifier with a FutureProvider
body: <p>I know the subject of updating information from a FutureProvider has come up on here so I want to avoid repeating prior discussion.  I found a really useful way to integrate FutureProvider into my app to pull in information from Firebase's Real-Time Database (as opposed to having to reuse the same async functions on 4 or 5 different screens).  In further testing, of course, I came to realize that any changes to the Real-Time Database do not take effect in the FutureProvider until I restart the app, even if I toggle listen to true or directly call my fetchUser() method in my FutureProvider.</p>
  <p>I ask if anyone has had success merging a ChangeNotifier with a FutureProvider to notify listeners of an update?  I've tried a few approaches and have not had success.  Here is my latest:</p>
  <p><strong>My main.dart:</strong></p>
  <pre><code>import 'package:shared_preferences/shared_preferences.dart';
  import 'package:fast_food_health_e/widgets/nutritionixList.dart';
  SharedPreferences preferences;
  
  
  void main() async {
  
    WidgetsFlutterBinding.ensureInitialized();
    preferences = await SharedPreferences.getInstance();
    await Firebase.initializeApp();
    runApp(FastFoodHealthEApp());
     }
   class FastFoodHealthEApp extends StatelessWidget {
   final FirebaseServices firebaseServices = FirebaseServices();
  
   @override
   Widget build(BuildContext context) {
  
  
  
      return MultiProvider(
          providers: [
  
      Provider&lt;AuthenticationProvider&gt;(
      create: (_) =&gt; AuthenticationProvider(FirebaseAuth.instance),
       ),
       StreamProvider(
       create: (context) =&gt; context.read&lt;AuthenticationProvider&gt;().authState,
       ),
       ChangeNotifierProvider(
       create: (context) =&gt; FirebaseServices(),
      child: (
      FutureProvider(create: (context) =&gt; firebaseServices.fetchUser(),
       catchError: (context, error) {
       print(&quot;The Error is: &quot; + error.toString());
      },)
  
      ),
      ),
     ],
  
    child: MaterialApp(
  
      initialRoute: '/',
      routes: {
  </code></pre>
  <p><strong>My FutureProvider:</strong></p>
  <pre><code> class FirebaseServices with ChangeNotifier{
  
  
  
     Future&lt;FastFoodHealthEUser&gt; fetchUser()
    async{
      // var firebaseUser = context.watch&lt;User&gt;();
      // String userID  = firebaseUser.uid;
      Map&lt;String, dynamic&gt; theMap;
     final FirebaseAuth auth = FirebaseAuth.instance;
     final User user = auth.currentUser;
     final uid = user.uid;
  
     notifyListeners();
  
      final referenceDatabase = await FirebaseDatabase.instance
          .reference()
          .child(uid)
          .once()
          .then((snapshot){theMap = new Map&lt;String, dynamic&gt;.from(snapshot.value);});
  
  
  
  
  
      return FastFoodHealthEUser.fromJson(theMap);
  
  
  
    }
  </code></pre>
  <p><strong>Class with an invocation of the FutureProvider:</strong></p>
  <pre><code> @override
     void didChangeDependencies() {
  
  
  setUpUsers();
  
  
  
  super.didChangeDependencies();
  </code></pre>
  <p>}</p>
  <pre><code>void setUpUsers () async  {
  
  
  
  firebaseUser = context.watch&lt;User&gt;();
  userID  = firebaseUser.uid;
  fastFoodHealthEUser =  Provider.of&lt;FastFoodHealthEUser&gt;(context, listen: true);
  
  
  this._getMoreData();
  
  
  }
  
  
  
  void _getMoreData() async {
  
  
  
  
  if(fastFoodHealthEUser!=null){
  
  
  
  
      Calories = fastFoodHealthEUser.todaysCal;
  
      print(&quot;Just testing this: &quot; + Calories.toString());
  
      sodium = fastFoodHealthEUser.todaysSodium;
  </code></pre>
  <p>Probably unsurprisingly, I get an error about not being able to find the correct Provider doing it as above:</p>
  <p><em>E/flutter ( 3492): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Error: Could not find the correct Provider above this MyDiaryScreen Widget</em></p>
  <p>Am I foolish for trying this with a FutureProvider?  Might a StreamProvider be better?  I just find FutureProvider more useful (as before my screens were chalk full of FutureBuilders, but I never had an issue updating them with new data).</p>