> For the complete documentation index, see [llms.txt](https://triyono.gitbook.io/fluttercheatsheet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://triyono.gitbook.io/fluttercheatsheet/my-note/error-userfriendly.md).

# Error UserFriendly

There is a little [static error builder](https://api.flutter.dev/flutter/widgets/ErrorWidget/builder.html) hidden in the documentation.

> When an error occurs while building a widget, the broken widget is replaced by the widget returned by this function. By default, an ErrorWidget is returned.

You can define in the the `builder` method of the MaterialApp widget.

```dart
 Widget buildError(BuildContext context, FlutterErrorDetails error) {
   return Scaffold(
     body: Center(
       child: Text(
         "Error appeared.",
         style: Theme.of(context).textTheme.title,
       ),
     )
   );
 }

 class MyApp extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     return MaterialApp(
       theme: ThemeData(
         primarySwatch: Colors.blue,
       ),
       builder: (BuildContext context, Widget widget) {
         ErrorWidget.builder = (FlutterErrorDetails errorDetails) {
           return buildError(context, errorDetails);
         };

         return widget;
       },
       title: 'Flutter Demo',
       home: MyHomePage(title: 'Flutter Demo Home Page'),
     );
   }
 }
```

[![Before and after](https://i.stack.imgur.com/pvovt.png)](https://i.stack.imgur.com/pvovt.png)
