本文主要是介绍flutter 一段代码优化抽离公共部分,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
优化前
var params;if (isSetPwd == true) {if (accountType == "email") {params = {"key": key,"validateCode": validateCode,"type": type};}else{params = {"key": key,"zone": zone.replaceAll("+", ""),"validateCode": validateCode,"type": type};}} else {if (accountType == "email") {params = {"key": key,"password": password,"validateCode": validateCode,"type": type};}else{params = {"key": key,"password": password,"zone": zone.replaceAll("+", ""),"validateCode": validateCode,"type": type};}}
优化后
var params = {
“key”: key,
“validateCode”: validateCode,
“type”: type
};
if (accountType != “email”) {
params[“zone”] = zone.replaceAll(“+”, “”);
}
if (!isSetPwd) {
params[“password”] = password;
}
这篇关于flutter 一段代码优化抽离公共部分的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!