From 9fc5803280be8a33dc3b86e5710126c02a0e260a Mon Sep 17 00:00:00 2001 From: "kreazy.me" <102190042@sv1.dut.udn.vn> Date: Sat, 30 Aug 2025 10:34:55 +0700 Subject: [PATCH] handle show null data in JsonViewer --- .../lib/src/shared/ui/common_widgets.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/devtools_app/lib/src/shared/ui/common_widgets.dart b/packages/devtools_app/lib/src/shared/ui/common_widgets.dart index 8e7467d2186..bc7a2f8d0e5 100644 --- a/packages/devtools_app/lib/src/shared/ui/common_widgets.dart +++ b/packages/devtools_app/lib/src/shared/ui/common_widgets.dart @@ -1085,8 +1085,11 @@ class TextViewer extends StatelessWidget { } class JsonViewer extends StatefulWidget { - JsonViewer({super.key, required this.encodedJson, this.scrollable = true}) - : assert(encodedJson.isNotEmpty); + const JsonViewer({ + super.key, + required this.encodedJson, + this.scrollable = true, + }); final String encodedJson; final bool scrollable; @@ -1111,7 +1114,7 @@ class _JsonViewerState extends State { } void _updateVariablesTree() { - assert(widget.encodedJson.isNotEmpty); + if (widget.encodedJson.isEmpty) return; final responseJson = json.decode(widget.encodedJson); // Insert the JSON data into the fake service cache so we can use it with // the `ExpandableVariable` widget. @@ -1197,6 +1200,12 @@ class _JsonViewerState extends State { @override Widget build(BuildContext context) { + if (widget.encodedJson.isEmpty) { + return const Padding( + padding: EdgeInsetsGeometry.only(top: 16.0), + child: CenteredMessage(message: 'No JSON data'), + ); + } Widget child = FutureBuilder( future: _initializeTree, builder: (context, snapshot) {