-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into ramin/prepare_for…
…_publish
- Loading branch information
Showing
19 changed files
with
702 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
lib/src/add_ons/drawing_tools_ui/line/line_drawing_tool_config_mobile.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import 'package:deriv_chart/deriv_chart.dart'; | ||
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/callbacks.dart'; | ||
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/drawing_tool_item.dart'; | ||
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/line/line_drawing_tool_item_mobile.dart'; | ||
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/line/line_drawing_tool_label_painter.dart'; | ||
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/data_model/drawing_pattern.dart'; | ||
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/data_model/edge_point.dart'; | ||
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/data_model/point.dart'; | ||
import 'package:deriv_chart/src/theme/colors.dart'; | ||
import 'package:flutter/foundation.dart' show kIsWeb; | ||
import 'package:flutter/material.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'line_drawing_tool_config_mobile.g.dart'; | ||
|
||
/// Line drawing tool config | ||
@JsonSerializable() | ||
class LineDrawingToolConfigMobile extends DrawingToolConfig { | ||
/// Initializes | ||
const LineDrawingToolConfigMobile({ | ||
String? configId, | ||
DrawingData? drawingData, | ||
List<EdgePoint> edgePoints = const <EdgePoint>[], | ||
this.lineStyle = const LineStyle( | ||
thickness: 0.9, | ||
color: BrandColors.coral, | ||
), | ||
this.overlayStyle, | ||
this.pattern = DrawingPatterns.solid, | ||
super.number, | ||
}) : super( | ||
configId: configId, | ||
drawingData: drawingData, | ||
edgePoints: edgePoints, | ||
); | ||
|
||
/// Initializes from JSON. | ||
factory LineDrawingToolConfigMobile.fromJson(Map<String, dynamic> json) => | ||
_$LineDrawingToolConfigMobileFromJson(json); | ||
|
||
/// Drawing tool name | ||
static const String name = 'dt_line_mobile'; | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$LineDrawingToolConfigMobileToJson(this) | ||
..putIfAbsent(DrawingToolConfig.nameKey, () => name); | ||
|
||
/// Drawing tool line style | ||
final LineStyle lineStyle; | ||
|
||
/// Drawing tool overlay style | ||
@JsonKey( | ||
fromJson: _overlayStyleFromJson, | ||
toJson: _overlayStyleToJson, | ||
) | ||
final OverlayStyle? overlayStyle; | ||
|
||
/// Drawing tool line pattern: 'solid', 'dotted', 'dashed' | ||
// TODO(maryia-binary): implement 'dotted' and 'dashed' patterns | ||
final DrawingPatterns pattern; | ||
|
||
@override | ||
DrawingToolItem getItem( | ||
UpdateDrawingTool updateDrawingTool, | ||
VoidCallback deleteDrawingTool, | ||
) => | ||
LineDrawingToolItemMobile( | ||
updateDrawingTool: updateDrawingTool, | ||
deleteDrawingTool: deleteDrawingTool, | ||
); | ||
|
||
@override | ||
LineDrawingToolConfigMobile copyWith({ | ||
String? configId, | ||
DrawingData? drawingData, | ||
LineStyle? lineStyle, | ||
LineStyle? fillStyle, | ||
OverlayStyle? overlayStyle, | ||
DrawingPatterns? pattern, | ||
List<EdgePoint>? edgePoints, | ||
bool? enableLabel, | ||
int? number, | ||
}) => | ||
LineDrawingToolConfigMobile( | ||
configId: configId ?? this.configId, | ||
drawingData: drawingData ?? this.drawingData, | ||
lineStyle: lineStyle ?? this.lineStyle, | ||
overlayStyle: overlayStyle ?? this.overlayStyle, | ||
pattern: pattern ?? this.pattern, | ||
edgePoints: edgePoints ?? this.edgePoints, | ||
number: number ?? this.number, | ||
); | ||
|
||
@override | ||
LineDrawingToolLabelPainter? getLabelPainter({ | ||
required Point startPoint, | ||
required Point endPoint, | ||
}) { | ||
if (kIsWeb) { | ||
return null; | ||
} else { | ||
return MobileLineDrawingToolLabelPainter( | ||
const LineDrawingToolConfigMobile(), | ||
startPoint: startPoint, | ||
endPoint: endPoint, | ||
); | ||
} | ||
} | ||
|
||
static OverlayStyle? _overlayStyleFromJson(Map<String, dynamic>? json) { | ||
if (json == null) { | ||
return null; | ||
} | ||
return OverlayStyle( | ||
color: Color(json['color'] as int), | ||
); | ||
} | ||
|
||
static Map<String, dynamic>? _overlayStyleToJson(OverlayStyle? instance) { | ||
if (instance == null) { | ||
return null; | ||
} | ||
return { | ||
'color': instance.color.value, | ||
}; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
lib/src/add_ons/drawing_tools_ui/line/line_drawing_tool_config_mobile.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
lib/src/add_ons/drawing_tools_ui/line/line_drawing_tool_item_mobile.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import 'package:deriv_chart/generated/l10n.dart'; | ||
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/drawing_tool_config.dart'; | ||
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/drawing_tool_item.dart'; | ||
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/line/line_drawing_tool_config_mobile.dart'; | ||
import 'package:deriv_chart/src/add_ons/indicators_ui/widgets/color_selector.dart'; | ||
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/data_model/drawing_pattern.dart'; | ||
import 'package:deriv_chart/src/theme/painting_styles/line_style.dart'; | ||
import 'package:flutter/material.dart'; | ||
import '../callbacks.dart'; | ||
|
||
/// Line drawing tool item in the list of drawing tools | ||
class LineDrawingToolItemMobile extends DrawingToolItem { | ||
/// Initializes | ||
const LineDrawingToolItemMobile({ | ||
required UpdateDrawingTool updateDrawingTool, | ||
required VoidCallback deleteDrawingTool, | ||
Key? key, | ||
LineDrawingToolConfigMobile config = const LineDrawingToolConfigMobile(), | ||
}) : super( | ||
key: key, | ||
title: 'Line', | ||
config: config, | ||
updateDrawingTool: updateDrawingTool, | ||
deleteDrawingTool: deleteDrawingTool, | ||
); | ||
|
||
@override | ||
DrawingToolItemState<DrawingToolConfig> createDrawingToolItemState() => | ||
LineDrawingToolItemMobileState(); | ||
} | ||
|
||
/// LineDrawingToolItem State class | ||
class LineDrawingToolItemMobileState | ||
extends DrawingToolItemState<LineDrawingToolConfigMobile> { | ||
LineStyle? _lineStyle; | ||
DrawingPatterns? _pattern; | ||
|
||
@override | ||
LineDrawingToolConfigMobile createDrawingToolConfig() => | ||
LineDrawingToolConfigMobile( | ||
lineStyle: _currentLineStyle, | ||
pattern: _currentPattern, | ||
); | ||
|
||
@override | ||
Widget getDrawingToolOptions() => Column( | ||
children: <Widget>[ | ||
_buildColorField(), | ||
// TODO(maryia-binary): implement _buildPatternField() to set pattern | ||
], | ||
); | ||
|
||
Widget _buildColorField() => Row( | ||
children: <Widget>[ | ||
Text( | ||
ChartLocalization.of(context).labelColor, | ||
style: const TextStyle(fontSize: 16), | ||
), | ||
ColorSelector( | ||
currentColor: _currentLineStyle.color, | ||
onColorChanged: (Color selectedColor) { | ||
setState(() { | ||
_lineStyle = _currentLineStyle.copyWith(color: selectedColor); | ||
}); | ||
updateDrawingTool(); | ||
}, | ||
) | ||
], | ||
); | ||
|
||
LineStyle get _currentLineStyle => | ||
_lineStyle ?? (widget.config as LineDrawingToolConfigMobile).lineStyle; | ||
|
||
DrawingPatterns get _currentPattern => | ||
_pattern ?? (widget.config as LineDrawingToolConfigMobile).pattern; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.