Skip to content

Instantly share code, notes, and snippets.

@devoncarew
Last active February 18, 2023 17:13
Show Gist options
  • Select an option

  • Save devoncarew/a7620dea65d3edfd9f4b2fbfcd3ed5fc to your computer and use it in GitHub Desktop.

Select an option

Save devoncarew/a7620dea65d3edfd9f4b2fbfcd3ed5fc to your computer and use it in GitHub Desktop.

directories.dart

Hi! todo: library docs.

Class AppDirs

abstract class AppDirs

The directory locations for the current platform's conventions. This class factors in information like the application and company name.

baseDirs

final BaseDirs baseDirs

The base directories backing this [AppDirs] instance.

AppDirs()

AppDirs({BaseDirs baseDirs})

get cache

String get cache

todo: doc

get config

String get config

todo: doc

get data

String get data

todo: doc

get dataLocal

String get dataLocal

todo: doc

get preference

String get preference

todo: doc

get state

String? get state

todo: doc

Class BaseDirs

abstract class BaseDirs

The base directories for the current platform. These are the standard directories for the platform's conventions, but without taking into account things like the application name.

For directory locations that take application name into account, see [Directories.getAppDirectories] and [AppDirs].

BaseDirs()

BaseDirs()

get home

String get home

The user's home directory. On Unix like systems, this will be $HOME. On Windows, this will be $USERPROFILE.

get cache

String get cache

todo: doc

get config

String get config

todo: doc

get data

String get data

todo: doc

get dataLocal

String get dataLocal

todo: doc

get preference

String get preference

todo: doc

get state

String? get state

todo: doc

Class Directories

class Directories

todo: doc including base and getAppDirs

baseDirs

final BaseDirs baseDirs

The base directories for the current platform. These are the standard directories for the platform's conventions, but without taking into account things like the application name.

Most applications should instead use [Directories.getAppDirectories] to locate directories. That will take in account things like the application and organization name, and will locate directories using the platform's conventions.

Directories()

Directories({Map<String, String>? env, OperatingSystem? os})

Create a new [Directories] instance.

The [env] and [os] parameters allow you to override the system defaults. This is generally only useful for testing.

appDirs()

AppDirs appDirs({
  String? qualifier,
  String? organization,
  String application,
  bool preferUnixConventions = false,
})

The directory locations for the current platform's conventions. This factors in information like the application and company name.

The [application], [qualifier] and [organization] information is used to construct the correct app path. For instance, in Unix that path might be 'foobar-app', on Windows 'Baz Corp/Foo Bar App' and on MacOS 'org.Baz-Corp.Foo-Bar-App'.

The [preferUnixConventions] param is used to configure the MacOS directory conventions used. This library defaults to the standard Mac conventions - an app's config directory may look something like ~/Library/Application support/org.Baz-Corp.Foo-Bar-App. However, for some apps - like command-line tools - a Unix convention may be more familiar to users. Specify preferUnixConventions: true to use thos conventions instead (the above path may then look something like ~/.config/foobar-app).

toString()

String toString()

Enum OperatingSystem

enum OperatingSystem

The operating system to assume for directory conventions; passed as a param to [Directories].

value unix

OperatingSystem unix

Unix-like operating systems (like Linux).

value windows

OperatingSystem windows

Windows.

value mac

OperatingSystem mac

MacOS.

OperatingSystem()

OperatingSystem()

detect()

static OperatingSystem detect()

Return the correct [OperatingSystem] enum for the current platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment