keychain 0.0.7

keychain #

A simple class that can be extended to create a type safe, cached store for passwords, api keys, etc.

The first time an extended Keychain class is initiated, the keys are obtained based on how they are created and then cached for future instances of the extended Keychain class.

This package uses dart:io and is intended for command line / server applications although there is a KeychainLight class that currently only supports String keys (see below).

shell (set an environment variable)



  "object": {
    "key": "aJsonVar"


  "object": {
    "anotherKey": "anotherJsonVar"


import "package:keychain/keychain.dart"

class Keys extends Keychain {

  final String str = Keychain.fromString('aString');
  final String env = Keychain.fromEnv('ENV_VAR');
  final String json = Keychain.fromJsonFile('key', 'project/secrets/keys.json');
  final Future<String> resource = Keychain.fromJsonResource('anotherKey', 'package:this_package/secrets/keys.json');


void main() {
  var keys = Keys();
  print(keys.str); // aString
  print(keys.env); // anEnvVar
  print(keys.json); // aJsonVar
  print(await keys.resource); // anotherJsonVar

The path for a json file must start with a directory on the path to the running script. For example, if the script is at /home/path/to/project/lib/bin/main.dart, you should put the json file somewhere along this path such as /home/path/to/project/secrets/keys.json (there needs to be one overlapping directory). This file can then be included in the extended class as in the example above ('project/secrets/keys.json' -> project is the overlapping directory).

KeychainLight does not import dart:io but therefore only supports String keys currently. To use KeychainLight:

import 'package:keychain/keychain_light.dart'

class Keys extends KeychainLight {
  final String str = KeychainLight.fromString('aString');

void main() {
  var keys = Keys();
  print(keys.str); // aString

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  keychain: ^0.0.7

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:keychain/keychain.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health issues and suggestions

Document public APIs. (-1 points)

14 out of 14 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/keychain.dart. (-2.96 points)

Analysis of lib/src/keychain.dart reported 6 hints, including:

line 2 col 28: The name utf8 is shown, but not used.

line 12 col 8: Duplicate import.

line 22 col 55: Use = to separate a named parameter from its default value.

line 30 col 71: Use = to separate a named parameter from its default value.

line 57 col 74: Use = to separate a named parameter from its default value.

Fix lib/src/keychain_light.dart. (-0.50 points)

Analysis of lib/src/keychain_light.dart reported 1 hint:

line 6 col 58: Use = to separate a named parameter from its default value.

Format lib/keychain.dart.

Run dartfmt to format lib/keychain.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/keychain_light.dart (Run dartfmt to format lib/keychain_light.dart.)
  • lib/src/keychain_cache.dart (Run dartfmt to format lib/src/keychain_cache.dart.)
  • lib/src/keychain_exception.dart (Run dartfmt to format lib/src/keychain_exception.dart.)

Maintenance issues and suggestions

Provide a file named (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

The package description is too short. (-12 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and keychain.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
bottom_line >=0.0.3 <0.1.0 0.0.4
resource ^2.1.6 2.1.6
Transitive dependencies
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
typed_data 1.1.6
uuid 2.0.4
Dev dependencies
test ^1.6.8