0

我有一个复杂的模型,无法使用 Sqflite (Flutter) 将它们保存在本地。

我能够将基本模型保存在 db 上。但我救不了别人。

我试着这样做。(视频有多个数据)


    int res = await dbClient.insert("$tableName", game.toMap());
        for (var i = 0; i < object.videos.length; i++) {
          Video expectedList = Video.map(object.videos[i]);
          int res2 = await dbClient.insert("video", expectedList.toMap());
    }

这是基本模型;


   int versionParent;
     double popularity;
     String key;
     String versionTitle;
     dynamic keywords = List<Keyword>();
     dynamic videos = List<Video>();
     dynamic genres = List<Genres>();

这是模型上的地图功能;


 var map = Map<String, dynamic>();
     map['genres'] = genres;
     map['id'] = id;
     map['keywords'] = keywords;
     map['key'] = key;
     map['versionTitle'] = versionTitle;
     map['popularity'] = popularity;
     map['videos'] = videos;
     return map;
   }

这是动态列表文件模型之一;


    int _id;
      int _game;
      String _name;
      String _videoId;
      Map<String, dynamic> toMap() {
        var map = Map<dynamic, dynamic>();
        map['id'] = id;
        map['game'] = game;
        map['name'] = name;
        map['video_id'] = videoId;
        return map;
      }

这是我创建的表(我为所有动态列表创建表)


    await db.execute('CREATE TABLE $tableName(id INTEGER PRIMARY KEY,hypes INTEGER, updatedAt INTEGER, pulseCount INTEGER, coverCoverId INTEGER, versionParent INTEGER, popularity INTEGER, firstReleaseDate INTEGER, key TEXT , url TEXT, name TEXT, slug TEXT, summary TEXT, imageCoverId TEXT, versionTitle TEXT)');
        await db.execute(
            'CREATE TABLE video(id INTEGER PRIMARY KEY, game INTEGER, name TEXT, videoId TEXT)');

4

0 回答 0