簡體   English   中英

參數類型“Context”不能分配給參數類型“BuildContext”。 For 循環和按鈕

[英]The argument type 'Context' can't be assigned to the parameter type 'BuildContext'. For Loop and Button

我正在嘗試在 for 循環中創建一個按鈕,因為該循環連接到主 dart。 Everything else is running fine but then I try to put in the raisebutton I seem to get these errors depending on the dart package I am using stating: package:path/path.dart Context context Type: Context
系統路徑上下文。 這與使用 new Context 創建的上下文不同,因為它的 Context.current 始終是當前工作目錄,而不是在創建上下文時設置一次。

或者

dart:js JsObject 獲取上下文
JavaScript 全局 object,通常是 window。

我不知道我做的對不對,請幫忙。

在此處輸入圖像描述

這是我的主要 dart 的一部分,其中 for 循環假設為 go 內部,因為 for 循環位於不同的 dart 文件中

在此處輸入圖像描述

我不確定您為什么經常實例化MyMenu或為什么要將MyMenu實例變量傳遞給MyMenu實例方法。 您可能想尋找一種更好的方式來構建您的代碼。

但要回答您的問題,您無法訪問MyMenu class 中的當前BuildContext 最快的補救措施:將BuildContext作為參數傳遞給buildMenuItemsList

buildMenuItemsList(Section section, BuildContext context) { ... }

MyMenu().buildMenuItemsList(MyMenu().getSections()[index], context),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM