Created
April 9, 2021 15:46
-
-
Save gaetschwartz/230ab0a59750f74799fa7ec2a6a4d497 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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