未处理的异常:使用不包含导航器的上下文请求导航器操作

时间:2020-12-27 12:28:03

标签: android ios flutter dart

我正在处理 main.dart 文件中的通知点击,但是每当我尝试在函数内使用 Navigator.push 时,它都会给我这个错误:

Unhandled Exception: Navigator operation requested with a context that does not include a Navigator.

这是我的代码:

class PushNotificationService {
  Future<dynamic> onSelectNotification(BuildContext context, String orderID) async {
    print("xxxxxxxxxx ${orderID}");
    NewOrderModel newOrderModel = NewOrderModel(
      id:orderID,
      // distance: item['distance'],
      // status: item['status'],
      // date_time: item['date_time']
    );
    await ApiServices()
        .fetchNewOrders(context, newOrderModel.id)
        .then((secondResp) {
      print('sec $secondResp');
      newOrderModel.estimated_delivery_time = secondResp['data']['estimated_delivery_time'];
      newOrderModel.fee = secondResp['data']['driver_fee'];
      newOrderModel.lat = secondResp['data']['address']['lat'];
      newOrderModel.lng = secondResp['data']['address']['lng'];
      newOrderModel.address = secondResp['data']['address']['address'];
      newOrderModel.addressNote =
      secondResp['data']['address']['address_notes'];
      // newOrderModel.driverID = driverID;
      newOrderModel.name = secondResp['data']['name'];
      newOrderModel.mobile = secondResp['data']['mobile'];
      newOrderModel.order_notes = secondResp['data']['order_notes'];

    });
    Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) {
      return NewOrder(theNewOrder: newOrderModel);

    }));
    /*Do whatever you want to do on notification click. In this case, I'll show an alert dialog*/
  }

这段代码在我的 class MyApp extends StatefulWidget { 类中,在 main.dart 文件中。

0 个答案:

没有答案