Skip to content

Instantly share code, notes, and snippets.

@yeasin50
Last active May 28, 2025 18:16
Show Gist options
  • Save yeasin50/07d846bbbef4c8a39c4748ae999cfde1 to your computer and use it in GitHub Desktop.
Save yeasin50/07d846bbbef4c8a39c4748ae999cfde1 to your computer and use it in GitHub Desktop.
How can we have same text struct on RichText Widget?

How to achieve the same text visual in RichText as Text?

I’m trying to achieve the same visual appearance in TextPainter.main codebase. Below is a minimal snippet for preview.

The wrap words are not the same, something with structStyle

Text, RichText, RichText with DefaultTextStyle

image

Flutter Community: Humpday Q&A/AMA with Craig Labenz :: 28th May 2025

/// checkout gist for preview : https://gist.github.com/yeasin50/07d846bbbef4c8a39c4748ae999cfde1
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
void main() {
runApp(MaterialApp(home: TextRenderIssueView()));
}
class TextRenderIssueView extends StatefulWidget {
const TextRenderIssueView({super.key});
@override
State<TextRenderIssueView> createState() => _TextRenderIssueViewState();
}
class _TextRenderIssueViewState extends State<TextRenderIssueView> {
final style = GoogleFonts.montserrat(fontSize: 40, color: Colors.white);
final String text = "Same text with same style, yet it looks difference.....";
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Column(
mainAxisSize: MainAxisSize.min,
spacing: 24,
children: [
Text(text, style: style),
RichText(
text: TextSpan(
children: [TextSpan(text: text, style: style)],
),
),
DefaultTextStyle(
key: ValueKey("value"),
style: style,
child: RichText(
text: TextSpan(text: text, style: style),
),
),
],
),
);
}
}
@yeasin50
Copy link
Author

yeasin50 commented May 28, 2025

Solved by Simon: by adding letterSpacing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment