-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAINTROID-679 Implement JSON Serialization via Code Generation
- Loading branch information
1 parent
d18319e
commit c48353a
Showing
75 changed files
with
893 additions
and
2,254 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,6 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install Protoc | ||
uses: arduino/setup-protoc@v2 | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: subosito/[email protected] | ||
with: | ||
flutter-version: "3.10.5" | ||
|
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
library command; | ||
|
||
export 'src/graphic/draw_path_command.dart'; | ||
export 'src/manager/sync_command_manager.dart'; | ||
|
||
export 'src/command_factory.dart'; | ||
export 'src/command_manager.dart'; | ||
export 'src/command.dart'; | ||
export 'src/graphic_command.dart'; | ||
export 'src/command_factory/command_factory.dart'; | ||
export 'src/command_implementation/command.dart'; | ||
export 'src/command_implementation/graphic/draw_path_command.dart'; | ||
export 'src/command_implementation/graphic/graphic_command.dart'; | ||
export 'src/command_manager/command_manager.dart'; | ||
export 'src/command_manager/sync_command_manager.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
library command; | ||
|
||
export 'src/command_factory_provider.dart'; | ||
export 'src/command_manager_provider.dart'; | ||
export 'src/command_factory/command_factory_provider.dart'; | ||
export 'src/command_manager/command_manager_provider.dart'; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
packages/command/lib/src/command_implementation/command.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,19 @@ | ||
import 'package:command/command.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:io_library/io_library.dart'; | ||
|
||
abstract class Command with EquatableMixin { | ||
const Command(); | ||
|
||
Map<String, dynamic> toJson(); | ||
|
||
factory Command.fromJson(Map<String, dynamic> json) { | ||
String type = json['type'] as String; | ||
switch (type) { | ||
case SerializerType.DRAW_PATH_COMMAND: | ||
return DrawPathCommand.fromJson(json); | ||
default: | ||
return DrawPathCommand.fromJson(json); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/command/lib/src/command_implementation/graphic/draw_path_command.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,52 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:command/command.dart'; | ||
import 'package:component_library/component_library.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:io_library/io_library.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'draw_path_command.g.dart'; | ||
|
||
@JsonSerializable() | ||
class DrawPathCommand extends GraphicCommand { | ||
final String type; | ||
final int version; | ||
|
||
DrawPathCommand( | ||
this.path, | ||
super.paint, { | ||
this.type = SerializerType.DRAW_PATH_COMMAND, | ||
int? version, | ||
}) : version = version ?? | ||
VersionStrategyManager.strategy.getDrawPathCommandVersion(); | ||
|
||
@PathWithActionHistoryConverter() | ||
final PathWithActionHistory path; | ||
|
||
@override | ||
void call(Canvas canvas) { | ||
canvas.drawPath(path, paint); | ||
} | ||
|
||
@override | ||
List<Object?> get props => [paint, path, type]; | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$DrawPathCommandToJson(this); | ||
|
||
factory DrawPathCommand.fromJson(Map<String, dynamic> json) { | ||
int version = json['version'] as int; | ||
|
||
switch (version) { | ||
case Version.v1: | ||
return _$DrawPathCommandFromJson(json); | ||
case Version.v2: | ||
// For different versions of DrawPathCommand the deserialization | ||
// has to be implemented manually. | ||
// Autogenerated code can only be used for one version | ||
default: | ||
return _$DrawPathCommandFromJson(json); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/command/lib/src/command_implementation/graphic/draw_path_command.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
...ages/command/lib/src/graphic_command.dart → ...plementation/graphic/graphic_command.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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.