title: SQFLITE ERROR: SqfliteDatabaseException (DatabaseException(database_closed))
body: <p>The two pages in the application are listed with database(sqlite). but when I want to switch between pages, I get such an error: SqfliteDatabaseException (DatabaseException(database_closed))</p>
  <p>please help mee.. I don't understand why see this error.</p>
  <pre><code>import 'dart:async';
  import 'dart:io';
  import 'dart:typed_data';
  import 'package:bankingapp/models/coin.dart';
  import 'package:bankingapp/models/histories.dart';
  import 'package:flutter/services.dart';
  import 'package:sqflite/sqflite.dart';
  import 'package:path/path.dart';
  
  class DbHelper {
    static Database? _db;
  
    Future&lt;Database&gt; get db async {
      return _db ??= await initDb();
    }
  
    Future&lt;Database&gt; initDb() async {
      var dbFolder = await getDatabasesPath();
      String path = join(dbFolder, 'app.db');
  
      // Delete any existing database:
      await deleteDatabase(path);
  
      // Create the writable database file from the bundled demo database file:
      try {
        await Directory(dirname(path)).create(recursive: true);
      } catch (_) {}
      ByteData data =
          await rootBundle.load(join(&quot;assets/database&quot;, &quot;bankingapp.db&quot;));
      List&lt;int&gt; bytes =
          data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
      await new File(path).writeAsBytes(bytes, flush: true);
  
      //open the database
      return await openDatabase(path);
  
    }
  
    Future&lt;List&lt;Histories&gt;&gt; getHistories() async {
      var dbClient = await db;
      var result = await dbClient.rawQuery(&quot;SELECT * FROM Histories&quot;);
      return result.map((data) =&gt; Histories.fromMap(data)).toList();
    }
  
    Future&lt;List&lt;Coins&gt;&gt; getCoins() async {
      var dbClient = await db;
      var result = await dbClient.rawQuery(&quot;SELECT * FROM Coins&quot;);
      return result.map((data) =&gt; Coins.fromMap(data)).toList();
    }
  }
  </code></pre>