Home > other >  How can I make Flutter Text show trailing space?
How can I make Flutter Text show trailing space?

Time:01-24

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?

CodePudding user response:

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,
                    ))),
              ),
            );
          }
        }
  • Related