Move to Flutter 3.47, use the improvements that come with this (#64)
Reviewed-on: #64
This commit is contained in:
parent
01b13b4764
commit
077044ec19
157 changed files with 1366 additions and 1457 deletions
|
|
@ -1,53 +1,55 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/membership.dart";
|
||||
|
||||
part "profile_response.freezed.dart";
|
||||
part "profile_response.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class ProfileResponse with _$ProfileResponse {
|
||||
const factory ProfileResponse({
|
||||
@JsonKey(fromJson: Profile.fromJson) required Profile profile,
|
||||
required Bio? bio,
|
||||
}) = _ProfileResponse;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const ProfileResponse({
|
||||
@JsonKey(fromJson: Profile.fromJson) required final Profile profile,
|
||||
required final Bio? bio,
|
||||
}) with _$ProfileResponse {
|
||||
Map<String, Object?> toJson() => _$ProfileResponseToJson(this);
|
||||
|
||||
factory ProfileResponse.fromJson(Map<String, Object?> json) =>
|
||||
_$ProfileResponseFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class Bio with _$Bio {
|
||||
const factory Bio({required String html, String? editSource}) = _Bio;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const Bio({required final String html, final String? editSource})
|
||||
with _$Bio {
|
||||
Map<String, Object?> toJson() => _$BioToJson(this);
|
||||
|
||||
factory Bio.fromJson(Map<String, Object?> json) => _$BioFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class Profile with _$Profile {
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const Profile({
|
||||
final String? id,
|
||||
final String? parseError,
|
||||
final Uri? avatarUrl,
|
||||
|
||||
@JsonKey(name: "displayname", fromJson: MembershipContent.displaynameFromJson)
|
||||
final String? displayName,
|
||||
|
||||
@JsonKey(readValue: Profile.readTimezone, name: "m.tz")
|
||||
final String? timezone,
|
||||
|
||||
@JsonKey(readValue: Profile.readPronouns, name: "m.pronouns")
|
||||
final IList<Pronoun> pronouns = const IList.empty(),
|
||||
}) with _$Profile {
|
||||
Map<String, Object?> toJson() => _$ProfileToJson(this);
|
||||
|
||||
static Object? readPronouns(Map<dynamic, dynamic> map, String key) =>
|
||||
map[key] ?? map["io.fsky.nyx.pronouns"];
|
||||
|
||||
static Object? readTimezone(Map<dynamic, dynamic> map, String key) =>
|
||||
map[key] ?? map["us.cloke.msc4175.tz"];
|
||||
|
||||
const factory Profile({
|
||||
String? id,
|
||||
String? parseError,
|
||||
Uri? avatarUrl,
|
||||
|
||||
@JsonKey(
|
||||
name: "displayname",
|
||||
fromJson: MembershipContent.displaynameFromJson,
|
||||
)
|
||||
String? displayName,
|
||||
|
||||
@JsonKey(readValue: Profile.readTimezone, name: "m.tz") String? timezone,
|
||||
|
||||
@Default(IList.empty())
|
||||
@JsonKey(readValue: Profile.readPronouns, name: "m.pronouns")
|
||||
IList<Pronoun> pronouns,
|
||||
}) = _Profile;
|
||||
|
||||
factory Profile.fromJson(Map<String, dynamic> json) =>
|
||||
_$ProfileFromJson(json);
|
||||
|
||||
|
|
@ -55,15 +57,18 @@ abstract class Profile with _$Profile {
|
|||
try {
|
||||
return Profile.fromJson(json);
|
||||
} catch (error) {
|
||||
return Profile(parseError: error.toString());
|
||||
return _Profile(parseError: error.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class Pronoun with _$Pronoun {
|
||||
const factory Pronoun({required String language, required String summary}) =
|
||||
_Pronoun;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const Pronoun({
|
||||
required final String language,
|
||||
required final String summary,
|
||||
}) with _$Pronoun {
|
||||
Map<String, Object?> toJson() => _$PronounToJson(this);
|
||||
|
||||
factory Pronoun.fromJson(Map<String, Object?> json) =>
|
||||
_$PronounFromJson(json);
|
||||
|
|
|
|||
Loading…
Reference in a new issue