import 'package:fancake/core/ui/app_dialog.dart' show keepWords; import 'package:flutter/painting.dart'; import 'package:flutter_test/flutter_test.dart'; /// 10/6 실기기 D-4 — 광고 안내 모달 제목이 「얻으세 / 요.」로 낱말 중간에서 바뀌었다. void main() { test('줄은 공백에서만 바뀐다', () { const text = '더 많은 기여의 기회를 얻으세요.'; final joined = keepWords(text); expect(joined.replaceAll('⁠', ''), text); // 여러 폭에서 줄 끝이 늘 공백 앞뒤다. // 가장 긴 어절(「얻으세요.」)보다 넓은 폭만 — 그보다 좁으면 엔진이 어절 안을 끊는다. for (var width = 160.0; width <= 400; width += 7) { final painter = TextPainter( text: TextSpan(text: joined, style: const TextStyle(fontSize: 25)), textDirection: TextDirection.ltr, )..layout(maxWidth: width); for (final line in painter.computeLineMetrics().skip(1)) { final start = painter .getPositionForOffset(Offset(0, line.baseline - line.ascent + 1)) .offset; expect( start == 0 || joined[start - 1] == ' ', isTrue, reason: 'width $width: 「${joined.substring(start).replaceAll('⁠', '')}」', ); } } }); }