Click here to Skip to main content
15,666,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On this code, i try to create Delete features, which is can delete history/data that already added.

Here's the code :

menuOption(String value, History history) async {
   if (value == 'update') { => UpdateHistoryPage(
         date:!, idHistory: history.idHistory!))?.then((value) {
       if (value ?? false) {
   } else if (value == 'delete') {
     bool yes = await DInfo.dialogConfirmation(
         context, 'Hapus', 'Yakin untuk menghapus history ini ?',
         textNo: 'Batal', textYes: 'Ya');
     if (yes) {
       bool success = await SourceHistory.delete(history.idHistory!);
       if (success) refresh();

The error :
Error: A value of type 'bool?' can't be assigned to a variable of type 'bool' because 'bool?' is nullable and 'bool' isn't.
      bool yes = await DInfo.dialogConfirmation(

What I have tried:

Nothing i can do, so still error
Updated 15-Mar-23 19:42pm

1 solution

Thee error message is pretty explicit: the function returns a nullable value - bool? - and you are trying to store it in a non-nullable type - bool; the types are not the same.

The simplest solutions are to change the type of yes to bool?, or change the return value of dialogConfirmation to bool

There are other ways, but they are more complicated:[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900