【问题标题】:'Future' is from 'dart:async'. return null;“未来”来自“飞镖:异步”。返回空值;
【发布时间】:2022-01-16 09:21:22
【问题描述】:
Future insertToDatabase({
    required String title,
    required String data,
    required String time,
  }) async {
    return await database.transaction((txn) {
      txn
          .rawInsert(
              'INSERT INTO tasks(title, date, time, status) VALUES("$title","$data","$time","new")')
          .then((value) {
        print('$value inserted Done !!');
      }).catchError((err) {
        print('error insert to tables ${err.toString()}');
      });
      return null; 
    });
  }

【问题讨论】:

  • 希望对你有帮助...试试看
    stackoverflow.com/a/54097327/3596519
  • return null; 不是未来,你可以简单地删除这一行。
  • 1.你没有问过问题。 2. 如果你问为什么return null 行会引发分析警告,如果你改用await,而不是混合使用awaitFuture.then,问题会更加明显。跨度>
  • 如果没有互联网连接或互联网连接不良怎么办?您的用户将永远等待,而您应该使用trycatchfuture,并设置timeOut
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: flutter dart mobile dart-null-safety


【解决方案1】:

到现在我也有同样的问题

  insertToDatabase({
    required String title,
    required String time,
    required String date,
  }) async {
    await database?.transaction((txn) {
      txn
          .rawInsert(
              'INSERT INTO tasks (title , date , time , status) VALUES ("$title $time" , "$date" , "new")')
          .then((value) {
        print('$value inserted successfully');
        emit(AppInsertDatabaseState());
        getDataFromDatabase(database);
      }).catchError((error) {
        print('Error When Inserting  new Records ${error.toString()}');
      });
      //throw Exception('Result unexpectedly null');
      print(null!);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-27
    • 2019-06-25
    • 1970-01-01
    • 2019-10-28
    • 2019-03-11
    • 2021-11-28
    • 2020-11-28
    相关资源
    最近更新 更多