fluttercandies / extended_text

A powerful extended official text for Flutter, which supports Speical Text(Image,@somebody), Custom Background, Custom overFlow, Text Selection.
MIT License
664 stars 134 forks source link

[Bug report] setState 绘制异常 #155

Open wigl opened 1 year ago

wigl commented 1 year ago

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。