import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:jj_mkvmaker/ui/row_fit.dart'; /// 약속 (row_fit - 82a87da P2 에서 옮김): fitRow 는 판단만 (나눌지 · 줄일 것의 폭 · 모자란 폭), FitButtonRows 는 그 판단대로 그린다 - /// 단추 크기는 줄이지 않고, 한 줄에 안 들면 두 줄, 줄일 것은 남는 폭 (최대 flexMax, flexMin 보다 작으면 뺌). 모듈 하나에 한 번만 둔다 void main() { test('fitRow: 넉넉하면 한 줄 · 줄일 것은 최대 폭', () { final r = fitRow(maxWidth: 960, first: List.filled(6, 40), second: List.filled(6, 40), gap: 8, flexMin: 48, flexMax: 100); expect([r.split, r.flexWidth, r.overflow], [false, 100, 0]); }); test('fitRow: 412 는 두 줄 · 줄일 것은 아래 줄의 남는 폭', () { final r = fitRow(maxWidth: 412, first: List.filled(6, 40), second: List.filled(6, 40), gap: 8, flexMin: 48, flexMax: 100); expect([r.split, r.flexWidth, r.overflow], [true, 100, 0]); }); test('fitRow: 남는 폭이 flexMin 보다 작으면 줄일 것을 뺌 · 두 줄로도 안 들면 모자란 폭', () { final r = fitRow(maxWidth: 260, first: List.filled(6, 40), second: List.filled(6, 40), flexMin: 48, flexMax: 100); expect([r.split, r.flexWidth], [true, 0]); final over = fitRow(maxWidth: 200, first: List.filled(6, 40), second: List.filled(2, 40)); expect([over.split, over.overflow], [true, 40]); }); test('fitRow: forceSplit (손가락 화면) 이면 넓어도 두 줄', () { expect(fitRow(maxWidth: 2000, first: [48], second: [48], forceSplit: true).split, isTrue); }); for (final width in [412.0, 600.0, 960.0]) { testWidgets('FitButtonRows $width: 넘치지 않고 끝 단추가 화면 안 · 단추 크기 그대로', (t) async { t.view.physicalSize = Size(width, 400); t.view.devicePixelRatio = 1; addTearDown(t.view.reset); Widget b(IconData i, String tip) => IconButton(tooltip: tip, icon: Icon(i), onPressed: () {}); await t.pumpWidget(MaterialApp( home: Scaffold( body: Align( alignment: Alignment.bottomCenter, child: FitButtonRows( buttonWidth: 48, first: [for (var i = 0; i < 6; i++) b(Icons.play_arrow, '재생 $i')], secondLead: [b(Icons.volume_up, '음소거')], flex: (w) => SizedBox(width: w, child: Slider(value: 50, max: 100, onChanged: (_) {})), flexMin: 48, flexMax: 100, secondTail: [for (final n in ['속도', '자막', '목록', '팝업', '전체 화면']) b(Icons.more_horiz, n)], ), ), ), )); expect(t.takeException(), isNull); final full = t.getRect(find.byTooltip('전체 화면')); expect(full.right, lessThanOrEqualTo(width)); expect(full.width, greaterThanOrEqualTo(40), reason: '단추를 줄이지 않음'); final twoRows = t.getRect(find.byTooltip('재생 0')).top < t.getRect(find.byTooltip('음소거')).top - 10; expect(twoRows, width < 6 * 48 + 8 + 6 * 48 + 100, reason: '한 줄에 안 들 때만 두 줄'); }); } }