checkIntercept method
Implementation
Future<dynamic> checkIntercept(MethodCall call) async {
var intercept = false;
String? matchUrl;
var args = Map<String, dynamic>.from(call.arguments);
var uri = Uri.parse(args['url'] as String);
if (args['url'] as String == FlutterCanary.instance.service) {
// 不拦截金丝雀域名
return await Future.value({'intercept': intercept});
}
//完全匹配
var matchMock = mockMap[uri.path];
if (matchMock == null) {
// TODO: 正则匹配
/*matchMock = mockMap.values.first(where: { (item) -> Bool in
do {
let regexStr = matchParameter(path: item.path)
let regex = try NSRegularExpression(pattern: regexStr, options: .caseInsensitive)
let count = regex.matches(in: path, options: .reportProgress, range: NSRange(location: 0, length: path.count)).count
if count > 0 {
return true
}
} catch {
print("正则匹配:\(error)")
}
return false
})*/
} else {
if (matchMock.enabled) {
var sceneid = matchMock.match(
matchMock.sceneid, Map<String, dynamic>.from(args['params']));
if (sceneid != null) {
intercept = true;
var queryStr = '?$uri.query';
matchUrl =
'${FlutterCanary.instance.service}/mock/app/scene/$sceneid$queryStr';
}
}
return Future.value({'intercept': intercept, 'url': matchUrl});
}
return Future.value({'intercept': intercept});
}