title: Flutter: Create object stream from Hive box
body: <p>I am trying to access some user settings which are changed and accessed throughout the app. To do that, I am using Hive to retrieve user settings from a box. I would like to make that information accessible throughout the app by turning the <code>UserSettings</code> object retrieved from <code>Hive.box('settings').get(userID)</code> into a stream that will be fed into a <code>StreamProvider</code>.</p>
  <p>How would I go about turning <code>Hive.box('settings').get(userID)</code> into a Stream?</p>
  <p>Edit: Here is my code implementation so far:</p>
  <p>local_database.dart</p>
  <pre><code>static Stream&lt;UserSettings&gt; get userSettings {
    return Hive.box('settings').watch(key: userID)?.map((boxEvent) {
      return boxEvent.value; // ========&gt; value is always null from boxEvent
    });
  }
  
  static void saveUserSettings(UserSettings userPref) {
    Hive.box('settings').put(userID, userPref); 
  }
  </code></pre>
  <p>main.dart</p>
  <pre><code>class Launch extends StatefulWidget {
    @override
    _LaunchState createState() =&gt; _LaunchState();
  }
  
  class _LaunchState extends State&lt;Launch&gt; {
    @override
    Widget build(BuildContext context) {
      return MultiProvider(
        providers: [
          StreamProvider&lt;User&gt;.value(value: AuthService.user),
          StreamProvider&lt;UserSettings&gt;.value(value: LocalDatabase.userSettings),
        ],
        child: MaterialApp(
          title: 'MyApp',
          home: AuthWrapper(),
        ),
      );
    }
  </code></pre>
  <p>settings.dart</p>
  <pre><code>class SettingsScreen extends StatefulWidget {
    @override
    _SettingsScreenState createState() =&gt; _SettingsScreenState();
  }
  
  class _SettingsScreenState extends State&lt;SettingsScreen&gt; {
    UserSettings _settings;
  
    @override
    Widget build(BuildContext context) {
      _settings = Provider.of&lt;UserSettings&gt;(context);
  
      print(_settings.useLightTheme); // =====&gt; Always returns null
  
      return Scaffold(
        appBar: AppBar(title: 'Settings'),
        body: Container()
      ),
    }
  }
  </code></pre>