簡體   English   中英

在 flutter 中,當我通過 model class 在其中一個選項卡屏幕中時,我在主底部導航屏幕中出現錯誤

[英]in flutter when I pass model class in one of the Tab screen I get error in main Bottom Navigation screen

我需要在提到所有標簽的 BottomNav 中傳遞什么?

這是更多選項卡,我想在小部件中傳遞我的 MODEL class:-

class More extends StatefulWidget{
final UserData currentUser; //UserData is model class
More(this.currentUser,) ;

@override
_MoreState createState() => new _MoreState();

 }

這是 BottomNav 屏幕,我在其中提到了我的所有 TAB(我在 More() 旁邊注釋了我得到錯誤的行):-

  class _BottomNavState  extends State<BottomNav> {


 int _index = 0;
 List<Widget> _items = [
 Home(),
  UserProfile(FirebaseAuth.instance.currentUser,imageList: [],currentIndex:0),
  Notifications(),
  Chat(),
  More(), /// I get error(red line below More() that I need to pass something here. What is that? So, that I can call my model class in widget.
 ];


 @override
  Widget build(BuildContext context) {

由於您聲明More小部件需要UserData作為參數,因此您必須向您的More狀態小部件提供UserData

如:

final myUserData = UserData();
//...
More(myUserData),

你已經像這樣定義了你的構造函數

More(this.currentUser);

這使得currentUser成為 position 0 處的強制positional parameter

因此,在使用 class 時,您應該像這樣強制傳遞UserData的 object,

More(UserData());

但萬一這不是強制性的,那么您需要將您的構造函數更改為此,

More({ this.currentUser });

暫無
暫無

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

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