From aa29358c5e853ba152b5ea3247c102923958a7f4 Mon Sep 17 00:00:00 2001 From: Jessica Pereira Date: Tue, 21 Feb 2023 18:54:39 -0300 Subject: [PATCH] Fix license page rtl (#120497) * fix license page rtl * fix editor spacings, tests to lateral view * fix defaultSize and setSurfaceSize * add validation for packageList position * fix spacing * simplify align --- packages/flutter/lib/src/material/about.dart | 5 +- .../flutter/test/material/about_test.dart | 130 ++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/about.dart b/packages/flutter/lib/src/material/about.dart index 6e4565802ae..f85adb39d1f 100644 --- a/packages/flutter/lib/src/material/about.dart +++ b/packages/flutter/lib/src/material/about.dart @@ -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( diff --git a/packages/flutter/test/material/about_test.dart b/packages/flutter/test/material/about_test.dart index 81da85f62b2..6f565174266 100644 --- a/packages/flutter/test/material/about_test.dart +++ b/packages/flutter/test/material/about_test.dart @@ -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.fromIterable([ + const LicenseEntryWithLineBreaks(['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.fromIterable([ + const LicenseEntryWithLineBreaks(['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 {