Skip to content

Commit

Permalink
Fix license page rtl (#120497)
Browse files Browse the repository at this point in the history
* fix license page rtl

* fix editor spacings, tests to lateral view

* fix defaultSize and setSurfaceSize

* add validation for packageList position

* fix spacing

* simplify align
  • Loading branch information
jehhxuxu authored Feb 21, 2023
1 parent c6e1a4d commit aa29358
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/flutter/lib/src/material/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,10 @@ class _MasterDetailScaffoldState extends State<_MasterDetailScaffold>
),
),
),
body: _masterPanel(context),
body: Align(
alignment: AlignmentDirectional.centerStart,
child: _masterPanel(context),
),
),
// Detail view stacked above main scaffold and master view.
SafeArea(
Expand Down
130 changes: 130 additions & 0 deletions packages/flutter/test/material/about_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,136 @@ void main() {
expect(tester.takeException().toString(), 'Exception: Injected failure');
expect(find.text('Exception: Injected failure'), findsOneWidget);
});

testWidgets('LicensePage master view layout position - ltr', (WidgetTester tester) async {
const TextDirection textDirection = TextDirection.ltr;
const Size defaultSize = Size(800.0, 600.0);
const Size wideSize = Size(1200.0, 600.0);
const String title = 'License ABC';
LicenseRegistry.addLicense(() {
return Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
const LicenseEntryWithLineBreaks(<String>['ABC'], 'DEF'),
]);
});

// Configure to show the default layout.
await tester.binding.setSurfaceSize(defaultSize);

await tester.pumpWidget(
const MaterialApp(
title: title,
home: Scaffold(
body: Directionality(
textDirection: textDirection,
child: LicensePage(),
),
),
),
);

// To stop loading
await tester.pumpAndSettle();

// If the layout width is less than 840.0 pixels, nested layout is
// used which positions license page title at the top center.
Offset titleOffset = tester.getCenter(find.text(title));
expect(titleOffset, Offset(defaultSize.width / 2, 92.0));
expect(tester.getCenter(find.byType(ListView)), Offset(defaultSize.width / 2, 328.0));

// Configure a wide window to show the lateral UI.
await tester.binding.setSurfaceSize(wideSize);

await tester.pumpWidget(
const MaterialApp(
title: title,
home: Scaffold(
body: Directionality(
textDirection: textDirection,
child: LicensePage(),
),
),
),
);

// To finish the FakeTimer
await tester.pumpAndSettle();

// If the layout width is greater than 840.0 pixels, lateral UI layout
// is used which positions license page title and packageList
// at the top left.
titleOffset = tester.getTopRight(find.text(title));
expect(titleOffset, const Offset(292.0, 136.0));
expect(titleOffset.dx, lessThan(wideSize.width - 320)); // Default master view width is 320.0.
expect(tester.getCenter(find.byType(ListView)), const Offset(160, 356));

// Configure to show the default layout.
await tester.binding.setSurfaceSize(defaultSize);
});

testWidgets('LicensePage master view layout position - rtl', (WidgetTester tester) async {
const TextDirection textDirection = TextDirection.rtl;
const Size defaultSize = Size(800.0, 600.0);
const Size wideSize = Size(1200.0, 600.0);
const String title = 'License ABC';
LicenseRegistry.addLicense(() {
return Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
const LicenseEntryWithLineBreaks(<String>['ABC'], 'DEF'),
]);
});

// Configure to show the default layout.
await tester.binding.setSurfaceSize(defaultSize);

await tester.pumpWidget(
const MaterialApp(
title: title,
home: Scaffold(
body: Directionality(
textDirection: textDirection,
child: LicensePage(),
),
),
),
);

// To stop loading
await tester.pumpAndSettle();

// If the layout width is less than 840.0 pixels, nested layout is
// used which positions license page title at the top center.
Offset titleOffset = tester.getCenter(find.text(title));
expect(titleOffset, Offset(defaultSize.width / 2, 92.0));
expect(tester.getCenter(find.byType(ListView)), Offset(defaultSize.width / 2, 328.0));

// Configure a wide window to show the lateral UI.
await tester.binding.setSurfaceSize(wideSize);

await tester.pumpWidget(
const MaterialApp(
title: title,
home: Scaffold(
body: Directionality(
textDirection: textDirection,
child: LicensePage(),
),
),
),
);

// To finish the FakeTimer
await tester.pumpAndSettle();

// If the layout width is greater than 840.0 pixels, lateral UI layout
// is used which positions license page title and packageList
// at the top right.
titleOffset = tester.getTopLeft(find.text(title));
expect(titleOffset, const Offset(908.0, 136.0));
expect(titleOffset.dx, greaterThan(wideSize.width - 320)); // Default master view width is 320.0.
expect(tester.getCenter(find.byType(ListView)), const Offset(1040.0, 356.0));

// Configure to show the default layout.
await tester.binding.setSurfaceSize(defaultSize);
});
}

class FakeLicenseEntry extends LicenseEntry {
Expand Down

0 comments on commit aa29358

Please sign in to comment.