早上好,我只想问一下如何获取共享首选项ID,以便能够更改密码
class _ChangePasswordState extends State<ChangePassword> {
String c1, password, c3;
final _key = new GlobalKey<FormState>();
///我想知道如何获取ID,因为我的ID未定义
save() async {
Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
SharedPreferences preferences = await _prefs;
String id = preferences.getString("id");
debugPrint(id);
final response =
await http.post('http://192.168.1.9/vessellog/changepass.php',
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, dynamic>{
'id': id,
'password': password,
}));
debugPrint(response.body);
final data = jsonDecode(response.body);
int value = data['value'];
if (value == 1) {
} else {
}
答案 0 :(得分:0)
您需要首先设置id
的值。
SharedPreferences pref = await SharedPreferences.getInstance();
pref.setString('id','value you want');