brand new text method, allow for using width and height properties properly, two new options as well

This commit is contained in:
Luan Nico
2017-12-30 16:50:21 -02:00
parent 8cdc82d16f
commit f3074d6e94

View File

@ -1,9 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'dart:ui'; import 'dart:ui';
import 'dart:ui' as ui show TextStyle;
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart' as material;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
class Util { class Util {
@ -28,13 +27,12 @@ class Util {
}); });
} }
Paragraph text(String text, { double fontSize = 24.0, Color color = Colors.white, fontFamily: 'Arial', double maxWidth = 180.0 }) { material.TextPainter text(String text, { fontSize = 24.0, color = material.Colors.white, fontFamily: 'Arial', maxWidth = 180.0, textAlign: TextAlign.left, textDirection: TextDirection.ltr }) {
ParagraphBuilder paragraph = new ParagraphBuilder(new ParagraphStyle()); material.TextStyle style = new material.TextStyle(color: color, fontSize: fontSize, fontFamily: fontFamily);
paragraph.pushStyle(new ui.TextStyle( material.TextSpan span = new material.TextSpan(style: style, text: text);
color: color, fontSize: fontSize, fontFamily: fontFamily)); material.TextPainter tp = new material.TextPainter(text: span, textAlign: textAlign, textDirection: textDirection);
paragraph.addText(text); tp.layout();
return paragraph.build() return tp;
..layout(new ParagraphConstraints(width: maxWidth));
} }
void enableEvents() { void enableEvents() {