From ab89d2e499139445d6493657049c694527729f05 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 9 Dec 2015 14:02:58 -0800 Subject: [PATCH] Update to the new TextDecoration API Now with fewer lists. --- examples/mine_digger/lib/main.dart | 2 +- examples/widgets/card_collection.dart | 2 +- examples/widgets/ensure_visible.dart | 4 +- examples/widgets/indexed_stack.dart | 2 +- examples/widgets/overlay_geometry.dart | 2 +- examples/widgets/pageable_list.dart | 2 +- examples/widgets/styled_text.dart | 4 +- .../lib/src/material/material_app.dart | 2 +- .../flutter/lib/src/material/typography.dart | 2 +- .../flutter/lib/src/painting/text_style.dart | 42 ++----------------- .../flutter/lib/src/rendering/paragraph.dart | 7 +--- packages/flutter/lib/src/widgets/basic.dart | 7 +--- .../lib/src/widgets/editable_text.dart | 2 +- packages/flutter/pubspec.yaml | 4 +- 14 files changed, 20 insertions(+), 64 deletions(-) diff --git a/examples/mine_digger/lib/main.dart b/examples/mine_digger/lib/main.dart index 6feb708cb2..626f494167 100644 --- a/examples/mine_digger/lib/main.dart +++ b/examples/mine_digger/lib/main.dart @@ -31,7 +31,7 @@ const List textColors = const [ ]; final List textStyles = textColors.map((Color color) { - return new TextStyle(color: color, fontWeight: bold, textAlign: TextAlign.center); + return new TextStyle(color: color, fontWeight: FontWeight.bold, textAlign: TextAlign.center); }).toList(); enum CellState { covered, exploded, cleared, flagged, shown } diff --git a/examples/widgets/card_collection.dart b/examples/widgets/card_collection.dart index ce81b53e0e..433b62e612 100644 --- a/examples/widgets/card_collection.dart +++ b/examples/widgets/card_collection.dart @@ -26,7 +26,7 @@ class CardCollection extends StatefulComponent { class CardCollectionState extends State { static const TextStyle cardLabelStyle = - const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: bold); + const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold); // TODO(hansmuller): need a local image asset static const _sunshineURL = "http://www.walltor.com/images/wallpaper/good-morning-sunshine-58540.jpg"; diff --git a/examples/widgets/ensure_visible.dart b/examples/widgets/ensure_visible.dart index 54122709ba..350369a451 100644 --- a/examples/widgets/ensure_visible.dart +++ b/examples/widgets/ensure_visible.dart @@ -25,13 +25,13 @@ class TappableCard extends StatelessComponent { static const TextStyle cardLabelStyle = const TextStyle( color: Colors.white, fontSize: 18.0, - fontWeight: bold + fontWeight: FontWeight.bold ); static const TextStyle selectedCardLabelStyle = const TextStyle( color: Colors.white, fontSize: 24.0, - fontWeight: bold + fontWeight: FontWeight.bold ); Widget build(BuildContext context) { diff --git a/examples/widgets/indexed_stack.dart b/examples/widgets/indexed_stack.dart index 3b07557287..cf80ea98e3 100644 --- a/examples/widgets/indexed_stack.dart +++ b/examples/widgets/indexed_stack.dart @@ -20,7 +20,7 @@ class IndexedStackDemoState extends State { } List _buildMenu() { - TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: bold); + TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold); String pad = ''; return new List.generate(_itemCount, (int i) { pad += '-'; diff --git a/examples/widgets/overlay_geometry.dart b/examples/widgets/overlay_geometry.dart index ed6b5bffda..16c8d1509a 100644 --- a/examples/widgets/overlay_geometry.dart +++ b/examples/widgets/overlay_geometry.dart @@ -91,7 +91,7 @@ class OverlayGeometryApp extends StatefulComponent { class OverlayGeometryAppState extends State { static const TextStyle cardLabelStyle = - const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: bold); + const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold); List cardModels; Map markers = new Map(); diff --git a/examples/widgets/pageable_list.dart b/examples/widgets/pageable_list.dart index 26d217222d..1e77a3442b 100644 --- a/examples/widgets/pageable_list.dart +++ b/examples/widgets/pageable_list.dart @@ -34,7 +34,7 @@ class PageableListAppState extends State { } static const TextStyle cardLabelStyle = - const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: bold); + const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold); List cardModels; Size pageSize = new Size(200.0, 200.0); diff --git a/examples/widgets/styled_text.dart b/examples/widgets/styled_text.dart index 134910a8cd..5341b7fdfe 100644 --- a/examples/widgets/styled_text.dart +++ b/examples/widgets/styled_text.dart @@ -39,9 +39,9 @@ HAL: This mission is too important for me to allow you to jeopardize it.'''; final TextStyle daveStyle = new TextStyle(color: Colors.indigo[400], height: 1.8); final TextStyle halStyle = new TextStyle(color: Colors.red[400], fontFamily: "monospace"); - final TextStyle boldStyle = const TextStyle(fontWeight: bold); + final TextStyle boldStyle = const TextStyle(fontWeight: FontWeight.bold); final TextStyle underlineStyle = const TextStyle( - decoration: underline, + decoration: TextDecoration.underline, decorationColor: const Color(0xFF000000), decorationStyle: TextDecorationStyle.wavy ); diff --git a/packages/flutter/lib/src/material/material_app.dart b/packages/flutter/lib/src/material/material_app.dart index 0f2a907611..3578f3c764 100644 --- a/packages/flutter/lib/src/material/material_app.dart +++ b/packages/flutter/lib/src/material/material_app.dart @@ -18,7 +18,7 @@ const TextStyle _errorTextStyle = const TextStyle( fontSize: 48.0, fontWeight: FontWeight.w900, textAlign: TextAlign.right, - decoration: underline, + decoration: TextDecoration.underline, decorationColor: const Color(0xFFFF00), decorationStyle: TextDecorationStyle.double ); diff --git a/packages/flutter/lib/src/material/typography.dart b/packages/flutter/lib/src/material/typography.dart index 1d1f24ff2c..a868db4660 100644 --- a/packages/flutter/lib/src/material/typography.dart +++ b/packages/flutter/lib/src/material/typography.dart @@ -71,7 +71,7 @@ class Typography { fontSize: 48.0, fontWeight: FontWeight.w900, textAlign: TextAlign.right, - decoration: underline, + decoration: TextDecoration.underline, decorationColor: const Color(0xFFFF00), decorationStyle: TextDecorationStyle.double ); diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart index 7f0230a32a..512d9aa3de 100644 --- a/packages/flutter/lib/src/painting/text_style.dart +++ b/packages/flutter/lib/src/painting/text_style.dart @@ -6,21 +6,6 @@ import 'dart:ui' as ui; import 'basic_types.dart'; -/// A normal font weight -const normal = FontWeight.w400; - -/// A bold font weight -const bold = FontWeight.w700; - -/// Draw a line underneath each line of text -const underline = const [TextDecoration.underline]; - -/// Draw a line above each line of text -const overline = const [TextDecoration.overline]; - -/// Draw a line through each line of text -const lineThrough = const [TextDecoration.lineThrough]; - /// An immutable style in which paint text class TextStyle { const TextStyle({ @@ -70,8 +55,8 @@ class TextStyle { /// The distance between the text baselines, as a multiple of the font size. final double height; - /// A list of decorations to paint near the text. - final List decoration; // TODO(ianh): Switch this to a Set<> once Dart supports constant Sets + /// The decorations to paint near the text. + final TextDecoration decoration; /// The color in which to paint the text decorations. final Color decorationColor; @@ -91,7 +76,7 @@ class TextStyle { TextAlign textAlign, TextBaseline textBaseline, double height, - List decoration, + TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle }) { @@ -302,26 +287,7 @@ class TextStyle { if (decoration != null) { if (haveDecorationDescription) decorationDescription += ' '; - bool multipleDecorations = false; - for (TextDecoration value in decoration) { - if (multipleDecorations) - decorationDescription += '+'; - switch (value) { - case TextDecoration.none: - decorationDescription += 'none'; - break; - case TextDecoration.underline: - decorationDescription += 'underline'; - break; - case TextDecoration.overline: - decorationDescription += 'overline'; - break; - case TextDecoration.lineThrough: - decorationDescription += 'line-through'; - break; - } - multipleDecorations = true; - } + decorationDescription += '$decoration'; haveDecorationDescription = true; } assert(haveDecorationDescription); diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index e16f80031c..6c378b6ab0 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -17,12 +17,7 @@ export 'package:flutter/painting.dart' show TextDecoration, TextDecorationStyle, TextSpan, - TextStyle, - normal, - bold, - underline, - overline, - lineThrough; + TextStyle; /// A render object that displays a paragraph of text class RenderParagraph extends RenderBox { diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 6ec04999d9..a9ce22040a 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -63,12 +63,7 @@ export 'package:flutter/rendering.dart' show TextStyle, TransferMode, ValueChanged, - VoidCallback, - bold, - normal, - underline, - overline, - lineThrough; + VoidCallback; // PAINTING NODES diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index b568968b11..5740aefad3 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -269,7 +269,7 @@ class _EditableTextWidget extends LeafRenderObjectWidget { TextSpan _buildTextSpan() { if (!hideText && value.composing.isValid) { TextStyle composingStyle = style.merge( - const TextStyle(decoration: underline) + const TextStyle(decoration: TextDecoration.underline) ); return new StyledTextSpan(style, [ diff --git a/packages/flutter/pubspec.yaml b/packages/flutter/pubspec.yaml index 928c89ec73..96f416c263 100644 --- a/packages/flutter/pubspec.yaml +++ b/packages/flutter/pubspec.yaml @@ -7,8 +7,8 @@ dependencies: collection: '>=1.1.3 <2.0.0' intl: '>=0.12.4+2 <0.13.0' material_design_icons: '>=0.0.3 <0.1.0' - sky_engine: 0.0.69 - sky_services: 0.0.69 + sky_engine: 0.0.70 + sky_services: 0.0.70 vector_math: '>=1.4.3 <2.0.0' # To pin the transitive dependency through mojo_sdk.