// Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Template: dev/snippets/config/templates/freeform.tmpl // // Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring // of samples, and may be ignored if you are just exploring the sample. // Flutter code sample for ErrorWidget // //*************************************************************************** //* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) // //* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) //*************************************************************************** //******************************************************************** //* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) import 'package:flutter/material.dart'; void main() { ErrorWidget.builder = (FlutterErrorDetails details) { bool inDebug = false; assert(() { inDebug = true; return true; }()); // In debug mode, use the normal error widget which shows // the error message: if (inDebug) { return ErrorWidget(details.exception); } // In release builds, show a yellow-on-blue message instead: return Container( alignment: Alignment.center, child: const Text( 'Error!', style: TextStyle(color: Colors.yellow), textDirection: TextDirection.ltr, ), ); }; // Here we would normally runApp() the root widget, but to demonstrate // the error handling we artificially fail: return runApp(Builder( builder: (BuildContext context) { throw 'oh no, an error'; }, )); } //* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) //********************************************************************