Skip to content

[RenderParagraph] - Should call markNeedsLayout in the textAlign setter #140756

@matthew-carroll

Description

@matthew-carroll

Steps to reproduce

  1. Use the provided reproduction code
  2. Tap on the text to change the alignment from left to right

Expected results

The LayoutBuilder surrounding the Text widget should build again, because the layout of its descendantText changed.

Actual results

The LayoutBuilder doesn't run again because the descendant Text didn't report a layout change. It only reported dirty paint.

Code sample

Code sample
import 'package:flutter/material.dart';

const Color darkBlue = Color.fromARGB(255, 18, 32, 47);

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
      ),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: MyWidget(),
      ),
    );
  }
}

class MyWidget extends StatefulWidget {
  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        print("Running LayoutBuilder");
        return SizedBox(
          width: double.infinity, 
          child: TextAlignChanger(),
        );
      }
    );
  }
}


class TextAlignChanger extends StatefulWidget {
  @override
  State<TextAlignChanger> createState() => _TextAlignChangerState();
}

class _TextAlignChangerState extends State<TextAlignChanger> {
  TextAlign _textAlign = TextAlign.left;
  
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => setState(() {
        print("Changing text alignment to the right");
        _textAlign = TextAlign.right;
      }),
      child: Text(
        'Hello, World!',
        textAlign: _textAlign,
        style: Theme.of(context).textTheme.headlineMedium,
      ),
    );
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Reproduced in Dart Pad: Based on Flutter 3.16.5 Dart SDK 3.2.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.16Found to occur in 3.16found in release: 3.18Found to occur in 3.18frameworkflutter/packages/flutter repository. See also f: labels.good first issueRelatively approachable for first-time contributorshas reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions