Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug report] setState 绘制异常 #155

Open
wigl opened this issue Oct 20, 2023 · 0 comments
Open

[Bug report] setState 绘制异常 #155

wigl opened this issue Oct 20, 2023 · 0 comments

Comments

@wigl
Copy link

wigl commented Oct 20, 2023

Version

11.1.0

Platforms

Android, iOS

Device Model

iPhone 11

flutter info

Flutter (Channel [user-branch], 3.13.6, on macOS 12.6 21G115 darwin-x64

How to reproduce?

class _MyHomePageState extends State<MyHomePage> {
  String textName = "短文本";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Container(
        color: Colors.white,
        padding: const EdgeInsets.symmetric(vertical: 50, horizontal: 10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            FilledButton(
              onPressed: () {
                setState(() {
                  if (textName == "短文本") {
                    textName = "转朱阁,低绮户,照无眠。不应有恨,何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共婵娟";
                  } else {
                    textName = "短文本";
                  }
                });
              },
              child: const Text("rebuild"),
            ),
            const SizedBox(height: 50),
            ExtendedText(
              textName,
              // key: ValueKey(textName),
              maxLines: 1,
              softWrap: true,
              overflow: TextOverflow.ellipsis,
              overflowWidget: const TextOverflowWidget(
                position: TextOverflowPosition.end,
                align: TextOverflowAlign.center,
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text('\u2026 '),
                    Icon(
                      Icons.add,
                      color: Colors.redAccent,
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

初始样式:

image

rebuild后,长文本样式:

image

再次rebuild后,短文本样式:

image

其他

ExtendedText 加上key: ValueKey(textName), 即可修复bug。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant