-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
121adc7
commit 701a0f9
Showing
12 changed files
with
220 additions
and
52 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package prefix | ||
|
||
import ( | ||
"github.com/11wizards/go-to-dart/examples/prefix/shared" | ||
) | ||
|
||
type KeyValuePair[TKey, TValue any] struct { | ||
Key TKey `json:"key"` | ||
Value TValue `json:"value"` | ||
} | ||
|
||
type Map[TKey, TValue any] struct { | ||
Items []KeyValuePair[TKey, TValue] `json:"items"` | ||
} | ||
|
||
type Instance struct { | ||
M Map[string, int] `json:"m"` | ||
} | ||
|
||
type UserRepository struct { | ||
Users []shared.User `json:"users"` | ||
} |
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,86 @@ | ||
// ignore_for_file: always_use_package_imports | ||
import 'package:copy_with_extension/copy_with_extension.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'prefix.go.g.dart'; | ||
|
||
@CopyWith() | ||
@JsonSerializable(explicitToJson: true) | ||
class MyInstance extends Equatable { | ||
final MyMap<String, int> m; | ||
|
||
const Instance({ | ||
required this.m, | ||
}); | ||
|
||
Map<String, dynamic> toJson() => _$MyInstanceToJson(this); | ||
|
||
factory MyInstance.fromJson(Map<String, dynamic> json) => _$MyInstanceFromJson(json); | ||
|
||
@override | ||
List<Object?> get props => [ | ||
m, | ||
]; | ||
} | ||
|
||
@CopyWith() | ||
@JsonSerializable(explicitToJson: true, genericArgumentFactories: true) | ||
class MyKeyValuePair<TKey, TValue> extends Equatable { | ||
final TKey key; | ||
final TValue value; | ||
|
||
const KeyValuePair({ | ||
required this.key, | ||
required this.value, | ||
}); | ||
|
||
Map<String, dynamic> toJson(Object Function(TKey) toJsonTKey, Object Function(TValue) toJsonTValue) => _$MyKeyValuePairToJson(this, toJsonTKey, toJsonTValue); | ||
|
||
factory MyKeyValuePair.fromJson(Map<String, dynamic> json, TKey Function(Object? json) fromJsonTKey, TValue Function(Object? json) fromJsonTValue) => _$MyKeyValuePairFromJson(json, fromJsonTKey, fromJsonTValue); | ||
|
||
@override | ||
List<Object?> get props => [ | ||
key, | ||
value, | ||
]; | ||
} | ||
|
||
@CopyWith() | ||
@JsonSerializable(explicitToJson: true, genericArgumentFactories: true) | ||
class MyMap<TKey, TValue> extends Equatable { | ||
@JsonKey(defaultValue: <List<MyKeyValuePair<TKey, TValue>>>[])final List<MyKeyValuePair<TKey, TValue>> items; | ||
|
||
const Map({ | ||
required this.items, | ||
}); | ||
|
||
Map<String, dynamic> toJson(Object Function(TKey) toJsonTKey, Object Function(TValue) toJsonTValue) => _$MyMapToJson(this, toJsonTKey, toJsonTValue); | ||
|
||
factory MyMap.fromJson(Map<String, dynamic> json, TKey Function(Object? json) fromJsonTKey, TValue Function(Object? json) fromJsonTValue) => _$MyMapFromJson(json, fromJsonTKey, fromJsonTValue); | ||
|
||
@override | ||
List<Object?> get props => [ | ||
items, | ||
]; | ||
} | ||
|
||
@CopyWith() | ||
@JsonSerializable(explicitToJson: true) | ||
class MyUserRepository extends Equatable { | ||
@JsonKey(defaultValue: <List<User>>[])final List<User> users; | ||
|
||
const UserRepository({ | ||
required this.users, | ||
}); | ||
|
||
Map<String, dynamic> toJson() => _$MyUserRepositoryToJson(this); | ||
|
||
factory MyUserRepository.fromJson(Map<String, dynamic> json) => _$MyUserRepositoryFromJson(json); | ||
|
||
@override | ||
List<Object?> get props => [ | ||
users, | ||
]; | ||
} | ||
|
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,6 @@ | ||
package shared | ||
|
||
type User struct { | ||
Name string `json:"name"` | ||
Age int `json:"age"` | ||
} |
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.