import 'package:flutter/material.dart'; import 'package:matrix/matrix.dart'; class StoryThemeData { final Color? color1; final Color? color2; final BoxFit fit; final int alignmentX; final int alignmentY; static const String contentKey = 'msc3588.stories.design'; const StoryThemeData({ this.color1, this.color2, this.fit = BoxFit.contain, this.alignmentX = 0, this.alignmentY = 0, }); factory StoryThemeData.fromJson(Map json) { final color1Int = json.tryGet('color1'); final color2Int = json.tryGet('color2'); final color1 = color1Int == null ? null : Color(color1Int); final color2 = color2Int == null ? null : Color(color2Int); return StoryThemeData( color1: color1, color2: color2, fit: json.tryGet('fit') == 'cover' ? BoxFit.cover : BoxFit.contain, alignmentX: json.tryGet('alignment_x') ?? 0, alignmentY: json.tryGet('alignment_y') ?? 0, ); } Map toJson() => { if (color1 != null) 'color1': color1?.value, if (color2 != null) 'color2': color2?.value, 'fit': fit.name, 'alignment_x': alignmentX, 'alignment_y': alignmentY, }; }