Skip to content
Open
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
3 changes: 3 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ dev_dependencies:
sdk: flutter
intl_utils: ^2.8.2

dependency_overrides:
intl: 0.20.2

flutter:
uses-material-design: true

Expand Down
30 changes: 19 additions & 11 deletions lib/src/deriv_chart/chart/main_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ class _ChartImplementationState extends BasicChartState<MainChart> {

@override
Widget build(BuildContext context) => LayoutBuilder(
// Force remount when markerSeries changes.
// LayoutBuilder only re-invokes its builder on constraint changes;
// without a key that tracks markerSeries identity, the old
// MarkerArea subtree persists after trade-type switches.
key: ObjectKey(widget.markerSeries),
builder: (BuildContext context, BoxConstraints constraints) {
final XAxisModel xAxis = context.watch<XAxisModel>();

Expand Down Expand Up @@ -579,17 +584,20 @@ class _ChartImplementationState extends BasicChartState<MainChart> {
),
);

Widget _buildMarkerArea() => MultipleAnimatedBuilder(
animations: <Listenable>[
currentTickAnimation,
topBoundQuoteAnimationController,
bottomBoundQuoteAnimationController
],
builder: (BuildContext context, _) => MarkerArea(
markerSeries: widget.markerSeries!,
quoteToCanvasY: chartQuoteToCanvasY,
animationInfo: AnimationInfo(
currentTickPercent: currentTickAnimation.value,
Widget _buildMarkerArea() => KeyedSubtree(
key: ObjectKey(widget.markerSeries),
child: MultipleAnimatedBuilder(
Comment on lines +587 to +589
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Re-evaluate the need for both LayoutBuilder key and KeyedSubtree keyed by markerSeries.

Both the LayoutBuilder (in build) and this KeyedSubtree use ObjectKey(widget.markerSeries), causing the same remount trigger at two levels. This can cause unnecessary state resets higher in the tree and makes remount behavior harder to understand. Consider keying only the minimal subtree that truly depends on markerSeries (likely this MarkerArea/KeyedSubtree) and leaving the outer LayoutBuilder unkeyed unless you explicitly need to rebuild the entire layout on markerSeries changes.

Suggested implementation:

    return LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {

  • The _buildMarkerArea method that wraps the marker area in a KeyedSubtree(key: ObjectKey(widget.markerSeries), ...) should remain as it is; that subtree is now solely responsible for remounting on markerSeries changes.
  • If the exact LayoutBuilder snippet differs (extra parameters, different formatting), apply the same change conceptually: remove only the key: ObjectKey(widget.markerSeries), argument from the LayoutBuilder constructor, keeping the rest of the arguments and formatting intact.

animations: <Listenable>[
currentTickAnimation,
topBoundQuoteAnimationController,
bottomBoundQuoteAnimationController
],
builder: (BuildContext context, _) => MarkerArea(
markerSeries: widget.markerSeries!,
quoteToCanvasY: chartQuoteToCanvasY,
animationInfo: AnimationInfo(
currentTickPercent: currentTickAnimation.value,
),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
collection: ^1.18.0
deriv_technical_analysis: ^1.1.1
equatable: ^2.0.5
intl: ^0.19.0
intl: ^0.20.2
json_annotation: ^4.8.0
provider: ^6.0.5
shared_preferences: ^2.1.0
Expand Down
Loading