Skip to content

Commit

Permalink
Color extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
PhiFry committed Sep 3, 2024
1 parent f5517fb commit 6c09634
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/src/widgets/rich_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:flutter/widgets.dart' as sb;
import 'package:flutter_storyblok/src/fields/link.dart';
import 'package:flutter_storyblok/src/fields/rich_text.dart';
import 'package:flutter_storyblok/src/utils.dart';
import 'package:flutter_storyblok/src/widgets/storyblok_color.dart';
import 'package:flutter_storyblok/widgets.dart';

typedef BlockBuilder = Widget Function(BuildContext context, JSONMap data);

Expand Down Expand Up @@ -153,10 +153,9 @@ extension _RichTextLeafBuildWidget on List<RichTextLeaf> {

extension _RichTextLeafMarkableWidget on RichTextLeafMarkable {
TextStyle buildTextStyle() {
final foregroundColor = mapIfNotNull(this.foregroundColor?.colorString, StoryblokColor.fromString) ??
(link != null ? Colors.black : null);
final foregroundColor = this.foregroundColor?.color ?? (link != null ? Colors.black : null);
return TextStyle(
backgroundColor: isCode ? Colors.grey : mapIfNotNull(backgroundColor?.colorString, StoryblokColor.fromString),
backgroundColor: isCode ? Colors.grey : backgroundColor?.color,
color: foregroundColor,
fontStyle: isItalic || isCode ? FontStyle.italic : null,
fontWeight: isBold ? FontWeight.bold : null,
Expand Down
12 changes: 12 additions & 0 deletions lib/widgets.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
library;

import 'package:flutter/material.dart';
import 'package:flutter_storyblok/src/fields/rich_text.dart';
import 'package:flutter_storyblok/src/widgets/storyblok_color.dart';

export 'src/widgets/storyblok_color.dart';
export 'src/widgets/rich_text.dart';

extension RichTextLeafMarkTextStyleColor on RichTextLeafMarkTextStyle {
Color get color => StoryblokColor.fromString(colorString);
}

extension RichTextLeafMarkHighlightColor on RichTextLeafMarkHighlight {
Color get color => StoryblokColor.fromString(colorString);
}

0 comments on commit 6c09634

Please sign in to comment.