setPrefix static method

void setPrefix(
  1. String prefix, {
  2. Set<String>? allowList,
})

Sets the prefix that is attached to all keys for all shared preferences read or written via this class.

This changes the inputs when adding data to preferences as well as setting the filter that determines what data will be returned from the getInstance method.

By default, the prefix is 'flutter.', which is compatible with the previous behavior of this plugin. To use preferences with no prefix, set prefix to ''.

If prefix is set to '', you may encounter preferences that are incompatible with shared_preferences. The optional parameter allowList will cause the plugin to only return preferences that are both contained in the list AND match the provided prefix.

No migration of existing preferences is performed by this method. If you set a different prefix, and have previously stored preferences, you will need to handle any migration yourself.

This cannot be called after getInstance.

Implementation

static void setPrefix(String prefix, {Set<String>? allowList}) {
  if (_completer != null) {
    throw StateError('setPrefix cannot be called after getInstance');
  }
  _prefix = prefix;
  _prefixHasBeenChanged = true;
  _allowList = allowList;
}