首页 > 解决方案 > 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 {
  }

标签: mysqlflutter

解决方案


您需要设置idfirst 的值。

SharedPreferences pref = await SharedPreferences.getInstance();
pref.setString('id','value you want');

推荐阅读