局部刷新 简单的例子

https://www.jianshu.com/p/e9f48141218d?tdsourcetag=s_pctim_aiomsg

  1. void main() {
  2. runApp(Sample2());
  3. }
  4. class _Sample2State extends State<Sample2> {
  5. int count = 0;
  6. Text cacheText;
  7. @override
  8. void initState() {
  9. cacheText = Text(
  10. 'cache_text',
  11. textDirection: TextDirection.ltr,
  12. );
  13. }
  14. @override
  15. Widget build(BuildContext context) {
  16. return Column(
  17. children: <Widget>[
  18. RaisedButton(
  19. child: Text(
  20. '$count',
  21. textDirection: TextDirection.ltr,
  22. ),
  23. onPressed: () {
  24. print(this.widget);
  25. setState(() {
  26. count += 1;
  27. });
  28. },
  29. ),
  30. cacheText,
  31. Text('no_cache_text', textDirection: TextDirection.ltr),
  32. ],
  33. );
  34. }
  35. }