✨ Sound effects on alert
This commit is contained in:
@@ -7,8 +7,10 @@ import 'package:gap/gap.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:island/main.dart';
|
||||
import 'package:island/models/account.dart';
|
||||
import 'package:island/pods/config.dart';
|
||||
import 'package:island/pods/notification.dart';
|
||||
import 'package:island/talker.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:top_snackbar_flutter/top_snack_bar.dart';
|
||||
@@ -241,7 +243,22 @@ bool closeTopmostOverlayDialog() {
|
||||
|
||||
const kDialogMaxWidth = 480.0;
|
||||
|
||||
Future<void> _playSfx(String assetPath, double volume) async {
|
||||
final player = AudioPlayer();
|
||||
await player.setVolume(volume);
|
||||
await player.setAudioSource(AudioSource.asset(assetPath));
|
||||
await player.play();
|
||||
await player.dispose();
|
||||
}
|
||||
|
||||
void showErrorAlert(dynamic err, {IconData? icon}) {
|
||||
final context = globalOverlay.currentState!.context;
|
||||
final ref = ProviderScope.containerOf(context);
|
||||
final settings = ref.read(appSettingsProvider);
|
||||
if (settings.soundEffects) {
|
||||
unawaited(_playSfx('assets/audio/alert.reversed.wav', 0.75));
|
||||
}
|
||||
|
||||
if (err is Error) {
|
||||
talker.error('Something went wrong...', err, err.stackTrace);
|
||||
}
|
||||
@@ -292,6 +309,13 @@ void showErrorAlert(dynamic err, {IconData? icon}) {
|
||||
}
|
||||
|
||||
void showInfoAlert(String message, String title, {IconData? icon}) {
|
||||
final context = globalOverlay.currentState!.context;
|
||||
final ref = ProviderScope.containerOf(context);
|
||||
final settings = ref.read(appSettingsProvider);
|
||||
if (settings.soundEffects) {
|
||||
unawaited(_playSfx('assets/audio/alert.wav', 0.75));
|
||||
}
|
||||
|
||||
showOverlayDialog<void>(
|
||||
builder: (context, close) => ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: kDialogMaxWidth),
|
||||
@@ -421,4 +445,4 @@ Future<void> openExternalLink(Uri url, WidgetRef ref) async {
|
||||
await launchUrl(url, mode: LaunchMode.externalApplication);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:island/pods/audio.dart';
|
||||
import 'package:island/pods/message.dart';
|
||||
import 'package:island/pods/network.dart';
|
||||
import 'package:island/services/update_service.dart';
|
||||
@@ -131,17 +130,26 @@ class DebugSheet extends HookConsumerWidget {
|
||||
const Divider(height: 8),
|
||||
ListTile(
|
||||
minTileHeight: 48,
|
||||
leading: const Icon(Symbols.play_arrow),
|
||||
leading: const Icon(Symbols.error),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 24),
|
||||
title: Text('Play untitled'),
|
||||
onTap: () async {
|
||||
final synth = MiniSampleSynth(
|
||||
sampleAsset: 'assets/audio/messages.mp3',
|
||||
baseNote: 60,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
title: const Text('Test Error Alert'),
|
||||
onTap: () {
|
||||
showErrorAlert(
|
||||
'This is a test error message for debugging purposes.',
|
||||
);
|
||||
await synth.playMidiAsset(
|
||||
'assets/midi/never-gonna-give-you-up.mid',
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
minTileHeight: 48,
|
||||
leading: const Icon(Symbols.info),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
title: const Text('Test Info Alert'),
|
||||
onTap: () {
|
||||
showInfoAlert(
|
||||
'This is a test info message for debugging purposes.',
|
||||
'Test Alert',
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user