Commit ab89d2e4 authored by Adam Barth's avatar Adam Barth

Update to the new TextDecoration API

Now with fewer lists.
parent 3b3d5983
...@@ -31,7 +31,7 @@ const List<Color> textColors = const <Color>[ ...@@ -31,7 +31,7 @@ const List<Color> textColors = const <Color>[
]; ];
final List<TextStyle> textStyles = textColors.map((Color color) { final List<TextStyle> 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(); }).toList();
enum CellState { covered, exploded, cleared, flagged, shown } enum CellState { covered, exploded, cleared, flagged, shown }
......
...@@ -26,7 +26,7 @@ class CardCollection extends StatefulComponent { ...@@ -26,7 +26,7 @@ class CardCollection extends StatefulComponent {
class CardCollectionState extends State<CardCollection> { class CardCollectionState extends State<CardCollection> {
static const TextStyle cardLabelStyle = 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 // TODO(hansmuller): need a local image asset
static const _sunshineURL = "http://www.walltor.com/images/wallpaper/good-morning-sunshine-58540.jpg"; static const _sunshineURL = "http://www.walltor.com/images/wallpaper/good-morning-sunshine-58540.jpg";
......
...@@ -25,13 +25,13 @@ class TappableCard extends StatelessComponent { ...@@ -25,13 +25,13 @@ class TappableCard extends StatelessComponent {
static const TextStyle cardLabelStyle = const TextStyle( static const TextStyle cardLabelStyle = const TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 18.0, fontSize: 18.0,
fontWeight: bold fontWeight: FontWeight.bold
); );
static const TextStyle selectedCardLabelStyle = const TextStyle( static const TextStyle selectedCardLabelStyle = const TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 24.0, fontSize: 24.0,
fontWeight: bold fontWeight: FontWeight.bold
); );
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -20,7 +20,7 @@ class IndexedStackDemoState extends State<IndexedStackDemo> { ...@@ -20,7 +20,7 @@ class IndexedStackDemoState extends State<IndexedStackDemo> {
} }
List<PopupMenuItem> _buildMenu() { List<PopupMenuItem> _buildMenu() {
TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: bold); TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold);
String pad = ''; String pad = '';
return new List<PopupMenuItem>.generate(_itemCount, (int i) { return new List<PopupMenuItem>.generate(_itemCount, (int i) {
pad += '-'; pad += '-';
......
...@@ -91,7 +91,7 @@ class OverlayGeometryApp extends StatefulComponent { ...@@ -91,7 +91,7 @@ class OverlayGeometryApp extends StatefulComponent {
class OverlayGeometryAppState extends State<OverlayGeometryApp> { class OverlayGeometryAppState extends State<OverlayGeometryApp> {
static const TextStyle cardLabelStyle = 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<CardModel> cardModels; List<CardModel> cardModels;
Map<MarkerType, Point> markers = new Map<MarkerType, Point>(); Map<MarkerType, Point> markers = new Map<MarkerType, Point>();
......
...@@ -34,7 +34,7 @@ class PageableListAppState extends State<PageableListApp> { ...@@ -34,7 +34,7 @@ class PageableListAppState extends State<PageableListApp> {
} }
static const TextStyle cardLabelStyle = 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<CardModel> cardModels; List<CardModel> cardModels;
Size pageSize = new Size(200.0, 200.0); Size pageSize = new Size(200.0, 200.0);
......
...@@ -39,9 +39,9 @@ HAL: This mission is too important for me to allow you to jeopardize it.'''; ...@@ -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 daveStyle = new TextStyle(color: Colors.indigo[400], height: 1.8);
final TextStyle halStyle = new TextStyle(color: Colors.red[400], fontFamily: "monospace"); 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( final TextStyle underlineStyle = const TextStyle(
decoration: underline, decoration: TextDecoration.underline,
decorationColor: const Color(0xFF000000), decorationColor: const Color(0xFF000000),
decorationStyle: TextDecorationStyle.wavy decorationStyle: TextDecorationStyle.wavy
); );
......
...@@ -18,7 +18,7 @@ const TextStyle _errorTextStyle = const TextStyle( ...@@ -18,7 +18,7 @@ const TextStyle _errorTextStyle = const TextStyle(
fontSize: 48.0, fontSize: 48.0,
fontWeight: FontWeight.w900, fontWeight: FontWeight.w900,
textAlign: TextAlign.right, textAlign: TextAlign.right,
decoration: underline, decoration: TextDecoration.underline,
decorationColor: const Color(0xFFFF00), decorationColor: const Color(0xFFFF00),
decorationStyle: TextDecorationStyle.double decorationStyle: TextDecorationStyle.double
); );
......
...@@ -71,7 +71,7 @@ class Typography { ...@@ -71,7 +71,7 @@ class Typography {
fontSize: 48.0, fontSize: 48.0,
fontWeight: FontWeight.w900, fontWeight: FontWeight.w900,
textAlign: TextAlign.right, textAlign: TextAlign.right,
decoration: underline, decoration: TextDecoration.underline,
decorationColor: const Color(0xFFFF00), decorationColor: const Color(0xFFFF00),
decorationStyle: TextDecorationStyle.double decorationStyle: TextDecorationStyle.double
); );
......
...@@ -6,21 +6,6 @@ import 'dart:ui' as ui; ...@@ -6,21 +6,6 @@ import 'dart:ui' as ui;
import 'basic_types.dart'; 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>[TextDecoration.underline];
/// Draw a line above each line of text
const overline = const <TextDecoration>[TextDecoration.overline];
/// Draw a line through each line of text
const lineThrough = const <TextDecoration>[TextDecoration.lineThrough];
/// An immutable style in which paint text /// An immutable style in which paint text
class TextStyle { class TextStyle {
const TextStyle({ const TextStyle({
...@@ -70,8 +55,8 @@ class TextStyle { ...@@ -70,8 +55,8 @@ class TextStyle {
/// The distance between the text baselines, as a multiple of the font size. /// The distance between the text baselines, as a multiple of the font size.
final double height; final double height;
/// A list of decorations to paint near the text. /// The decorations to paint near the text.
final List<TextDecoration> decoration; // TODO(ianh): Switch this to a Set<> once Dart supports constant Sets final TextDecoration decoration;
/// The color in which to paint the text decorations. /// The color in which to paint the text decorations.
final Color decorationColor; final Color decorationColor;
...@@ -91,7 +76,7 @@ class TextStyle { ...@@ -91,7 +76,7 @@ class TextStyle {
TextAlign textAlign, TextAlign textAlign,
TextBaseline textBaseline, TextBaseline textBaseline,
double height, double height,
List<TextDecoration> decoration, TextDecoration decoration,
Color decorationColor, Color decorationColor,
TextDecorationStyle decorationStyle TextDecorationStyle decorationStyle
}) { }) {
...@@ -302,26 +287,7 @@ class TextStyle { ...@@ -302,26 +287,7 @@ class TextStyle {
if (decoration != null) { if (decoration != null) {
if (haveDecorationDescription) if (haveDecorationDescription)
decorationDescription += ' '; decorationDescription += ' ';
bool multipleDecorations = false; decorationDescription += '$decoration';
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;
}
haveDecorationDescription = true; haveDecorationDescription = true;
} }
assert(haveDecorationDescription); assert(haveDecorationDescription);
......
...@@ -17,12 +17,7 @@ export 'package:flutter/painting.dart' show ...@@ -17,12 +17,7 @@ export 'package:flutter/painting.dart' show
TextDecoration, TextDecoration,
TextDecorationStyle, TextDecorationStyle,
TextSpan, TextSpan,
TextStyle, TextStyle;
normal,
bold,
underline,
overline,
lineThrough;
/// A render object that displays a paragraph of text /// A render object that displays a paragraph of text
class RenderParagraph extends RenderBox { class RenderParagraph extends RenderBox {
......
...@@ -63,12 +63,7 @@ export 'package:flutter/rendering.dart' show ...@@ -63,12 +63,7 @@ export 'package:flutter/rendering.dart' show
TextStyle, TextStyle,
TransferMode, TransferMode,
ValueChanged, ValueChanged,
VoidCallback, VoidCallback;
bold,
normal,
underline,
overline,
lineThrough;
// PAINTING NODES // PAINTING NODES
......
...@@ -269,7 +269,7 @@ class _EditableTextWidget extends LeafRenderObjectWidget { ...@@ -269,7 +269,7 @@ class _EditableTextWidget extends LeafRenderObjectWidget {
TextSpan _buildTextSpan() { TextSpan _buildTextSpan() {
if (!hideText && value.composing.isValid) { if (!hideText && value.composing.isValid) {
TextStyle composingStyle = style.merge( TextStyle composingStyle = style.merge(
const TextStyle(decoration: underline) const TextStyle(decoration: TextDecoration.underline)
); );
return new StyledTextSpan(style, <TextSpan>[ return new StyledTextSpan(style, <TextSpan>[
......
...@@ -7,8 +7,8 @@ dependencies: ...@@ -7,8 +7,8 @@ dependencies:
collection: '>=1.1.3 <2.0.0' collection: '>=1.1.3 <2.0.0'
intl: '>=0.12.4+2 <0.13.0' intl: '>=0.12.4+2 <0.13.0'
material_design_icons: '>=0.0.3 <0.1.0' material_design_icons: '>=0.0.3 <0.1.0'
sky_engine: 0.0.69 sky_engine: 0.0.70
sky_services: 0.0.69 sky_services: 0.0.70
vector_math: '>=1.4.3 <2.0.0' vector_math: '>=1.4.3 <2.0.0'
# To pin the transitive dependency through mojo_sdk. # To pin the transitive dependency through mojo_sdk.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment