title: Flutter integrating Hive database with Riverpod
body: <p>There is very easy way to use <code>Hive</code> key-value database on <code>StatefulWidgets</code>, for example:</p>
  <pre class="lang-dart prettyprint-override"><code>class HookDemo extends StatefulWidget {
    @override
    _HookDemoState createState() =&gt; _HookDemoState();
  }
  
  class _HookDemoState extends State&lt;HookDemo&gt; {
    Box user;
    @override
    void initState() {
      super.initState();
      
      user = Hive.box&lt;User&gt;('user');
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        floatingActionButton: FloatingActionButton(
          onPressed: () {
              final _u = User()
                  ..nameFamily = 'myname'
                  ..mobileNumber = '123456789';
              _user!.add(_u);
              _u.save();
          },
          child: Icon(Icons.add),
        ),
        ...
      );
    }
  }
  </code></pre>
  <p>here we defined <code>Box user</code> property and inside <code>initState</code> we implemented what's user such as <code>user = Hive.box&lt;User&gt;('user');</code></p>
  <p>after that we can use <code>user</code> without any problem and getting <code>already opened</code> error</p>
  <p>now in this current application we used <code>HookWidget</code> and when we want to use <code>Hive</code> we get error as <code>box already opened</code></p>
  <p><code>main.dart</code>:</p>
  <pre class="lang-dart prettyprint-override"><code>Future&lt;void&gt; initHiveDriver() async {
    final appDocumentDirectory = await path_provider.getApplicationDocumentsDirectory();
    await Hive.initFlutter(appDocumentDirectory.path);
  
    await Hive.openBox&lt;UserAdapter&gt;('user');
  }
  
  Future&lt;void&gt; main() async {
      WidgetsFlutterBinding.ensureInitialized();
      ///...
      initHiveDriver();
  
      runApp(
        ProviderScope(observers: [
          Logger()
        ],
        child: MyApp()),
      );
  }
  </code></pre>
  <p>how can i create a provider for <code>Hive</code> with <code>Riverpod</code> and use it into <code>HookWidget</code>?</p>