I have an in-app socket notification stream system that listens messages in home. (main->app->home) When I try to navigate a page and make http call, it throws the error below.
Edit: When I trigger it in initState() it works perfectly.
โโโก EXCEPTION CAUGHT BY SCHEDULER LIBRARY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The following assertion was thrown during a scheduler callback:
'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1702 pos 12: 'center!.parent
== this': 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=2_bug.md
When the exception was thrown, this was the stack:
#2 RenderViewport.indexOfFirstChild (package:flutter/src/rendering/viewport.dart:1702:12)
#3 RenderViewportBase.debugDescribeChildren (package:flutter/src/rendering/viewport.dart:974:17)
#4 DiagnosticableTreeNode.getChildren (package:flutter/src/foundation/diagnostics.dart:2989:48)
#5 DiagnosticsNode.toJsonMap.<anonymous closure> (package:flutter/src/foundation/diagnostics.dart:1562:32)
#6 DiagnosticsNode.toJsonMap (package:flutter/src/foundation/diagnostics.dart:1603:6)
#7 DiagnosticsNode.toJsonList.<anonymous closure> (package:flutter/src/foundation/diagnostics.dart:1627:19)
#8 MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
#9 ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
#10 new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:188:27)
#11 new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#12 new List.of (dart:core-patch/array_patch.dart:51:28)
#13 ListIterable.toList (dart:_internal/iterable.dart:213:44)
#14 DiagnosticsNode.toJsonList (package:flutter/src/foundation/diagnostics.dart:1628:8)
#15 DiagnosticsNode.toJsonMap.<anonymous closure> (package:flutter/src/foundation/diagnostics.dart:1590:25)
#16 DiagnosticsNode.toJsonMap (package:flutter/src/foundation/diagnostics.dart:1603:6)
#17 WidgetInspectorService._nodeToJson (package:flutter/src/widgets/widget_inspector.dart:1513:18)
#18 WidgetInspectorService._reportStructuredError (package:flutter/src/widgets/widget_inspector.dart:922:44)
#19 FlutterError.reportError (package:flutter/src/foundation/assertions.dart:1137:14)
#20 RenderObject._debugReportException (package:flutter/src/rendering/object.dart:1370:18)
#21 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1713:7)
#22 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:882:18)
#23 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:483:19)
#24 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:13)
#25 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:349:5)
#26 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1145:15)
#27 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
#28 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#32 _invoke (dart:ui/hooks.dart:150:10)
#33 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#34 _drawFrame (dart:ui/hooks.dart:114:31)
(elided 5 frames from class _AssertionError and dart:async)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Another exception was thrown: Updated layout information required for RenderViewport#637e1 NEEDS-LAYOUT to calculate semantics.
flutter: EVENT FROM NOTIFICATION: Instance of 'SocketNotification'
flutter: EVENT FROM NOTIFICATION: Instance of 'SocketNotification'
flutter: EVENT FROM NOTIFICATION: Instance of 'SocketNotification'
Another exception was thrown: RenderBox.size accessed beyond the scope of resize, layout, or permitted parent access. RenderBox can always access
its own size, otherwise, the only object that is allowed to read RenderBox.size is its parent, if they have said they will. It you hit this assert
trying to access a child's size, pass "parentUsesSize: true" to that child's layout().
Another exception was thrown: RenderBox.size accessed beyond the scope of resize, layout, or permitted parent access. RenderBox can always access
its own size, otherwise, the only object that is allowed to read RenderBox.size is its parent, if they have said they will. It you hit this assert
trying to access a child's size, pass "parentUsesSize: true" to that child's layout().
Another exception was thrown: Updated layout information required for RenderViewport#637e1 NEEDS-LAYOUT to calculate semantics.
Another exception was thrown: RenderBox.size accessed beyond the scope of resize, layout, or permitted parent access. RenderBox can always access
its own size, otherwise, the only object that is allowed to read RenderBox.size is its parent, if they have said they will. It you hit this assert
trying to access a child's size, pass "parentUsesSize: true" to that child's layout().
main.dart
Future<void> main() async {
try {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
} catch (error, stackTrace) {
printDebug('$error & $stackTrace');
}
}
my_app.dart
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return InAppNotification(
child: MultiProvider(
providers: getProviders(),
child: MaterialApp(
title: 'My App',
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Consumer<AuthProvider>(
builder: (context, provider, child) {
return provider.loggedIn ? const Home() : const AuthScreen();
},
),
routes: getRoutes(),
),
),
);
}
}
home.dart
@override
void initState() {
super.initState();
listenPusher();
}
void listenPusher() {
_pusherSubscription = _pusher.stream.listen((event) {
switch (event.type) {
case ChannelType.message:
// handle
break;
case ChannelType.notification:
printDebug('EVENT FROM NOTIFICATION: ${event.data}');
InAppNotification.show(
child: const NotificationBody(),
context: context,
onTap: () => print('Notification tapped!'),
duration: const Duration(milliseconds: 30000),
);
break;
}
});
}