0

Here is a demonstration of the problem:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(
        child: Text(" hello ",
            style: TextStyle(
              fontSize: 100,
              backgroundColor: Colors.green,
            )),
      ),
    );
  }
}

It shows up like this:

Text not showing trailing space

So far I've tried this on web and macOS targets and got the same result.

How can I make the Text widget include the space at the end?

ijt
  • 3,505
  • 1
  • 29
  • 40
  • I think it boils down to how flutter renders a string, but the truth is if you try to render this on a console, if there's no reference text to reference the space between texts, you just see you text without the space is invincible. – Denzel Jan 23 '23 at 22:47

1 Answers1

1

Here's what I mean.

class MyHomePage extends StatelessWidget {
          @override
          Widget build(BuildContext context) {
            return const Scaffold(
              body: Center(
                child: Container(
                  color: Colors.green,
                  child: Text(" hello ",
                    style: TextStyle(
                      fontSize: 100,
                      backgroundColor: Colors.green,
                    ))),
              ),
            );
          }
        }
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
Denzel
  • 942
  • 5
  • 14
  • This gets the job done, so +1. However, I was hoping for something in terms of the Text widget itself so I could extend that to underlined text in a RichText for example. – ijt Jan 23 '23 at 22:56
  • I'm accepting your answer because I can simulate the underlining with a BoxBorder on the Container. https://stackoverflow.com/questions/47423297/how-can-i-add-a-border-to-a-widget-in-flutter – ijt Jan 23 '23 at 23:04