Skip to content

Instantly share code, notes, and snippets.

@gaetschwartz
Created April 9, 2021 15:46
Show Gist options
  • Save gaetschwartz/230ab0a59750f74799fa7ec2a6a4d497 to your computer and use it in GitHub Desktop.
Save gaetschwartz/230ab0a59750f74799fa7ec2a6a4d497 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void sound() => SystemSound.play(SystemSoundType.alert);
void main() {
FlutterError.onError = (e) => sound();
runZonedGuarded<void>(() => runApp(MyApp()), (e, s) => sound());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) => MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Sound on error')),
body: Center(
child: ElevatedButton(
onPressed: () => throw Exception(),
child: Text('Exception'),
)),
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment