【发布时间】:2023-03-23 18:23:01
【问题描述】:
我有我的颤振应用程序,登录后我调用共享首选项来存储一些值,例如令牌、用户 ID 等。所有这些都在 ios 和 android 上运行良好。突然现在在 ios 上,它给了我 NoSuchMethodError: The method 'setString' was called on null
这里是代码sn-p。
try {
//final jsonResponse = json.decode(responseJson);
Login login1 = new Login.fromJson(responseJson);
token = login1.token;
print(login1.fleetID);
await AuthUtils.insertDetails(_sharedPreferences, responseJson);
} catch (Err) {
print("ERrro is at" + Err.toString());
}
The whole of this function it self is async.
Below is the function where I call the to insert details.
static insertDetails(SharedPreferences prefs, var response) async {
print("Token is :"+response['token']);
print("userID is :"+response['userID']);
await prefs.setString(authTokenKey, response['token']);
await prefs.setString(userIdKey, response['userID']);
}
我已经打印了令牌和用户ID 不为空或为空。但我仍然收到 'setString' 的错误消息在 null 上被调用。但它在仅适用于 Android 的 ios 上运行良好
只是补充一下,我在下面找到了这个。
Receiver: null 尝试调用:setString("auth_token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NTc2MDAzNTcsImV4cCI6MTU1NzYwNjM1NywianRpIjoiNmExOE9CTE9m")
【问题讨论】:
-
您在 gitter 上提出了同样的问题,并在那里提供了更多详细信息。如果没有这些细节,就很难按照书面形式回答这个问题。请随时使用其他相关详细信息更新您的问题。
-
@RichardHeap 很抱歉我在这里缺少信息,但现在我收到了一个新错误,如下所示,我已在您的回答中添加了评论
标签: ios flutter sharedpreferences