Open wigl opened 1 year ago
11.1.0
Android, iOS
iPhone 11
Flutter (Channel [user-branch], 3.13.6, on macOS 12.6 21G115 darwin-x64
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, ), ], ), ), ), ], ), ), ); } }
ExtendedText 加上key: ValueKey(textName), 即可修复bug。
key: ValueKey(textName),
Version
11.1.0
Platforms
Android, iOS
Device Model
iPhone 11
flutter info
How to reproduce?
初始样式:
rebuild后,长文本样式:
再次rebuild后,短文本样式:
其他
ExtendedText 加上
key: ValueKey(textName),
即可修复bug。