Flutter 解决release不能使用的问题

李星波
2023-12-01

release包出现SharedPreferences插件丢失的问题,登录不了

Unhandled Exception: MissingPluginException(No implementation found for meth

然后把吐司的方法放到SharedPreferences前面加可以了

  if (httpRes.code == 200) {
      Fluttertoast.showToast(
          msg: "登录成功",
          toastLength: Toast.LENGTH_SHORT,
          gravity: ToastGravity.BOTTOM,
          timeInSecForIosWeb: 10,
          backgroundColor: Colors.white,
          textColor: Colors.black,
          fontSize: 16.0);

      //数据缓存写入token值
      SharedPreferences prefs = await SharedPreferences.getInstance();
      await prefs.setString('token', httpRes.data.token);
      await prefs.setInt('userId', httpRes.data.userId);
      await prefs.setString('phone', _userPhoneController.text);
      await prefs.setString('password', _userPassWordController.text);

      //登录成功后进入主界面
      Navigator.pushAndRemoveUntil(
        context,
        MaterialPageRoute(builder: (context) => const MusicPlayer()),
        (route) => route == null,
      );
    }
 类似资料: