Ensure TextPainters are disposed when possible. (#8902)
Ensure TextPainters are disposed when possible.
There are a few ways in which TextPainters are used:
* To get the width of what would be rendered; in this case, we delegate all
implementations to calculateTextSpanWidth. We then `dispose` the TextPainter
in that function.
* To instantiate, layout, and paint exactly once; in this case, we `dispose`
immediately after painting, as the documentation says we should.
* To be passed to a CustomPainter. in these cases, I think it is not safe to
immediately dispose. I'm not sure what the expected workflow is.