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
21 changes: 21 additions & 0 deletions lib/src/add_ons/add_ons_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:deriv_chart/src/add_ons/add_on_config.dart';
import 'package:deriv_chart/src/add_ons/repository.dart';
import 'package:deriv_chart/src/misc/chart_diagnostics.dart';
import 'package:shared_preferences/shared_preferences.dart';

/// Called to create an AddOnConfig object from a map.
Expand Down Expand Up @@ -73,6 +74,9 @@ class AddOnsRepository<T extends AddOnConfig> extends ChangeNotifier

if (!prefs.containsKey(addOnsKey)) {
// No saved indicators or drawing tools.
if (kChartDiagnosticsEnabled) {
chartDiag('repo#$hashCode loadFromPrefs($addOnsKey): no saved items');
}
notifyListeners();
return;
}
Expand All @@ -90,6 +94,11 @@ class AddOnsRepository<T extends AddOnConfig> extends ChangeNotifier
_hiddenStatus.add(false);
}

if (kChartDiagnosticsEnabled) {
chartDiag('repo#$hashCode loadFromPrefs($addOnsKey): loaded '
'${items.map((T c) => c.configId).toList()}');
}

notifyListeners();
}

Expand All @@ -98,6 +107,10 @@ class AddOnsRepository<T extends AddOnConfig> extends ChangeNotifier
void add(T addOnConfig) {
items.add(addOnConfig);
_hiddenStatus.add(false);
if (kChartDiagnosticsEnabled) {
chartDiag('repo#$hashCode add(${addOnConfig.configId}) -> $addOnsKey, '
'items: ${items.map((T c) => c.configId).toList()}');
}
_writeToPrefs();
notifyListeners();
}
Expand Down Expand Up @@ -128,6 +141,11 @@ class AddOnsRepository<T extends AddOnConfig> extends ChangeNotifier
}
final removedItem = items.removeAt(index);
_hiddenStatus.removeAt(index);
if (kChartDiagnosticsEnabled) {
chartDiag('repo#$hashCode removeAt($index) '
'removed ${removedItem.configId} -> $addOnsKey, '
'items: ${items.map((T c) => c.configId).toList()}');
}
_writeToPrefs();
// Notify about the deletion
onDeleteCallback?.call(removedItem, index);
Expand All @@ -148,6 +166,9 @@ class AddOnsRepository<T extends AddOnConfig> extends ChangeNotifier
void clear() {
items.clear();
_hiddenStatus.clear();
if (kChartDiagnosticsEnabled) {
chartDiag('repo#$hashCode clear() -> $addOnsKey');
}
_writeToPrefs();
notifyListeners();
}
Expand Down
92 changes: 55 additions & 37 deletions lib/src/deriv_chart/chart/main_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -511,38 +511,43 @@ class _ChartImplementationState extends BasicChartState<MainChart> {
loadingAnimationColor: widget.loadingAnimationColor,
);

Widget _buildAnnotations() => MultipleAnimatedBuilder(
animations: <Animation<double>>[
currentTickAnimation,
_currentTickBlinkAnimation,
topBoundQuoteAnimationController,
bottomBoundQuoteAnimationController,
],
builder: (BuildContext context, _) =>
Stack(fit: StackFit.expand, children: <Widget>[
if (widget.annotations != null)
...widget.annotations!
.map(
(ChartData annotation) => RepaintBoundary(
child: CustomPaint(
key: ValueKey<String>(annotation.id),
painter: ChartPainter(
animationInfo: AnimationInfo(
currentTickPercent: currentTickAnimation.value,
blinkingPercent: _currentTickBlinkAnimation.value,
Widget _buildAnnotations() => LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final XAxisModel xAxisModel = context.watch<XAxisModel>();
return MultipleAnimatedBuilder(
animations: <Listenable>[
currentTickAnimation,
_currentTickBlinkAnimation,
topBoundQuoteAnimationController,
bottomBoundQuoteAnimationController,
],
builder: (BuildContext context, _) =>
Stack(fit: StackFit.expand, children: <Widget>[
if (widget.annotations != null)
...widget.annotations!
.map(
(ChartData annotation) => RepaintBoundary(
child: CustomPaint(
key: ValueKey<String>(annotation.id),
painter: ChartPainter(
animationInfo: AnimationInfo(
currentTickPercent: currentTickAnimation.value,
blinkingPercent: _currentTickBlinkAnimation.value,
),
chartData: annotation,
chartConfig: context.watch<ChartConfig>(),
theme: context.watch<ChartTheme>(),
epochToCanvasX: xAxisModel.xFromEpoch,
quoteToCanvasY: chartQuoteToCanvasY,
chartScaleModel: context.watch<ChartScaleModel>(),
),
),
chartData: annotation,
chartConfig: context.watch<ChartConfig>(),
theme: context.watch<ChartTheme>(),
epochToCanvasX: xAxis.xFromEpoch,
quoteToCanvasY: chartQuoteToCanvasY,
chartScaleModel: context.watch<ChartScaleModel>(),
),
),
),
)
.toList()
]),
)
.toList()
]),
);
},
);

Widget _buildScrollToLastTickButton() => Material(
Expand Down Expand Up @@ -590,13 +595,26 @@ class _ChartImplementationState extends BasicChartState<MainChart> {
topBoundQuoteAnimationController,
bottomBoundQuoteAnimationController
],
builder: (BuildContext context, _) => MarkerArea(
markerSeries: widget.markerSeries!,
quoteToCanvasY: chartQuoteToCanvasY,
animationInfo: AnimationInfo(
currentTickPercent: currentTickAnimation.value,
),
),
builder: (BuildContext context, _) {
// This builder re-runs on every animation tick, independently of the
// gating LayoutBuilder. During a trade-type switch / navigation the
// series can become null while the animation controllers are still
// ticking (e.g. a running contract), so we must NOT force-unwrap
// markerSeries here β€” doing so threw "Null check operator used on a
// null value", which Flutter rendered as the release-mode grey
// ErrorWidget overlaying the chart.
final MarkerSeries? markerSeries = widget.markerSeries;
if (markerSeries == null) {
return const SizedBox.shrink();
}
return MarkerArea(
markerSeries: markerSeries,
quoteToCanvasY: chartQuoteToCanvasY,
animationInfo: AnimationInfo(
currentTickPercent: currentTickAnimation.value,
),
);
},
);

Widget _buildDataFitButton() {
Expand Down
Loading
Loading