pr suggestions

pull/355/head
Erick Zanardo 3 years ago
parent 5b7b973752
commit 336ebfe2e0

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_ui/pinball_ui.dart';
final _labelStrongTextPaint = TextPaint(
final _boldLabelTextPaint = TextPaint(
style: const TextStyle(
fontSize: 1.8,
color: PinballColors.white,
@ -33,8 +33,8 @@ class ErrorComponent extends SpriteComponent with HasGameRef {
);
/// {@macro error_component}
ErrorComponent.strong({required this.label, Vector2? position})
: _textPaint = _labelStrongTextPaint,
ErrorComponent.bold({required this.label, Vector2? position})
: _textPaint = _boldLabelTextPaint,
super(
position: position,
);
@ -43,16 +43,7 @@ class ErrorComponent extends SpriteComponent with HasGameRef {
final String label;
final TextPaint _textPaint;
@override
Future<void> onLoad() async {
anchor = Anchor.center;
final sprite = await gameRef.loadSprite(
Assets.images.errorBackground.keyName,
);
size = sprite.originalSize / 20;
this.sprite = sprite;
List<String> _splitInLines() {
final maxWidth = size.x - 8;
final lines = <String>[];
var currentLine = '';
@ -69,6 +60,20 @@ class ErrorComponent extends SpriteComponent with HasGameRef {
}
lines.add(currentLine);
return lines;
}
@override
Future<void> onLoad() async {
anchor = Anchor.center;
final sprite = await gameRef.loadSprite(
Assets.images.errorBackground.keyName,
);
size = sprite.originalSize / 20;
this.sprite = sprite;
final lines = _splitInLines();
/// Based on how many lines we have, their size and a small
/// offset due to the centering, this calculates where the lines

@ -16,7 +16,7 @@ class ErrorComponentGame extends AssetsGame {
await add(ErrorComponent(label: text));
await add(
ErrorComponent.strong(
ErrorComponent.bold(
label: text,
position: Vector2(0, 10),
),

@ -7,7 +7,7 @@ import 'package:pinball_components/pinball_components.dart';
import '../../helpers/helpers.dart';
extension IterableX on Iterable<Component> {
extension _IterableX on Iterable<Component> {
int countTexts(String value) {
return where(
(component) => component is TextComponent && component.text == value,
@ -45,9 +45,9 @@ void main() {
});
});
group('when using the stronger font', () {
group('when using the bold font', () {
flameTester.test('renders correctly', (game) async {
await game.ensureAdd(ErrorComponent.strong(label: 'Error Message'));
await game.ensureAdd(ErrorComponent.bold(label: 'Error Message'));
final count = game.descendants().countTexts('Error Message');
expect(count, equals(1));

Loading…
Cancel
Save