flutter_secure_storage icon indicating copy to clipboard operation
flutter_secure_storage copied to clipboard

Windows Error

Open Aggie85 opened this issue 1 year ago • 2 comments

After a recent upgrade of flutter_securre_storage, I keep getting the following error under Windows...

Launching lib\main.dart on Windows in debug mode... √ Built build\windows\runner\Debug\sandis_list.exe. Connecting to VM Service at ws://127.0.0.1:49857/9uCr3Nyrbfs=/ws flutter: Failed to decrypt data: Error 0x00000000: Failure on CryptUnprotectData() Delete corrupt file: c:\users\shane\appdata\roaming\tanstaaflsoftware\sandis_list\flutter_secure_storage.dat [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Error 0x00000000: Failure on CryptUnprotectData() #0 DpapiJsonFileMapStorage.load. (package:flutter_secure_storage_windows/src/flutter_secure_storage_windows_ffi.dart:234:11) #1 using (package:ffi/src/arena.dart:124:31) #2 DpapiJsonFileMapStorage.load (package:flutter_secure_storage_windows/src/flutter_secure_storage_windows_ffi.dart:209:19) #3 FlutterSecureStorageWindows.readAll (package:flutter_secure_storage_windows/src/flutter_secure_storage_windows_ffi.dart:113:17) #4 AppPreferencesFlutterSectureStorage.readAll (package:sandis_list/app_preferences_flutter_secure_storage.dart:50:12) #5 AppGlobalObjects.initialize (package:sandis_list/app_global_objects.dart:108:10) #6 main (package:sandis_list/main.dart:48:3)

I haven't changed this part of my code in almost 6 months!

Any idea on how to fix or what could have changed?

All the best,

Aggie85

Aggie85 avatar Sep 01 '23 22:09 Aggie85

This error is caused by multiple writes to the storage.

Сode example to reproduce the error (need to quickly scroll the list):

import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

late final FlutterSecureStorage storage;

void main() {
  storage = const FlutterSecureStorage();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    var controller = ScrollController();
    controller.addListener(
      () => storage.write(key: "key", value: "${controller.offset}"),
    );

    return MaterialApp(
      title: 'Scroll quickly to see the bug.',
      home: Scaffold(
        body: ListView(
          controller: controller,
          children: [for (int i = 0; i < 100; i++) Text("$i")],
        ),
      ),
    );
  }
}

ReinRaus avatar Oct 18 '23 20:10 ReinRaus

This error is caused by multiple writes to the storage.

Сode example to reproduce the error (need to quickly scroll the list):

import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

late final FlutterSecureStorage storage;

void main() {
  storage = const FlutterSecureStorage();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    var controller = ScrollController();
    controller.addListener(
      () => storage.write(key: "key", value: "${controller.offset}"),
    );

    return MaterialApp(
      title: 'Scroll quickly to see the bug.',
      home: Scaffold(
        body: ListView(
          controller: controller,
          children: [for (int i = 0; i < 100; i++) Text("$i")],
        ),
      ),
    );
  }
}

@mogol plz fix asap

stan-at-work avatar Oct 31 '23 11:10 stan-at-work

I am closing all older issues. If this issue still exists in the latest version, please let me know.

juliansteenbakker avatar Aug 13 '24 20:08 juliansteenbakker