Move to Flutter 3.47, use the improvements that come with this (#64)

Reviewed-on: #64
This commit is contained in:
Henry Hiles 2026-08-22 13:04:33 -04:00 committed by Henry Hiles
commit 077044ec19
157 changed files with 1366 additions and 1457 deletions

View file

@ -5,7 +5,7 @@ part "avatar.freezed.dart";
part "avatar.g.dart";
@freezed
abstract class AvatarContent extends Content with _$AvatarContent {
sealed class AvatarContent extends Content with _$AvatarContent {
AvatarContent._();
factory AvatarContent({ImageInfo? info, Uri? url}) = _AvatarContent;

View file

@ -5,7 +5,7 @@ part "canonical_alias.freezed.dart";
part "canonical_alias.g.dart";
@freezed
abstract class CanonicalAliasContent extends Content
sealed class CanonicalAliasContent extends Content
with _$CanonicalAliasContent {
CanonicalAliasContent._();
factory CanonicalAliasContent({

View file

@ -19,9 +19,11 @@ import "package:nexus/models/content/history_visibility.dart";
class Content {
final Error? parseError;
Content({this.parseError});
factory Content.fromJson(Map<String, dynamic> json) => Content();
const Content({this.parseError});
factory Content.fromJson(Map<String, dynamic> json) => const Content();
Map<String, dynamic> toJson() => {};
static Map<String, dynamic> readValue(Map<dynamic, dynamic> json, _) =>
@ -34,13 +36,16 @@ class Content {
?.contentFromJson ??
Content.fromJson)(json);
} catch (error) {
if (error is Error) return .new(parseError: error);
if (error is Error) return Content(parseError: error);
rethrow;
}
}
}
enum EventType {
enum EventType(
final String type,
final Content Function(Map<String, dynamic> json) contentFromJson,
) {
encrypted("m.room.encrypted", EncryptedContent.fromJson),
redaction("m.room.redaction", RedactionContent.fromJson),
encryption("m.room.encryption", EncryptionContent.fromJson),
@ -61,8 +66,4 @@ enum EventType {
reaction("m.reaction", ReactionContent.fromJson),
pinnedEvents("m.room.pinned_events", PinnedEventsContent.fromJson),
message("m.room.message", MessageContent.fromJson);
final String type;
final Content Function(Map<String, dynamic> json) contentFromJson;
const EventType(this.type, this.contentFromJson);
}

View file

@ -5,7 +5,7 @@ part "create.freezed.dart";
part "create.g.dart";
@freezed
abstract class CreateContent extends Content with _$CreateContent {
sealed class CreateContent extends Content with _$CreateContent {
CreateContent._();
factory CreateContent({
@JsonKey(name: "additional_creators")
@ -30,9 +30,10 @@ enum RoomType {
space,
}
@freezed
abstract class PreviousRoom with _$PreviousRoom {
const factory PreviousRoom({required String roomId}) = _PreviousRoom;
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const PreviousRoom({required final String roomId}) with _$PreviousRoom {
Map<String, Object?> toJson() => _$PreviousRoomToJson(this);
factory PreviousRoom.fromJson(Map<String, Object?> json) =>
_$PreviousRoomFromJson(json);

View file

@ -4,7 +4,7 @@ part "encrypted.freezed.dart";
part "encrypted.g.dart";
@freezed
abstract class EncryptedContent extends Content with _$EncryptedContent {
sealed class EncryptedContent extends Content with _$EncryptedContent {
EncryptedContent._();
factory EncryptedContent() = _EncryptedContent;

View file

@ -4,7 +4,7 @@ part "encryption.freezed.dart";
part "encryption.g.dart";
@freezed
abstract class EncryptionContent extends Content with _$EncryptionContent {
sealed class EncryptionContent extends Content with _$EncryptionContent {
EncryptionContent._();
factory EncryptionContent({
required String algorithm,

View file

@ -4,7 +4,7 @@ part "history_visibility.freezed.dart";
part "history_visibility.g.dart";
@freezed
abstract class HistoryVisibilityContent extends Content
sealed class HistoryVisibilityContent extends Content
with _$HistoryVisibilityContent {
HistoryVisibilityContent._();
factory HistoryVisibilityContent({

View file

@ -6,7 +6,7 @@ part "join_rules.freezed.dart";
part "join_rules.g.dart";
@freezed
abstract class JoinRulesContent extends Content with _$JoinRulesContent {
sealed class JoinRulesContent extends Content with _$JoinRulesContent {
JoinRulesContent._();
factory JoinRulesContent({
required JoinRule joinRule,
@ -17,12 +17,13 @@ abstract class JoinRulesContent extends Content with _$JoinRulesContent {
_$JoinRulesContentFromJson(json);
}
@freezed
abstract class AllowCondition with _$AllowCondition {
const factory AllowCondition({
String? roomId,
required AllowConditionType type,
}) = _AllowCondition;
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const AllowCondition({
final String? roomId,
required final AllowConditionType type,
}) with _$AllowCondition {
Map<String, Object?> toJson() => _$AllowConditionToJson(this);
factory AllowCondition.fromJson(Map<String, Object?> json) =>
_$AllowConditionFromJson(json);

View file

@ -5,7 +5,7 @@ part "membership.freezed.dart";
part "membership.g.dart";
@freezed
abstract class MembershipContent extends Content with _$MembershipContent {
sealed class MembershipContent extends Content with _$MembershipContent {
MembershipContent._();
static String? displaynameFromJson(String? displayName) =>

View file

@ -10,7 +10,7 @@ part "message.g.dart";
typedef EncryptedFile = Map<String, dynamic>;
@Freezed(unionKey: "msgtype", fallbackUnion: "default")
abstract class MessageContent extends Content with _$MessageContent {
sealed class MessageContent extends Content with _$MessageContent {
MessageContent._();
static String? mediaUrlFromJson(Map<dynamic, dynamic> json, String key) =>
json[key] ?? json["file"]?[key];

View file

@ -4,7 +4,7 @@ part "name.freezed.dart";
part "name.g.dart";
@freezed
abstract class NameContent extends Content with _$NameContent {
sealed class NameContent extends Content with _$NameContent {
NameContent._();
factory NameContent({required String name}) = _NameContent;

View file

@ -5,7 +5,7 @@ part "pinned_events.freezed.dart";
part "pinned_events.g.dart";
@freezed
abstract class PinnedEventsContent extends Content with _$PinnedEventsContent {
sealed class PinnedEventsContent extends Content with _$PinnedEventsContent {
PinnedEventsContent._();
factory PinnedEventsContent({
@Default(IList.empty()) @JsonKey(name: "pinned") IList<String> pinnedEvents,

View file

@ -5,7 +5,7 @@ part "power_levels.freezed.dart";
part "power_levels.g.dart";
@freezed
abstract class PowerLevelsContent extends Content with _$PowerLevelsContent {
sealed class PowerLevelsContent extends Content with _$PowerLevelsContent {
PowerLevelsContent._();
factory PowerLevelsContent({
@Default(IMap.empty()) IMap<String, int> events,
@ -24,12 +24,13 @@ abstract class PowerLevelsContent extends Content with _$PowerLevelsContent {
_$PowerLevelsContentFromJson(json);
}
@freezed
abstract class Notifications with _$Notifications {
const factory Notifications({
@Default(50) int room,
@Default(IMapConst({})) IMap<String, int> other,
}) = _Notifications;
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const Notifications({
final int room = 50,
final IMap<String, int> other = const IMap.empty(),
}) with _$Notifications {
Map<String, Object?> toJson() => _$NotificationsToJson(this);
factory Notifications.fromJson(Map<String, Object?> json) =>
_$NotificationsFromJson(json);

View file

@ -4,7 +4,7 @@ part "reaction.freezed.dart";
part "reaction.g.dart";
@Freezed(toJson: false)
abstract class ReactionContent extends Content with _$ReactionContent {
sealed class ReactionContent extends Content with _$ReactionContent {
ReactionContent._();
static String? keyJsonFromJson(Map<dynamic, dynamic> json, String key) =>
json["m.relates_to"]?["key"];

View file

@ -4,7 +4,7 @@ part "redaction.freezed.dart";
part "redaction.g.dart";
@freezed
abstract class RedactionContent extends Content with _$RedactionContent {
sealed class RedactionContent extends Content with _$RedactionContent {
RedactionContent._();
factory RedactionContent({String? reason, String? redacts}) =
_RedactionContent;

View file

@ -5,7 +5,7 @@ part "server_acl.freezed.dart";
part "server_acl.g.dart";
@freezed
abstract class ServerACLContent extends Content with _$ServerACLContent {
sealed class ServerACLContent extends Content with _$ServerACLContent {
ServerACLContent._();
factory ServerACLContent({
@Default(IList.empty()) IList<String> allow,

View file

@ -5,7 +5,7 @@ part "sticker.freezed.dart";
part "sticker.g.dart";
@freezed
abstract class StickerContent extends Content with _$StickerContent {
sealed class StickerContent extends Content with _$StickerContent {
StickerContent._();
factory StickerContent({
required String body,

View file

@ -1,11 +1,12 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "topic.freezed.dart";
part "topic.g.dart";
@freezed
abstract class TopicContent extends Content with _$TopicContent {
sealed class TopicContent extends Content with _$TopicContent {
TopicContent._();
factory TopicContent({
required String topic,
@ -16,24 +17,24 @@ abstract class TopicContent extends Content with _$TopicContent {
_$TopicContentFromJson(json);
}
@freezed
abstract class TopicContentBlock with _$TopicContentBlock {
factory TopicContentBlock({
@Default(IList.empty())
@JsonKey(name: "m.text")
IList<TextualRepresentation> representations,
}) = _TopicContentBlock;
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const TopicContentBlock({
final IList<TextualRepresentation> representations = const IList.empty(),
}) with _$TopicContentBlock {
Map<String, Object?> toJson() => _$TopicContentBlockToJson(this);
factory TopicContentBlock.fromJson(Map<String, Object?> json) =>
_$TopicContentBlockFromJson(json);
}
@freezed
abstract class TextualRepresentation with _$TextualRepresentation {
factory TextualRepresentation({
required String body,
@Default("text/plain") String mimetype,
}) = _TextualRepresentation;
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const TextualRepresentation({
required final String body,
final String mimetype = "text/plain",
}) with _$TextualRepresentation {
Map<String, Object?> toJson() => _$TextualRepresentationToJson(this);
factory TextualRepresentation.fromJson(Map<String, Object?> json) =>
_$TextualRepresentationFromJson(json);