![](/img/trans.png)
[英]The Argument type 'Context' can't be assigned to the parameter type 'BuildContext' - Flutter
[英]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.