【发布时间】:2022-03-05 20:34:11
【问题描述】:
我想将 Paricipant 类的实例传递给标签栏。我试图让List迟到,但它没有显示开头的信息(我必须转到另一个页面并返回查看)。
class MainTabBar extends StatelessWidget {
MainTabBar({Key? key, required this.userInfo}) : super(key: key);
final ParticipantInfo userInfo;
final List<ItemView> items = <ItemView>[
ItemView(title: "User", icon: Icons.account_box, view: UserProfileTab(userInfo: userInfo)),
ItemView(title: "Current State", icon: Icons.content_paste, view: CurrentStatesTab(roomNumber: userInfo.location,)),
const ItemView(title: "All data", icon: Icons.table_rows_rounded, view: AllInfoTab()),
];
@override
Widget build(BuildContext context) {......
lib/main.dart:44:85: Error: Can't access 'this' in a field initializer to read 'userInfo'.
ItemView(title: "User", icon: Icons.account_box, view: UserProfileTab(userInfo: userInfo)),
^^^^^^^^
lib/main.dart:45:100: Error: Can't access 'this' in a field initializer to read 'userInfo'.
ItemView(title: "Current State", icon: Icons.content_paste, view: CurrentStatesTab(roomNumber: userInfo.location,)),
【问题讨论】: