【解決方法】エラーブールフラッターを取得しました


このコードでは、既に追加された履歴/データを削除できる削除機能を作成しようとしています。

コードは次のとおりです。

menuOption(String value, History history) async {
   if (value == 'update') {
     Get.to(() => UpdateHistoryPage(
         date: history.date!, idHistory: history.idHistory!))?.then((value) {
       if (value ?? false) {
         refresh();
       }
     });
   } 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();
     }
   }
 }

エラー :

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(

私が試したこと:

何もできないので、まだエラー

解決策 1

あなたのエラーメッセージはかなり明白です:関数はnull許容値を返します- bool? -そして、それをnull不可の型に保存しようとしています- bool; タイプは同じではありません。

最も簡単な解決策は、型を変更することです yesbool?、またはの戻り値を変更します dialogConfirmationbool

他にも方法はありますが、より複雑です。 https://stackoverflow.com/questions/67246851/in-dart-given-the-nullable-type-t-how-do-i-get-the-non-nullable-one-t[^]

コメント

タイトルとURLをコピーしました