-1
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; 
    });
  }

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
  • I hope it helps you ... try it
    https://stackoverflow.com/a/54097327/3596519
    – Masoud Jan 16 '22 at 09:36
  • `return null;` is not a future, you can simply remove this line . – Md. Yeasin Sheikh Jan 16 '22 at 09:46
  • 1
    1. You haven't asked a question. 2. If you're asking why the `return null` line raises an analysis warning, the problem would be much more obvious if you switched to using `await` everywhere instead of using a mixture of `await` and `Future.then`. – jamesdlin Jan 16 '22 at 09:49
  • what if there is no internet connection or bad internet connection? your user will wait forever, instead you should use `try` and `catch` for `future`, and set `timeOut` – Sayyid J Jan 16 '22 at 10:15
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 26 '22 at 16:09

1 Answers1

0

i have the same problem till now

  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!);
Mohit Kushwaha
  • 1,003
  • 1
  • 10
  • 15
leenz
  • 1
  • 1