Skip to content

Add text to the editor programatically #205

Answered by hm21
sabinjose asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

Thank you for your kind words, I’m glad you appreciate my package. Below is an example of how you can wrap your text directly.

final String _bibleText =
    'For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life.';

String _wrapText(String text, double maxWidth) {
  final words = text.split(' ');
  String wrappedText = '';
  String currentLine = '';

  for (var word in words) {
    final testLine = currentLine.isEmpty ? word : '$currentLine $word';
    final textPainter = TextPainter(
      text: TextSpan(
          text: testLine,
          style: const TextStyle(
            /// The default fontSize from the…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sabinjose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants