Fix crash when dumping the app if it uses RichText

Specifically:

* Handle null styles in TextSpan without crashing in toString().

* Handle null children in TextSpan child lists without crashing in
  toString().

* Handle entirely empty TextSpans in toString() explicitly.

* Assert that TextSpans don't contain nulls in various places. This is
  done more often than one might think necessary, because it turns out
  that TextSpan takes a (mutable) List for one of its arguments, so
  who knows what it will contain at any given time. By asserting all
  over the place, hopefully we'll catch it near the change if they do
  change it.

* Add a RichText example to Stocks to exercise RichText and TextSpans.

See also: https://github.com/flutter/flutter/issues/2514, https://github.com/flutter/flutter/issues/2519
This commit is contained in:
Ian Hickson
2016-03-09 00:38:21 -08:00
parent 3dc22dce58
commit 7cf2dbdf37
6 changed files with 100 additions and 4 deletions

View File

@@ -46,6 +46,19 @@ class StockSymbolView extends StatelessComponent {
),
new Text('Market Cap', style: headings),
new Text('${stock.marketCap}'),
new Container(
height: 8.0
),
new RichText(
text: new TextSpan(
style: DefaultTextStyle.of(context).merge(new TextStyle(fontSize: 8.0)),
text: 'Prices may be delayed by ',
children: <TextSpan>[
new TextSpan(text: 'several', style: new TextStyle(fontStyle: FontStyle.italic)),
new TextSpan(text: ' years.'),
]
)
),
],
justifyContent: FlexJustifyContent.collapse
)