Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix license page rtl #120497

Merged
merged 8 commits into from Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/flutter/lib/src/material/about.dart
Expand Up @@ -1365,6 +1365,7 @@ class _MasterDetailScaffoldState extends State<_MasterDetailScaffold>

@override
Widget build(BuildContext context) {
final TextDirection directionality = Directionality.of(context);
return Stack(
children: <Widget>[
Scaffold(
Expand Down Expand Up @@ -1396,7 +1397,10 @@ class _MasterDetailScaffoldState extends State<_MasterDetailScaffold>
),
),
),
body: _masterPanel(context),
body: Align(
jehhxuxu marked this conversation as resolved.
Show resolved Hide resolved
alignment: directionality == TextDirection.ltr ? Alignment.centerLeft : Alignment.centerRight,
child: _masterPanel(context),
),
),
// Detail view stacked above main scaffold and master view.
SafeArea(
Expand Down
96 changes: 96 additions & 0 deletions packages/flutter/test/material/about_test.dart
Expand Up @@ -1006,6 +1006,102 @@ 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 narrowSize = Size(800.0, 600.0);
jehhxuxu marked this conversation as resolved.
Show resolved Hide resolved
const Size wideSize = Size(1200.0, 600.0);
const String title = 'License ABC';

// Configure a narrow window to show the default layout.
await tester.binding.setSurfaceSize(narrowSize);

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

// 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(narrowSize.width / 2, 92.0));
jehhxuxu marked this conversation as resolved.
Show resolved Hide resolved

// Configure a wide window to show the lateral UI.
await tester.binding.setSurfaceSize(wideSize);
jehhxuxu marked this conversation as resolved.
Show resolved Hide resolved

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

// If the layout width is greater than 840.0 pixels, lateral UI layout
// is used which positions license page title 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.
});

testWidgets('LicensePage master view layout position - rtl', (WidgetTester tester) async {
const TextDirection textDirection = TextDirection.rtl;
const Size narrowSize = Size(800.0, 600.0);
const Size wideSize = Size(1200.0, 600.0);
const String title = 'License ABC';

// Configure a narrow window to show the default layout.
await tester.binding.setSurfaceSize(narrowSize);

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

// 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(narrowSize.width / 2, 92.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(),
),
),
),
);

// If the layout width is greater than 840.0 pixels, lateral UI layout
// is used which positions license page title 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.
});
}

class FakeLicenseEntry extends LicenseEntry {
Expand Down