text
stringlengths 1
372
|
|---|
child: column(
|
children: <widget>[
|
Text('Show material dialog'),
|
],
|
),
|
);
|
}
|
<code_end>
|
this code doesn’t make an explicit call to setState,
|
but it’s called by showDialog.
|
the build method isn’t the right place to call
|
showDialog because build can be called by the
|
framework for every frame, for example, during an animation.
|
how to fix it?
|
one way to avoid this error is to use the navigator API
|
to trigger the dialog as a route. in the following example,
|
there are two pages. the second page has a
|
dialog to be displayed upon entry.
|
when the user requests the second page by
|
clicking a button on the first page,
|
the navigator pushes two routes–one
|
for the second page and another for the dialog.
|
<code_start>
|
class FirstScreen extends StatelessWidget {
|
const FirstScreen({super.key});
|
@override
|
widget build(BuildContext context) {
|
return scaffold(
|
appBar: AppBar(
|
title: const Text('First screen'),
|
),
|
body: center(
|
child: ElevatedButton(
|
child: const Text('Launch screen'),
|
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,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.