【问题标题】:Receiving error message Bad state: No element收到错误消息坏状态:没有元素
【发布时间】: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


    【解决方案1】:

    我认为“args['notificationId']”会是“args['Id'];”?

    【讨论】:

    • 抱歉,代码中有错字...但问题仍然存在
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多