Skip to content

Commit

Permalink
Merge pull request #174 from kaboc/fix/headings
Browse files Browse the repository at this point in the history
見出しテキスト欠損の修正とスクロールのパフォーマンス改善
  • Loading branch information
tatsutakein authored Sep 26, 2023
2 parents 09e0993 + 39f47d1 commit 8fe9b57
Showing 1 changed file with 15 additions and 32 deletions.
47 changes: 15 additions & 32 deletions lib/core/components/section_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@ final class SectionHeader extends StatelessWidget {

@override
Widget build(BuildContext context) {
final component = ShaderMask(
shaderCallback: (Rect bounds) {
// NOTE: bounds から取得するとグラデーションが想定どおりかからないため、テキストサイズを別途取得する
final textSize = _getTextSize(maxWidth: bounds.width);
return gradient.createShader(
Rect.fromLTWH(0, 0, textSize.width, textSize.height),
);
},
blendMode: BlendMode.srcIn,
child: Padding(
// NOTE: Text Widget の描画範囲から外れて文字やブラーが見切れてしまうため、現状は左右に余白を設けている
padding: const EdgeInsets.all(_blurRadius),
child: Text(
text,
style: style.copyWith(
color: Colors.white,
final component = Align(
alignment: Alignment.centerLeft,
child: RepaintBoundary(
child: ShaderMask(
shaderCallback: gradient.createShader,
blendMode: BlendMode.srcIn,
child: Padding(
// NOTE: Text Widget の描画範囲から外れて文字やブラーが見切れてしまうため、現状は左右に余白を設けている
padding: const EdgeInsets.all(_blurRadius),
child: Text(
text,
style: style.copyWith(
color: Colors.white,
),
),
),
),
),
Expand All @@ -61,20 +60,4 @@ final class SectionHeader extends StatelessWidget {

return component;
}

/// 描画するテキストのサイズを取得する
Size _getTextSize({
required double maxWidth,
}) {
final textPainter = TextPainter(
text: TextSpan(
text: text,
style: style,
),
textDirection: TextDirection.ltr,
)..layout(
maxWidth: maxWidth,
);
return textPainter.size;
}
}

0 comments on commit 8fe9b57

Please sign in to comment.