【发布时间】:2020-10-21 06:56:39
【问题描述】:
我在这段代码中遇到了一些问题。一开始只有邮箱和密码,
login() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final response = await http.post(
"https://api.batulimee.com//v1_ship/login_app",
body:{
"email": email,
"password": password,
"apikey": apikey,
}),
);
final data = jsonDecode(response.body);
String status = data['status'];
String pesan = data['message'];
if (status == "success") {
prefs.setString('stringValue', "apikey");
Navigator.of(context).pushReplacement(PageRouteBuilder(
pageBuilder: (_, __, ___) => new bottomNavBar(),
transitionDuration: Duration(milliseconds: 600),
transitionsBuilder:
(_, Animation<double> animation, __, Widget child) {
return Opacity(
opacity: animation.value,
child: child,
);
}));
print(pesan);
print(apikey);
} else {
print(pesan);
}
}
当我添加 apikey 变量然后尝试登录时,出现这样的错误。
Exception has occurred. NoSuchMethodError (NoSuchMethodError: The getter 'length' was called on null. Receiver: null Tried calling: length)
我应该怎么放那个apikey?
【问题讨论】:
-
是“url”只是您在此处共享的代码 sn-p 中的占位符。如果 url 是变量,请去掉引号。