flutter_secure_storage icon indicating copy to clipboard operation
flutter_secure_storage copied to clipboard

Both Android options `preferencesKeyPrefix` and `sharedPreferencesName` are ignored in V10.0-beta versions.

Open FrankenApps opened this issue 8 months ago • 1 comments

I noticed that the AndroidOptions:

  • preferencesKeyPrefix
  • sharedPreferencesName

do not seem to be evaluated anymore in the V10.0-beta.x versions.

Instead the default values (VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIHNlY3VyZSBzdG9yYWdlCg and FlutterSecureStorage) are always used instead of the provided options. This can easily be reproduced with the code below:

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  const secureStorage1 = FlutterSecureStorage(
    aOptions: AndroidOptions(
      preferencesKeyPrefix: 'aPrefix',
      sharedPreferencesName: 'someName',
    ),
  );
  const secureStorage2 = FlutterSecureStorage(
    aOptions: AndroidOptions(
      preferencesKeyPrefix: 'anotherPrefix',
      sharedPreferencesName: 'anotherName',
    ),
  );

  await secureStorage1.write(key: 'testKey', value: 'someValue');

  final value = await secureStorage2.read(key: 'testKey');
  print(
    'The value read from the other secure storage (should be null): $value',
  );
  assert(
      value == null,
      'The value should be null when read from the instance with a different '
      'key prefix.');
  assert(await secureStorage2.containsKey(key: 'testKey') == false,
      'The key should not be found with a different prefix.');

  runApp(const MaterialApp(home: HomePage()));
}

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

  @override
  Widget build(BuildContext context) {
    return const Material(
      child: Center(
        child: Text('View Console.'),
      ),
    );
  }
}

The assertions are not triggered in version 9.2.4, for which reason I believe this is a bug.

This now happens in the recent beta versions, because the initSecureStorage method does not overwrite the secureStorage variable even if the options are different.

I am willing to fix this in a PR, just trying to make sure upfront, that this is not expected behavior (in which case the documentation should probably be updated instead).

The full sample may also be found on my forked repo.

FrankenApps avatar Mar 26 '25 18:03 FrankenApps

⚠️ This issue has been marked as stale because it has been open for 60 days with no activity.

If this issue is still relevant, please comment to keep it active. Otherwise, it will be closed in 60 days.

github-actions[bot] avatar May 26 '25 03:05 github-actions[bot]

❌ This issue has been closed because it remained inactive for 60 days after being marked as stale.

github-actions[bot] avatar Jul 25 '25 03:07 github-actions[bot]