Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:stac/src/parsers/core/stac_action_parser.dart';
import 'package:stac/stac.dart';
import 'package:stac_core/stac_core.dart';

Expand All @@ -22,6 +23,6 @@ class StacSetValueActionParser extends StacActionParser<StacSetValueAction> {
for (final value in model.values ?? []) {
StacRegistry.instance.setValue(value['key'] as String, value['value']);
}
return Stac.onCallFromJson(model.action, context);
return model.action.parse(context);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify null safety for the action invocation.

The change from Stac.onCallFromJson(model.action, context) to model.action.parse(context) introduces a potential null pointer exception. Since model.action is typed as StacAction? (nullable), calling .parse(context) directly will throw if action is null.

Consider applying this diff to handle the null case safely:

-    return model.action.parse(context);
+    return model.action?.parse(context);

Alternatively, verify whether model.action is guaranteed to be non-null in practice by running the following script:


🏁 Script executed:

#!/bin/bash
# Description: Search for StacSetValueAction usage to verify if action field can be null.

# Search for JSON examples or tests where StacSetValueAction is instantiated
rg -n -C3 --type=dart 'StacSetValueAction\(' 

# Search for fromJson calls that might pass null action
rg -n -C3 --type=dart "action.*:.*null" | rg -C3 "StacSetValueAction"

Length of output: 4220


📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return model.action.parse(context);
return model.action?.parse(context);
🤖 Prompt for AI Agents
packages/stac/lib/src/parsers/actions/stac_set_value/stac_set_value_action_parser.dart
around line 26: model.action is nullable so calling .parse(context)
unconditionally can cause an NPE; update this line to guard against null by
using a null-aware call that returns null when action is missing, and if the
method's return type is non-nullable instead throw a clear exception when
model.action is null so callers get an explicit error.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:stac/src/parsers/core/stac_widget_parser.dart';
import 'package:stac/src/parsers/foundation/navigation/stac_bottom_navigation_bar_landscape_layout_parser.dart';
import 'package:stac/src/parsers/foundation/navigation/stac_bottom_navigation_bar_type_parser.dart';
import 'package:stac/src/parsers/foundation/text/stac_text_style_parser.dart';
import 'package:stac/src/parsers/widgets/stac_default_bottom_navigation_controller/stac_default_bottom_navigation_controller.dart';
import 'package:stac/src/parsers/widgets/stac_default_bottom_navigation_controller/stac_default_bottom_navigation_controller_parser.dart';
import 'package:stac/src/utils/color_utils.dart';
import 'package:stac_core/stac_core.dart';
import 'package:stac_framework/stac_framework.dart';
Expand All @@ -21,6 +21,17 @@ class StacBottomNavigationBarParser

@override
Widget parse(BuildContext context, StacBottomNavigationBar model) {
return _BottomNavigationBarWidget(model: model);
}
}

class _BottomNavigationBarWidget extends StatelessWidget {
const _BottomNavigationBarWidget({required this.model});

final StacBottomNavigationBar model;

@override
Widget build(BuildContext context) {
final controller = BottomNavigationScope.of(context)?.controller;

return BottomNavigationBar(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:flutter/material.dart';
import 'package:stac/src/parsers/core/stac_widget_parser.dart';
import 'package:stac/src/parsers/widgets/stac_default_bottom_navigation_controller/stac_default_bottom_navigation_controller_parser.dart';
import 'package:stac_core/stac_core.dart';
import 'package:stac_framework/stac_framework.dart';

import '../stac_default_bottom_navigation_controller/stac_default_bottom_navigation_controller.dart';

class StacBottomNavigationViewParser
extends StacParser<StacBottomNavigationView> {
const StacBottomNavigationViewParser();
Expand All @@ -18,6 +17,17 @@ class StacBottomNavigationViewParser

@override
Widget parse(BuildContext context, StacBottomNavigationView model) {
return _BottomNavigationViewWidget(model: model);
}
}

class _BottomNavigationViewWidget extends StatelessWidget {
const _BottomNavigationViewWidget({required this.model});

final StacBottomNavigationView model;

@override
Widget build(BuildContext context) {
final controller = BottomNavigationScope.of(context)?.controller;
if (model.children.isEmpty) return const SizedBox();
final index = controller?.index ?? 0;
Expand Down

This file was deleted.

Loading