Flutter 如何使用颤振中的onTap导航到其他屏幕

Flutter 如何使用颤振中的onTap导航到其他屏幕,flutter,dart,Flutter,Dart,当用户点击警报对话框中的按钮时,我试图将用户导航到另一个屏幕,因此我用inkwell包装容器,然后使用onTap()和navigator push replacement: onTap: (){ Navigator.pushReplacement( context,MaterialPageRoute(builder: (context) => Subscription ()),); } 但这给了我一个错误:error:3个

当用户点击警报对话框中的按钮时,我试图将用户导航到另一个屏幕,因此我用inkwell包装容器,然后使用onTap()和navigator push replacement:

onTap: (){
           Navigator.pushReplacement(
           context,MaterialPageRoute(builder: (context) => Subscription ()),);
          } 
但这给了我一个错误:error:
3个位置参数,但找到了0。

墨水池全块()

订阅类别:

    class Subscription extends StatefulWidget {
  final bool isPaymentSuccess;
  final User currentUser;
  final Map items;
  Subscription(this.currentUser, this.isPaymentSuccess, this.items);

  @override
  _SubscriptionState createState() => _SubscriptionState();
}

您需要通过导航传递YRU参数,如下所示:


onTap:(){
Navigator.pushReplacement(
  context,MaterialPageRoute(builder: (context) => Subscription (true, currentUser,items) //here pass the actual values of these variables, for example false if the payment isn't successfull..etc
),);
} 

订阅页有3个参数需要传入

您需要为其传递值

Final bool ispaymentSuccess;
Final User currentUser;
Final Map items;
这就是为什么会出现错误

为了更好的用户体验。。。 给所有订阅构造函数@required,这样当您想要导航到页面时,它将要求您传入这些值

像这样

Subscription({@required this.isPaymentSuccess, @required this.items, @required this.currentUser});
Subscription({@required this.isPaymentSuccess, @required this.items, @required this.currentUser});