dartpub.dev DartNative · beta
plugins / native_keychain
na

native_keychain

v0.1.1 MIT

iOS Keychain storage for DartNative apps.

Store strings and bytes in the iOS Keychain with an explicit service, optional access group, and device-bound accessibility policies. Supports reading, updating, and deleting individual items through native FFI.

by tayormi/native_keychain · DartNative ≥ 3.0 · updated 4 days ago
Install
Free
pubspec.yaml
dependencies:
  native_keychain:
    hosted: https://dartpub.dev
    version: ^0.1.1
Weekly installs
1
Active apps
3
Rating
0.0 · 0
Open issues
0

native_keychain

Store tokens, passwords, and small secrets in the iOS Keychain from DartNative.

Install

Add to your DartNative app's pubspec.yaml:

dependencies:
  native_keychain:
    hosted: https://dartpub.dev
    version: ^0.1.1

Run dn pub get, then rebuild the app to link the native plugin. Use the generated plugin registrant provided by your DartNative app template.

Use

import 'package:native_keychain/native_keychain.dart';

void saveToken(String token) {
  final keychain = NativeKeychain(service: 'com.example.myapp');
  keychain.writeString('api-token', token);
  final savedToken = keychain.readString('api-token');
  if (savedToken == null) throw StateError('Token was not saved');
  // Remove it when the user signs out:
  keychain.delete('api-token');
}

Notes

  • iOS only, with a native deployment target of iOS 15+. Your DartNative SDK may require a newer OS.
  • Items default to whenUnlockedThisDeviceOnly: available while unlocked and bound to the device. Other supported accessibility policies are documented in API notes.
  • Missing keys return null. Other native failures throw KeychainException.
  • Use a stable service name. Sharing items through an access group requires matching Keychain entitlements.

Supports strings and bytes. Items do not sync through iCloud. See API notes for migration and accessibility details.

MIT license.