Skip to content

Conversation

@MeandNi
Copy link

@MeandNi MeandNi commented Oct 23, 2025

Description

  • Fix ScaffoldMessenger error by moving UI code to _CatalogGalleryHome
  • Fix JSON encoding error by using messageText instead of jsonEncode(message.parts.last)
  • Resolves two runtime exceptions that prevented the example from running properly
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: No ScaffoldMessenger widget found. CatalogGalleryApp widgets require a ScaffoldMessenger widget ancestor. The specific widget that could not find a ScaffoldMessenger ancestor was: CatalogGalleryApp The ancestors of this widget were: _FocusInheritedScope _FocusScopeWithExternalFocusNode _FocusInheritedScope Focus FocusTraversalGroup MediaQuery _MediaQueryFromView _PipelineOwnerScope _ViewScope _RawViewInternal-[_DeprecatedRawViewKey FlutterView#4937b] RawView View [root] Typically, the ScaffoldMessenger widget is introduced by the MaterialApp at the top of your application widget tree. #0 debugCheckHasScaffoldMessenger. (package:flutter/src/material/debug.dart:182:7) debug.dart:182 #1 debugCheckHasScaffoldMessenger (package:flutter/src/material/debug.dart:195:4) debug.dart:195 #2 ScaffoldMessenger.of (package:flutter/src/material/scaffold.dart:157:12) scaffold.dart:157 #3 _CatalogGalleryAppState.build.

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Converting object to an encodable object failed: Instance of 'TextPart'
#0 _JsonStringifier.writeObject (dart:convert/json.dart:824:7)
json.dart:824
#1 _JsonStringStringifier.printOn (dart:convert/json.dart:1024:17)
json.dart:1024
#2 _JsonStringStringifier.stringify (dart:convert/json.dart:1005:5)
json.dart:1005
#3 JsonEncoder.convert (dart:convert/json.dart:353:30)
json.dart:353
#4 JsonCodec.encode (dart:convert/json.dart:238:45)
json.dart:238
#5 jsonEncode (dart:convert/json.dart:118:12)
json.dart:118
#6 _CatalogGalleryHome.build. (package:catalog_gallery/main.dart:57:28)
main.dart:57
#7 _RootZone.runUnaryGuarded (dart:async/zone.dart:1778:10)
zone.dart:1778
#8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
stream_impl.dart:381
#9 _DelayedData.perform (dart:async/stream_impl.dart:573:14)
stream_impl.dart:573
#10 _PendingEvents.handleNext (dart:async/stream_impl.dart:678:11)
stream_impl.dart:678
#11 _PendingEvents.schedule. (dart:async/stream_impl.dart:649:7)
stream_impl.dart:649
#12 _microtaskLo<…>

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses two runtime exceptions in the catalog_gallery example. The refactoring to introduce _CatalogGalleryHome is a good solution for the ScaffoldMessenger issue. The fix for the JSON encoding error is also a good improvement. I have one suggestion to make the onSubmit handler more robust to prevent a potential runtime crash if a message does not contain any text parts.

- Fix ScaffoldMessenger error by moving UI code to _CatalogGalleryHome
- Fix JSON encoding error by using messageText instead of jsonEncode(message.parts.last)
- Resolves two runtime exceptions that prevented the example from running properly
@MeandNi MeandNi force-pushed the fix/catalog-gallery-runtime-errors branch from 8b4a432 to 62961b7 Compare November 3, 2025 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant