text stringlengths 1 474 |
|---|
onPressed: () { |
// Navigate to the second screen using a named route. |
Navigator.pushNamed(context, '/second'); |
// Immediately show a dialog upon loading the second screen. |
Navigator.push( |
context, |
PageRouteBuilder( |
barrierDismissible: true, |
opaque: false, |
pageBuilder: (_, anim1, anim2) => const MyDialog(), |
), |
); |
}, |
), |
), |
); |
} |
}<code_end> |
<topic_end> |
<topic_start> |
The ScrollController is attached to multiple scroll views |
This error can occur when multiple scrolling |
widgets (such as ListView) appear on the |
screen at the same time. It’s more likely for |
this error to occur on a web or desktop app, |
than a mobile app since it’s rare to encounter |
this scenario on mobile.For more information and to learn how to fix, |
check out the following video on |
PrimaryScrollController:<topic_end> |
<topic_start> |
References |
To learn more about how to debug errors, |
especially layout errors in Flutter, |
check out the following resources: |
<topic_end> |
<topic_start>Handling errors in Flutter |
The Flutter framework catches errors that occur during callbacks |
triggered by the framework itself, including errors encountered |
during the build, layout, and paint phases. Errors that don’t occur |
within Flutter’s callbacks can’t be caught by the framework, |
but you can handle them by setting up an error handler on the |
PlatformDispatcher.All errors caught by Flutter are routed to the |
FlutterError.onError handler. By default, |
this calls FlutterError.presentError, |
which dumps the error to the device logs. |
When running from an IDE, the inspector overrides this |
behavior so that errors can also be routed to the IDE’s |
console, allowing you to inspect the |
objects mentioned in the message.info Note |
Consider calling FlutterError.presentError |
from your custom error handler in order to see |
the logs in the console as well.When an error occurs during the build phase, |
the ErrorWidget.builder callback is |
invoked to build the widget that is used |
instead of the one that failed. By default, |
in debug mode this shows an error message in red, |
and in release mode this shows a gray background.When errors occur without a Flutter callback on the call stack, |
they are handled by the PlatformDispatcher’s error callback. By default, |
this only prints errors and does nothing else.You can customize these behaviors, |
typically by setting them to values in |
your void main() function.Below each error type handling is explained. At the bottom |
there’s a code snippet which handles all types of errors. Even |
though you can just copy-paste the snippet, we recommend you |
to first get acquainted with each of the error types.<topic_end> |
<topic_start> |
Errors caught by Flutter |
For example, to make your application quit immediately any time an |
error is caught by Flutter in release mode, you could use the |
following handler: |
<code_start>import 'dart:io'; |
import 'package:flutter/foundation.dart'; |
import 'package:flutter/material.dart'; |
void main() { |
FlutterError.onError = (details) { |
FlutterError.presentError(details); |
if (kReleaseMode) exit(1); |
}; |
runApp(const MyApp()); |
} |
// rest of `flutter create` code...<code_end> |
info Note |
The top-level kReleaseMode constant indicates |
whether the app was compiled in release mode.This handler can also be used to report errors to a logging service. |
For more details, see our cookbook chapter for |
reporting errors to a service.<topic_end> |
<topic_start> |
Define a custom error widget for build phase errors |
To define a customized error widget that displays whenever |
the builder fails to build a widget, use MaterialApp.builder. |
<code_start>class MyApp extends StatelessWidget { |
const MyApp({super.key}); |
@override |
Widget build(BuildContext context) { |
return MaterialApp( |
builder: (context, widget) { |
Widget error = const Text('...rendering error...'); |
if (widget is Scaffold || widget is Navigator) { |
error = Scaffold(body: Center(child: error)); |
} |
ErrorWidget.builder = (errorDetails) => error; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.