drift_sounds_cli 0.0.1 copy "drift_sounds_cli: ^0.0.1" to clipboard
drift_sounds_cli: ^0.0.1 copied to clipboard

The command line client for drift_sounds.

drift_sounds_cli #

Description #

This package allows you to generate code and a database file from a directory of sound files.

Usage #

First, activate the dsc command:

dart pub global activate drift_sounds_cli

$ dsc -h
drift_sounds_cli
Add all sounds in a directory to a database and generate code.
-s, --sounds                   The directory where sounds will be loaded from.
                               (defaults to "sounds\")
-d, --database-file            The file where the database will be written.
                               (defaults to "assets/sounds.sqlite3")
-c, --code-file                The file where code will be written.
                               (defaults to "lib/sounds.gen.dart")
-n, --class-name               The name of the generated sounds class.
                               (defaults to "Sounds")
-e, --sound-file-extensions    The file extensions which qualify files as sound files.
                               (defaults to ".wav", ".mp3", ".ogg")
-h, --[no-]help                Show help for the command.

logging
-q, --[no-]quiet               Whether logging should be quiet.
-v, --[no-]verbose             Whether logging should be verbose.

Next, add the assets directory to your pubspec.yaml file:

flutter:
  uses-material-design: true
  assets:
    - assets/

use the fluttergen command to generate the Assets class:

fluttergen

Now, you can place an instance of DriftSoundsDatabaseScope at the top of your widget tree:

import 'package:drift_sounds/drift_sounds.dart';
import 'package:flutter/material.dart';
import 'gen/assets.gen.dart';

void main() {
  runApp(const MyApp());
}

/// The top-level app widget.
class MyApp extends StatelessWidget {
  /// Create an instance.
  const MyApp({super.key});

  /// Build the widget.
  @override
  Widget build(final BuildContext context) => SoLoudScope(
    child: DriftSoundsDatabaseScope(
      assetKey: Assets.sounds,
      child: MaterialApp(
        ...
      ),
    ),
  );
}

Anywhere you need access to a Sounds instance, you can use the BuildContext.sounds extension getter, or DriftSoundsDatabaseScope.of static method.