从 sharedpreferences flutter 中获取存储的数据

问题描述 投票:0回答:0

请帮帮我。我不知道这段代码有什么问题: 试图让用户密码存储在首选项中,但出现错误,这是我尝试过的代码

        'package:shared_preferences/shared_preferences.dart';

        class AuthenticationPinBloc extends Bloc<AuthenticationPinEvent, AuthenticationPinState> {
    final PINRepository pinRepository;
    isUserloggedIn() async {
      // Obtain shared preferences.
      final prefs = await SharedPreferences.getInstance();
      var passcode = prefs.getString('status');
    } 
    AuthenticationPinBloc({required this.pinRepository}) : super(const AuthenticationPinState(pinStatus: AuthenticationPINStatus.enterPIN)) {
      on<AuthenticationPinAddEvent>((event, emit) async {
        String pin = "${state.pin}${event.pinNum}";
        if(pin.length < 6){
          emit(AuthenticationPinState(pin: pin, pinStatus: AuthenticationPINStatus.enterPIN));
        }
        // get password from SharedPreferences
        else if (pin == passcode){
          print(passcode);
          emit(AuthenticationPinState(pin: pin, pinStatus: AuthenticationPINStatus.equals));

    In the line (pin == passcode) I get an error:

    print passcode also has error am new to Flutter


    will be very glad to get help
flutter variables sharedpreferences flutter-dependencies stored-functions
© www.soinside.com 2019 - 2024. All rights reserved.