繁体   English   中英

如何在 sqflite flutter 中使用propper更新

[英]how to use propper update in sqflite flutter

我是 flutter 的新手,我正在尝试使用 sqflite 制作一个待办事项任务应用程序,所以一切都处于脱机状态......

我做了添加任务,一切正常,但是当它进入更新时,就像我想从 0 t 1 切换最喜欢的一样,反之亦然,我没有在网上找到任何东西..

这是我知道错误的代码:(

sql 代码:

static Future<void> updateFavorite(
      String table, Map<String, Object> data) async {
    final db = await DBHelper.database();
    db.update(
      table,
      data,
      where: 'id = ?',
      whereArgs: data['id'],
    );
  }

这是我的提供者:

void switchFavorite({
    String id,
    String title,
    String description,
    String startDate,
    String finishDate,
    int repeated,
    int completed,
    int favorite,
  }) {
    final updatedTask = Task(
      id: id,
      title: title,
      description: description,
      startDate: startDate,
      finishDate: finishDate,
      completed: completed,
      favorite: favorite,
    );
    notifyListeners();
    print(updatedTask.id);
    DBHelper.updateFavorite('user_tasks', {
      'id': updatedTask.id,
      'title': updatedTask.title,
      'description': updatedTask.description,
      'startdate': updatedTask.startDate,
      'finishdate': updatedTask.finishDate,
      'completed': updatedTask.completed ?? 0,
      'favorite': updatedTask.favorite,
    });
  }

这是我想通过按图标按钮来使用它的方式:

IconButton(
                            icon: tasks.tasks[i].favorite == 0
                                ? Icon(Icons.favorite_border)
                                : Icon(Icons.favorite),
                            onPressed: () {
                              Provider.of<TaskProvider>(
                                context,
                                listen: false,
                              ).switchFavorite(
                                id: tasks.tasks[i].id,
                                title: tasks.tasks[i].title,
                                description: tasks.tasks[i].description,
                                startDate: tasks.tasks[i].startDate,
                                finishDate: tasks.tasks[i].startDate,
                                favorite: tasks.tasks[i].favorite == 0 ? 1 : 0,
                              );
                            },
                          ),

希望你能帮助我<3 ...

这是我的错误用法:

static Future<void> updateFavorite(
      String table, Map<String, Object> data) async {
    final db = await DBHelper.database();
    db.update(
      table,
      data,
      where: 'id = ?',
      whereArgs: data['id'],
    );
  }

我应该在哪里使用whereargs: [id]以这种方式

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM