【发布时间】:2020-12-12 18:27:42
【问题描述】:
我收到以下错误消息 Bad state: No element
经过调查,我发现 notificationId 没有从一个页面流向另一个页面。
因此,如果您能帮我解决这个问题。
如果您需要我的更多信息,请告诉我。
请查看以下代码:
notification.dart
class NotificationList extends StatelessWidget {
static const routeName = 'notification-list';
void selectCategory(BuildContext ctx, int id, String title) {
print(id);
print(title);
// id and title data flowing till here
Navigator.of(ctx).pushNamed(
NotificationDetail.routeName,
arguments: {
'notificationId': id,
'Title': title,
},
);
}
main.dart
initialRoute: '/',
routes: {
'/': (ctx) => LoginMainPage(),
NotificationList.routeName: (ctx) => NotificationList(),
NotificationDetail.routeName: (ctx) => NotificationDetail(),
},
),
notificationDetail.dart
class NotificationDetail extends StatefulWidget {
static const routeName = 'notification-detail';
@override
_NotificationDetailState createState() => _NotificationDetailState();
}
class _NotificationDetailState extends State<NotificationDetail> {
@override
Widget build(BuildContext context) {
final args =
ModalRoute.of(context).settings.arguments as Map<String, dynamic>;
final notificationId = args['notificationId'];
print(notificationId); //notificationId is coming as null
final loadednotification =
Provider.of<NotificationProvider>(context, listen: false)
.findByNotificationId(notificationId);
print(loadednotification.description);
【问题讨论】:
标签: flutter