-
Notifications
You must be signed in to change notification settings - Fork 28.6k
ErrorWidget.builder not working on profile/release #109382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @zmtzawqlp, Thanks for filing the issue. I am able to reproduce the issue. Looks like the error is not being reporte. When the exception occurs in release mode code sample (works)import 'package:flutter/material.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
ErrorWidget.builder = (FlutterErrorDetails details) {
return Material(
child: Container(
color: Colors.purple,
alignment: Alignment.center,
child: const Text(
'Something went wrong!',
style: TextStyle(fontSize: 20, color: Colors.white),
),
),
);
};
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
throw 'Something went wrong!';
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Column(children: <Widget>[
Positioned(
child: Container(
height: 10,
width: 10,
color: Colors.red,
))
]),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
code sample (doesn't work)import 'package:flutter/material.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
ErrorWidget.builder = (FlutterErrorDetails details) {
return Material(
child: Container(
color: Colors.purple,
alignment: Alignment.center,
child: const Text(
'Something went wrong!',
style: TextStyle(fontSize: 20, color: Colors.white),
),
),
);
};
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Column(children: <Widget>[
Positioned(
child: Container(
height: 10,
width: 10,
color: Colors.red,
))
]),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
flutter doctor -v (mac)
|
@maheshmnj if you replace ErrorWidget.builder = _defaultErrorWidgetBuilder; error info will be shown in release |
I have verified that import "package:flutter/material.dart";
void main() {
ErrorWidget.builder = (FlutterErrorDetails details) {
return Container(color: Colors.green);
};
runApp(const MaterialApp(home: Scaffold(body: MyApp())));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
throw "help!";
}
} |
it should has a way to show such error in release. demo in debug, just show error in console, it's easy miss those infos if your app has many debug info. |
@goderbauer wondering if we have to manually throw errors for |
I notice: the description of ErrorWidget.builder /// When an error occurs while building a widget, the broken widget is That why demo code does not work, the replaced widget also has error, so it's drop-dead halt. i think ErrorWidget.builder should not be public to the user. Not all users are professional. The following codes may be more safety. import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() {
// ErrorWidget.builder = (FlutterErrorDetails details) {
// return Material(
// child: Container(
// color: Colors.purple,
// alignment: Alignment.center,
// child: const Text(
// 'Something went wrong!',
// style: TextStyle(fontSize: 20, color: Colors.white),
// ),
// ),
// );
// };
FlutterError.onError = _onError;
runZonedGuarded<void>(() async {
runApp(const MyApp());
},
((error, stack) => _onError(FlutterErrorDetails(
exception: error,
stack: stack,
))));
}
void _onError(FlutterErrorDetails details) {
WidgetsBinding.instance.addPostFrameCallback(
(timeStamp) {
showDialog(
context: MyApp.navigatorKey.currentContext!,
builder: (b) {
return Padding(
padding: const EdgeInsets.all(20.0),
child: GestureDetector(
onTap: () {
Navigator.of(b).pop();
},
child: Material(
child: Container(
padding: EdgeInsets.all(10),
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Text('exception:'),
Text('${details.exception}'),
Text('stack:'),
Text('${details.stack}'),
],
)),
),
),
),
);
},
);
},
);
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
navigatorKey: navigatorKey,
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
void initState() {
// TODO: implement initState
super.initState();
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Stack(children: <Widget>[
GestureDetector(
child: Positioned(
child: Container(
height: 10,
width: 10,
color: Colors.red,
),
),
)
]),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
|
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Uh oh!
There was an error while loading. Please reload this page.
Steps to Reproduce
flutter run --profile
on the code sampleExpected results: show Custom error widget
Actual results: white screen
Code sample
The text was updated successfully, but these errors were encountered: