Flutter [b] a jump page, use a callback method

Recently, a demand, a contact page is a directory page, b page is to add a contact page, the open a b , in order to reduce coupling, b is only responsible to get contact information by a judge for compliance, can be added . This requires a callback method to use to solve. With two kinds of solutions.
1, also circulated on the Internet, write an interface implemented by a single case manager, in a re-registration, d is invoked. ** equivalent to a global method, implemented in a, d is called. ** cause a memory leak problem, not to find out about how to solve.
https://blog.csdn.net/k741451/article/details/51615783
As my needs have particularity, directly a-> b, there is no cross-page call. It is possible to use a simpler way to deal with.

2, I'm here flutter project, with a dart to achieve.

2.1, d is defined in a callback

typedef OnCheckCallback = int Function(String phone);

2.2, instantiates

  final OnCheckCallback onCheck;

In d can be directly invoked by onCheck. If you need to return can

Navigator.pop(context, item);

2.3, in a medium

 Navigator.push(context, MaterialPageRoute(builder: (_){
              return AddEmergencyContactWidget(onCheck: (phone){
              	//业务代码,处理这个传过来的参数phone
              },);
            })).then((e) {
              if(e is EmergencyContactInfo){	//处理返回过来的item,这个info是返回的item的类型
					//业务代码
              }
            });
Published 57 original articles · won praise 3 · Views 6179

Guess you like

Origin blog.csdn.net/qq_39830579/article/details/104919531