mysql - Flutter 使用共享首选项更改密码
问题描述
美好的一天,我只是想问一下如何获得 sharepreferences 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 {
}
解决方案
您需要设置id
first 的值。
SharedPreferences pref = await SharedPreferences.getInstance();
pref.setString('id','value you want');
推荐阅读
- javascript - 遍历数组中的 API 调用(GAS/Javascript)
- c - 针对零验证 CRC 校验和
- java - 为什么在while循环中跳过第一条语句?
- phpspreadsheet - 如何为 PHP 电子表格生成的 Excel 文件添加边框
- python - 如何在不使用 cron 作业的情况下刷新(索引)天蓝色搜索服务,最近在 Blob 容器中上传的文件
- python - 如何在python中打印属性。它是打印位置。但我需要打印“25”
- css - wordpress 菜单中的 CSS 类不起作用
- sql - 在 T SQL 中的我的日期列上获取时间戳 23:59:59
- mysql - SQL、主键、外键和表
- ios - 有没有办法在 SwiftUI 中制作 List 样式 insetGrouped?