better_sound_effect 0.0.2 copy "better_sound_effect: ^0.0.2" to clipboard
better_sound_effect: ^0.0.2 copied to clipboard

PlatformAndroidiOS
outdated

A Sound Effect Player for Flutter.

example/lib/main.dart

import 'dart:async';

import 'package:better_sound_effect/better_sound_effect.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final soundEffect = BetterSoundEffect();

  int? soundId;

  @override
  void initState() {
    super.initState();

    Future.microtask(() async {
      soundId = await soundEffect.loadAssetAudioFile("assets/button.wav");
    });
  }

  @override
  void dispose() {
    if (soundId != null) {
      soundEffect.release(soundId!);
    }
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: CupertinoButton(
            child: Text("click"),
            onPressed: () {
              if (soundId != null) {
                soundEffect.play(soundId!);
              }
            },
          ),
        ),
      ),
    );
  }
}
3
likes
120
pub points
59%
popularity

Publisher

unverified uploader

A Sound Effect Player for Flutter.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on better_sound_effect