Exception is thrown when debugging on windows, stacktrace:
ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Scaffold.geometryOf() must only be accessed during the paint phase.
The ScaffoldGeometry is only available during the paint phase, because its value is computed during the animation and layout phases prior to painting.
#0 _ScaffoldGeometryNotifier.value.<anonymous closure> (package:flutter/src/material/scaffold.dart:835:9)
#1 _ScaffoldGeometryNotifier.value (package:flutter/src/material/scaffold.dart:842:6)
#2 _BottomAppBarClipper.getClip (package:flutter/src/material/bottom_app_bar.dart:238:35)
The stacktrace is hinting at getting geometry values from a BottomAppBar which is what I have in my widget. This error is followed by a lot of error messages for mouse_tracker when I move the mouse on the screen:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter/src/rendering/mouse_tracker.dart': Failed assertion: line 195 pos 12: '!_debugDuringDeviceUpdate': is not true.
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2 MouseTracker._deviceUpdatePhase (package:flutter/src/rendering/mouse_tracker.dart:195:12)
Nothing on the screen is clickable after this.
The error occurs only after the FloatingActionButton is pressed, and not if the back button on the page is pressed. The onPressed for the FAB is:
void onOkPressed() {
Navigator.of(context).pop();
}
How can I solve this error?
The FAB is contained in the bottom app bar, try setting the FAB location to float
from
Scaffold(
appBar: const AppBar(),
bottomNavigationBar: const BottomAppBar(),
floatingActionButton: FloatingActionButton(
onPressed: onOkPressed,
child: const Icon(Icons.check, size: 32),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endContained,
....
to
Scaffold(
appBar: const AppBar(),
bottomNavigationBar: const BottomAppBar(),
floatingActionButton: FloatingActionButton(
onPressed: onOkPressed,
child: const Icon(Icons.check, size: 32),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
....
Related
I have an app that displays a snackbar when some action is done. I had tested this with my phone and some emulator and it works. Recently I installed an emulator with android 13 and maybe a bigger resolution and I'm getting this error:
The following assertion was thrown during performLayout():
Floating SnackBar presented off screen.
A SnackBar with behavior property set to SnackBarBehavior.floating is fully or partially off screen because some or all the widgets provided to Scaffold.floatingActionButton, Scaffold.persistentFooterButtons and Scaffold.bottomNavigationBar take up too much vertical space.
Consider constraining the size of these widgets to allow room for the SnackBar to be visible.
The relevant error-causing widget was
Scaffold
dashboard.dart:69
When the exception was thrown, this was the stack
#0 _ScaffoldLayout.performLayout.<anonymous closure>
#0 _ScaffoldLayout.performLayout.<anonymous closure>
scaffold.dart:1189
#1 _ScaffoldLayout.performLayout
scaffold.dart:1204
#2 MultiChildLayoutDelegate._callPerformLayout
custom_layout.dart:240
#3 RenderCustomMultiChildLayoutBox.performLayout
custom_layout.dart:410
#4 RenderObject._layoutWithoutResize
object.dart:2027
#5 PipelineOwner.flushLayout
object.dart:1020
#6 RendererBinding.drawFrame
binding.dart:516
#7 WidgetsBinding.drawFrame
binding.dart:865
#8 RendererBinding._handlePersistentFrameCallback
binding.dart:381
#9 SchedulerBinding._invokeFrameCallback
binding.dart:1289
#10 SchedulerBinding.handleDrawFrame
binding.dart:1218
#11 SchedulerBinding._handleDrawFrame
binding.dart:1076
#12 _invoke (dart:ui/hooks.dart:145:13)
#13 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:338:5)
#14 _drawFrame (dart:ui/hooks.dart:112:31)
The following RenderObject was being processed when the exception was fired: RenderCustomMultiChildLayoutBox#3f6d8 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: RenderCustomMultiChildLayoutBox#3f6d8 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
needs compositing
parentData: <none> (can use size)
constraints: BoxConstraints(w=411.4, h=867.4)
size: Size(411.4, 867.4)
child 1: RenderRepaintBoundary#ba78b relayoutBoundary=up1
needs compositing
I have no idea how can I debug what is going on here. The code works in smaller devices/older versions of android. The popups are triggered quiet straightforward:
SnackBar getSnackbar({
required String message,
required Color backgroundColor,
}) {
return SnackBar(
elevation: 8,
backgroundColor: backgroundColor,
behavior: SnackBarBehavior.floating,
content: Row(children: [
Flexible(
child: Text(
message,
style: const TextStyle(
color: Colors.white,
),
),
)
]),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
);
}
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(getSnackbar(
backgroundColor: Colors.green,
message: 'File saved to $filename',
));
The screen where this is called does not have any Scaffold.floatingActionButton, Scaffold.persistentFooterButtons and Scaffold.bottomNavigationBar as the exception says. It is just a Scaffold with a body:
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('SomeScreen'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: _isLoading
? const Center(child: CircularProgressIndicator())
: Column(children: [
_displaySomething(),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
_displayAnotherThing(),
],
))
]),
),
);
}
Update: I have futher debugged the issue and it also happens in older versions of android. So it may be related to a recent update of flutter but I'm not able to find why.
I was able to see the problem appears only with behavior:SnackBarBehavior.floating,.
Also removing all the code from the Scaffolfd, leaving just the TextButton that triggers the snackbar is enough to reproduce the issue, but I don't know what can I do with it.
I faced this problem too. This problem arises due to the fact that your column takes up all the available space, you need to limit it somehow to give room for a snackbar
I cross posted this here, because I though it was a bug. But there it was explained that for the SnackBars you have to also consider other Scaffolds in the widget tree as moving backwards would keep the snackbar "flying" and could collide with elements of the previous Scaffolds.
So as a summary on how to solve this issue, take a look not only in the screen where you see the exception triggered but also from previous screens.
I am using the BackdropAppBar package and would like to open the drawer programmatically from the leading icon using something like that : _scaffoldKey.currentState!.openDrawer();
But it doesn't work
The drawer is visible when swiping but i want a menu icon to activate it
Also tried this : Backdrop.of(context).scaffoldKey!.currentState!.openDrawer();
Heres's my code :
BackdropScaffold(
key: _scaffoldKey,
appBar: BackdropAppBar(
title: Text('PRODUCTS'),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.person),
onPressed: () {
print('open drawer');//text is printed
//none of the following work
_scaffoldKey.currentState!.openDrawer();
Scaffold.of(context).openDrawer();
Backdrop.of(context).scaffoldKey!.currentState!.openDrawer();
} ,
),
BackdropToggleButton(
icon: AnimatedIcons.close_menu,
),
],
drawer: MyDrawer(),
frontLayer: pageBuilder(),
backLayer: Center(
child: Text("Back Layer"),
),
));
}
_scaffoldKey is defined like this :
final GlobalKey<BackdropScaffoldState> _scaffoldKey = GlobalKey<BackdropScaffoldState>();
Here's the error :
Exception caught by gesture
The following _CastError was thrown while handling a gesture:
Null check operator used on a null value
When the exception was thrown, this was the stack:
#0 Backdrop.of (package:backdrop/src/scaffold.dart:29:61)
I actually found a solution :
replace key: _scaffoldKey with scaffoldKey: _scaffoldKey
Hopefully this will save somebody some time
So what I'm trying to do, besides my app bar where I have logo and search option I want to add bottom TabBar where user can choose between movies or tv shows, and while he is on one of them the text should be lit up (different color). But when I tried to add the TabBar i got an error:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building MediaQuery(MediaQueryData(size: Size(411.4, 683.4),
devicePixelRatio: 2.6, textScaleFactor: 1.0, platformBrightness: Brightness.light, padding:
EdgeInsets.zero, viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets.zero, alwaysUse24HourFormat:
false, accessibleNavigation: false, highContrast: false, disableAnimations: false, invertColors:
false, boldText: false, navigationMode: traditional)):
No TabController for TabBar.
When creating a TabBar, you must either provide an explicit TabController using the "controller"
property, or you must ensure that there is a DefaultTabController above the TabBar.
In this case, there was neither an explicit controller nor a default controller.
The relevant error-causing widget was:
AppBar file:///C:/Users/Meliha/Desktop/Rubicon/chillax/lib/presenter/home_page_movies.dart:22:15
When the exception was thrown, this was the stack:
#0 _TabBarState._updateTabController.<anonymous closure> (package:flutter/src/material/tabs.dart:965:9)
#1 _TabBarState._updateTabController (package:flutter/src/material/tabs.dart:974:6)
#2 _TabBarState.didChangeDependencies (package:flutter/src/material/tabs.dart:1006:5)
#3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4653:11)
#4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4469:5)
#5 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
#6 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6094:32)
... Normal element mounting (99 frames)
#105 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
#106 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6094:32)
... Normal element mounting (238 frames)
#344 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
#345 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6094:32)
... Normal element mounting (300 frames)
#645 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
#646 Element.updateChild (package:flutter/src/widgets/framework.dart:3306:18)
#647 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1182:16)
#648 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1153:5)
#649 RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1095:18)
#650 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2647:19)
#651 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1094:13)
#652 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:934:7)
#653 WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:915:7)
(elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
════════════════════════════════════════════════════════════════════════════════════════════════════
Here is the code of the main page for the movies:
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:movie_app/view/now_playing_movie.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:movie_app/view/now_playing_tv.dart';
import 'package:movie_app/view/test.dart';
import 'package:movie_app/view/top_movies.dart';
import 'package:movie_app/view/top_tvs.dart';
import '../style/style.dart';
class HomePageMovie extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePageMovie> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF151C26),
appBar: AppBar(
backgroundColor: Color(0xFF151C26),
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SvgPicture.asset(
logo,
height: 195,
),
],
),
actions: <Widget>[
IconButton(
onPressed: () {},
icon: Icon(
EvaIcons.searchOutline,
color: Colors.white,
))
],
bottom: TabBar(
indicatorColor: Color(0xFFf4C10F),
indicatorSize: TabBarIndicatorSize.tab,
indicatorWeight: 3.0,
unselectedLabelColor: Colors.white,
labelColor: Colors.white,
isScrollable: true,
tabs: [
Tab(
icon: Icon(Icons.movie),
text: "Movies",
),
Tab(
icon: Icon(Icons.tv),
text: "TV Shows",
)
]),
titleSpacing: 0.0,
),
body: ListView(
children: <Widget>[
NowPlayingMovies(),
BestMovie(),
],
),
);
}
}
Any form of help/tip/guide would be great. Thanks in advance
The solution for your problem is right inside the error text
When creating a TabBar, you must either provide an explicit TabController using the "controller"
property, or you must ensure that there is a DefaultTabController above the TabBar.
Therefore the easiest solution is to wrap your TabBar with the DefaultTabController. Since you are making use of the bottom property of AppBar which expects a PreferredSizeWidget, you additionally need to wrap it all inside something that implements this (since it's an abstract class) - easiest solution here is to just make use of PreferredSize. Complete example could look like this:
AppBar(
bottom: PreferredSize(
// Set whatever size you want - this is a good default one
preferredSize: Size.fromHeight(kToolbarHeight),
child: DefaultTabController(
length: 2,
child: TabBar(
tabs: [
Tab(
text: 'Movies',
),
Tab(
text: 'TV Shows',
),
],
),
),
),
),
The error logs are pretty verbose at times, but this is the crucial message:
When creating a TabBar, you must either provide an explicit TabController using the "controller"
property, or you must ensure that there is a DefaultTabController above the TabBar.
In this case, there was neither an explicit controller nor a default controller.
You just need to wrap your Scaffold widget in a DefaultTabController and give it a length corresponding to the number of tabs you have. For more complex behaviour you can initialise a ScrollController and add this to the controller: parameter of the TabBar and TabBarView.
I also notice in the example you have a ListView containing your two tab widgets. This won't work, swap it out for a TabBarView.
I have a Flutter app that populates a list of river gauge information and allows the user to select an item and view details in a chart, using the charts_flutter package.
I have used the chart successfully in the past with a FutureBuilder, and now it is being refactored to use a Provider. The view containing the chart works as expected, but when returning to the previous screen (the list of gauges) I receive an error after the list shows very briefly. The error is as follows.
This is the code that renders the chart view
class GaugeDetailChart extends StatefulWidget {
GaugeReferenceModel referenceModel;
GaugeDetailChart({this.referenceModel});
#override
_GaugeDetailChartState createState() => _GaugeDetailChartState();
}
class _GaugeDetailChartState extends State<GaugeDetailChart> {
GaugeDetailViewModel viewModel;
#override
void initState() {
_loadData();
super.initState();
}
_loadData() {
viewModel = Provider.of<GaugeDetailViewModel>(context, listen: false);
viewModel.reloading = true;
viewModel.setReferenceModel(widget.referenceModel);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: RLAppBar(
titleText: Text('Gauge Detail'),
),
body: Center(
child: Consumer<GaugeDetailViewModel>(
builder: (context, model, child) => Stack(
children: [
Center(
child: Visibility(
visible: model.reloading,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Loading details for'),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('${widget.referenceModel.gaugeName}'),
)
],
)),
),
// removing the following container resolves the exception
Container(
height: MediaQuery.of(context).size.height * .5,
alignment: Alignment(0.0, 0.0),
color: Colors.lightBlueAccent,
child: charts.TimeSeriesChart(
model.seriesFlowData,
animate: true,
animationDuration: Duration(milliseconds: 500),
primaryMeasureAxis: charts.NumericAxisSpec(
tickProviderSpec: charts.BasicNumericTickProviderSpec(
zeroBound: false,
dataIsInWholeNumbers: false,
desiredMaxTickCount: 8,
desiredMinTickCount: 5),
renderSpec: charts.GridlineRendererSpec(
tickLengthPx: 0, labelOffsetFromAxisPx: 5)),
)
)
],
),
),
));
}
}
The chart renders on the view correctly. The only time the error occurs is when exiting this view and returning to the previous view, which is performed using the NavigationController back button.
If I remove the Container that holds the chart, then returning to the previous view works without error. Something about the Container is causing the previous view to fail. The errors generated are very vague.
The following assertion was thrown building Overlay-[LabeledGlobalKey<OverlayState>#5f9d5](state: OverlayState#a6169(entries: [OverlayEntry#2b4ce(opaque: true; maintainState: false), OverlayEntry#eea3d(opaque: false; maintainState: true), OverlayEntry#c217d(opaque: true; maintainState: false), OverlayEntry#ae45e(opaque: false; maintainState: true), OverlayEntry#c7b73(opaque: true; maintainState: false), OverlayEntry#e34a6(opaque: false; maintainState: true)])):
'package:flutter/src/widgets/framework.dart': Failed assertion: line 5125 pos 14: '_dependents.isEmpty': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=BUG.md
The relevant error-causing widget was:
MaterialApp file:///Users/philiptownsend/Documents/projects.nosync/_Flutter/RiverLink/stream_watcher/lib/main.dart:32:12
When the exception was thrown, this was the stack:
#2 InheritedElement.debugDeactivated.<anonymous closure> (package:flutter/src/widgets/framework.dart:5125:14)
#3 InheritedElement.debugDeactivated (package:flutter/src/widgets/framework.dart:5127:6)
#4 _InactiveElements._deactivateRecursively.<anonymous closure> (package:flutter/src/widgets/framework.dart:2048:15)
#5 _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:2050:6)
#6 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4710:14)
Has anyone experienced anything like this before or can anyone make a recommendation on where to start looking or how to solve this?
Thanks!
I am not really sure but why don't you try making the container a seperate widget and try
calling that widget. Maybe that resolves the issue
The images for the code below are not showing and it's throwing an exception. My pubspec is aligned correctly so not sure what's wrong.
I tried updating flutter, restarting,re-aligning but still get the same exception below.
Syncing files to device iPhone X... flutter: ══╡ EXCEPTION CAUGHT BY
IMAGE RESOURCE SERVICE
╞════════════════════════════════════════════════════ flutter: The
following assertion was thrown resolving an image codec: flutter:
Unable to load asset: /images/barlogo.png flutter: flutter: When the
exception was thrown, this was the stack: flutter: #0
PlatformAssetBundle.load
(package:flutter/src/services/asset_bundle.dart:221:7) flutter:
import 'package:flutter/material.dart';
void main() {
return runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: new Color(0xffA62FF0),
centerTitle: true,
elevation: 1.0,
leading: new Icon(Icons.camera_alt),
title: SizedBox(
height: 35.0, child:new Image.asset('/images/barlogo.png')),
actions: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 12.0),
child: new Image.asset('/images/search.png'),
)
],
),
)
)
);
}
The exception gives it away - Flutter cannot find the image requested.
You should not have a leading / when specifying asset paths. Try:
Image.asset('images/barlogo.png')
There's more info in the documentation: https://api.flutter.dev/flutter/widgets/Image/Image.asset.html