1

I have created an app using SQFlite plugin for Flutter. Everything works fine on iOS and most Android phones, yet I have one tester who was experiencing some very bizarre behaviour on his OnePlus device, specifically a OnePlus 5 running OxygenOS 9.0.1). Apparently the database remained after uninstalling the app (would load old data), then it "sometimes saves and sometimes doesn't".

What follows is the code I used to create the database:

  _initDatabase() async {
    Directory documentsDirectory = await getApplicationDocumentsDirectory();
    String path = join(documentsDirectory.path, _databaseName);
    return await openDatabase(path,
        version: _databaseVersion, onCreate: _onCreate);
  }

This is the _onCreate() method:

  Future _onCreate(Database db, int version) async {
    await db.transaction((txn) async {
      await txn.execute('''
              CREATE TABLE $tableCharacters (
                $columnCharacterId INTEGER PRIMARY KEY,
                $columnCharacterName TEXT NOT NULL
              )''');
      await txn.execute('''
              CREATE TABLE $tablePerks (
                $columnPerkId INTEGER PRIMARY KEY,
                $columnPerkClass TEXT NOT NULL,
                $columnPerkDetails TEXT NOT NULL
              )''').then((_) async {
        for (Perk perk in perkList) {
          for (int i = 0; i < perk.numOfPerks; i++) {
            int id = await txn.insert(tablePerks, perk.toMap());
            print("ID: " +
                id.toString() +
                " : " +
                perk.perkClassCode +
                " : " +
                perk.perkDetails);
          }
        }
      });
      await txn.execute('''
              CREATE TABLE $tableCharacterPerks (
                $columnAssociatedCharacterId INTEGER,
                $columnAssociatedPerkId INTEGER,
                $columnCharacterPerkIsSelected BOOLEAN
              )''');
    });
  }

My question is: is there anything wrong with this method that could solve my issue with OnePlus devices? Is there something I can do to ensure it will install properly on these phones? I have over 6k active users so I definitely want to keep this release airtight.

Thank you.

Garrison
  • 99
  • 1
  • 9

0 Answers0