Skip to content

text justify is not working correctly with RichText #28891

@attdona

Description

@attdona

TextAlign.justify with RichText does not works as expected:

MVCE:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

List<TextSpan> getSpan() {
  List<TextSpan> spans = List<TextSpan>();

  spans.add(TextSpan(
    text: "And thus We made them rise ",
  ));

  spans.add(TextSpan(
    text: " they ",
    style: TextStyle(
      decoration: TextDecoration.underline,
    ),
  ));

  spans.add(TextSpan(
    text: " And thus We made them rise ",
  ));
  return spans;
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(title: Text("MVCE"),),
          body: RichText(
          softWrap: true,
          textAlign: TextAlign.justify,
          text: TextSpan(
            style: TextStyle(
              color: Colors.black,
              fontWeight: FontWeight.w500,
              fontSize: 16.0,
            ),
            children: getSpan(),
          ),
        ))
    );
  }
}

Cross posted from here

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: typographyText rendering, possibly libtxtengineflutter/engine related. See also e: labels.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions