Unverified Commit 92e3436f authored by Abhishek Ghaskata's avatar Abhishek Ghaskata Committed by GitHub

migrate complex layout to null safety (#83894)

parent 1df798a5
...@@ -14,12 +14,12 @@ void main() { ...@@ -14,12 +14,12 @@ void main() {
enum ScrollMode { complex, tile } enum ScrollMode { complex, tile }
class ComplexLayoutApp extends StatefulWidget { class ComplexLayoutApp extends StatefulWidget {
const ComplexLayoutApp({Key key}) : super(key: key); const ComplexLayoutApp({Key? key}) : super(key: key);
@override @override
ComplexLayoutAppState createState() => ComplexLayoutAppState(); ComplexLayoutAppState createState() => ComplexLayoutAppState();
static ComplexLayoutAppState of(BuildContext context) => context.findAncestorStateOfType<ComplexLayoutAppState>(); static ComplexLayoutAppState? of(BuildContext context) => context.findAncestorStateOfType<ComplexLayoutAppState>();
} }
class ComplexLayoutAppState extends State<ComplexLayoutApp> { class ComplexLayoutAppState extends State<ComplexLayoutApp> {
...@@ -55,7 +55,7 @@ class ComplexLayoutAppState extends State<ComplexLayoutApp> { ...@@ -55,7 +55,7 @@ class ComplexLayoutAppState extends State<ComplexLayoutApp> {
} }
class TileScrollLayout extends StatelessWidget { class TileScrollLayout extends StatelessWidget {
const TileScrollLayout({ Key key }) : super(key: key); const TileScrollLayout({ Key? key }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -81,12 +81,12 @@ class TileScrollLayout extends StatelessWidget { ...@@ -81,12 +81,12 @@ class TileScrollLayout extends StatelessWidget {
} }
class ComplexLayout extends StatefulWidget { class ComplexLayout extends StatefulWidget {
const ComplexLayout({ Key key }) : super(key: key); const ComplexLayout({ Key? key }) : super(key: key);
@override @override
ComplexLayoutState createState() => ComplexLayoutState(); ComplexLayoutState createState() => ComplexLayoutState();
static ComplexLayoutState of(BuildContext context) => context.findAncestorStateOfType<ComplexLayoutState>(); static ComplexLayoutState? of(BuildContext context) => context.findAncestorStateOfType<ComplexLayoutState>();
} }
class ComplexLayoutState extends State<ComplexLayout> { class ComplexLayoutState extends State<ComplexLayout> {
...@@ -129,7 +129,7 @@ class ComplexLayoutState extends State<ComplexLayout> { ...@@ -129,7 +129,7 @@ class ComplexLayoutState extends State<ComplexLayout> {
} }
class TopBarMenu extends StatelessWidget { class TopBarMenu extends StatelessWidget {
const TopBarMenu({Key key}) : super(key: key); const TopBarMenu({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -182,7 +182,7 @@ class TopBarMenu extends StatelessWidget { ...@@ -182,7 +182,7 @@ class TopBarMenu extends StatelessWidget {
} }
class MenuItemWithIcon extends StatelessWidget { class MenuItemWithIcon extends StatelessWidget {
const MenuItemWithIcon(this.icon, this.title, this.subtitle, {Key key}) : super(key: key); const MenuItemWithIcon(this.icon, this.title, this.subtitle, {Key? key}) : super(key: key);
final IconData icon; final IconData icon;
final String title; final String title;
...@@ -204,7 +204,7 @@ class MenuItemWithIcon extends StatelessWidget { ...@@ -204,7 +204,7 @@ class MenuItemWithIcon extends StatelessWidget {
} }
class FancyImageItem extends StatelessWidget { class FancyImageItem extends StatelessWidget {
const FancyImageItem(this.index, {Key key}) : super(key: key); const FancyImageItem(this.index, {Key? key}) : super(key: key);
final int index; final int index;
...@@ -228,7 +228,7 @@ class FancyImageItem extends StatelessWidget { ...@@ -228,7 +228,7 @@ class FancyImageItem extends StatelessWidget {
} }
class FancyGalleryItem extends StatelessWidget { class FancyGalleryItem extends StatelessWidget {
const FancyGalleryItem(this.index, {Key key}) : super(key: key); const FancyGalleryItem(this.index, {Key? key}) : super(key: key);
final int index; final int index;
@override @override
...@@ -250,7 +250,7 @@ class FancyGalleryItem extends StatelessWidget { ...@@ -250,7 +250,7 @@ class FancyGalleryItem extends StatelessWidget {
} }
class InfoBar extends StatelessWidget { class InfoBar extends StatelessWidget {
const InfoBar({Key key}) : super(key: key); const InfoBar({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -268,7 +268,7 @@ class InfoBar extends StatelessWidget { ...@@ -268,7 +268,7 @@ class InfoBar extends StatelessWidget {
} }
class IconBar extends StatelessWidget { class IconBar extends StatelessWidget {
const IconBar({Key key}) : super(key: key); const IconBar({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -287,7 +287,7 @@ class IconBar extends StatelessWidget { ...@@ -287,7 +287,7 @@ class IconBar extends StatelessWidget {
} }
class IconWithText extends StatelessWidget { class IconWithText extends StatelessWidget {
const IconWithText(this.icon, this.title, {Key key}) : super(key: key); const IconWithText(this.icon, this.title, {Key? key}) : super(key: key);
final IconData icon; final IconData icon;
final String title; final String title;
...@@ -308,7 +308,7 @@ class IconWithText extends StatelessWidget { ...@@ -308,7 +308,7 @@ class IconWithText extends StatelessWidget {
} }
class MiniIconWithText extends StatelessWidget { class MiniIconWithText extends StatelessWidget {
const MiniIconWithText(this.icon, this.title, {Key key}) : super(key: key); const MiniIconWithText(this.icon, this.title, {Key? key}) : super(key: key);
final IconData icon; final IconData icon;
final String title; final String title;
...@@ -337,7 +337,7 @@ class MiniIconWithText extends StatelessWidget { ...@@ -337,7 +337,7 @@ class MiniIconWithText extends StatelessWidget {
} }
class FatDivider extends StatelessWidget { class FatDivider extends StatelessWidget {
const FatDivider({Key key}) : super(key: key); const FatDivider({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -349,7 +349,7 @@ class FatDivider extends StatelessWidget { ...@@ -349,7 +349,7 @@ class FatDivider extends StatelessWidget {
} }
class UserHeader extends StatelessWidget { class UserHeader extends StatelessWidget {
const UserHeader(this.userName, {Key key}) : super(key: key); const UserHeader(this.userName, {Key? key}) : super(key: key);
final String userName; final String userName;
...@@ -384,7 +384,7 @@ class UserHeader extends StatelessWidget { ...@@ -384,7 +384,7 @@ class UserHeader extends StatelessWidget {
Row( Row(
children: <Widget>[ children: <Widget>[
Text('Yesterday at 11:55 • ', style: Theme.of(context).textTheme.caption), Text('Yesterday at 11:55 • ', style: Theme.of(context).textTheme.caption),
Icon(Icons.people, size: 16.0, color: Theme.of(context).textTheme.caption.color), Icon(Icons.people, size: 16.0, color: Theme.of(context).textTheme.caption!.color),
], ],
), ),
], ],
...@@ -398,7 +398,7 @@ class UserHeader extends StatelessWidget { ...@@ -398,7 +398,7 @@ class UserHeader extends StatelessWidget {
} }
class ItemDescription extends StatelessWidget { class ItemDescription extends StatelessWidget {
const ItemDescription({Key key}) : super(key: key); const ItemDescription({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -410,7 +410,7 @@ class ItemDescription extends StatelessWidget { ...@@ -410,7 +410,7 @@ class ItemDescription extends StatelessWidget {
} }
class ItemImageBox extends StatelessWidget { class ItemImageBox extends StatelessWidget {
const ItemImageBox({Key key}) : super(key: key); const ItemImageBox({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -491,7 +491,7 @@ class ItemImageBox extends StatelessWidget { ...@@ -491,7 +491,7 @@ class ItemImageBox extends StatelessWidget {
} }
class ItemGalleryBox extends StatelessWidget { class ItemGalleryBox extends StatelessWidget {
const ItemGalleryBox(this.index, {Key key}) : super(key: key); const ItemGalleryBox(this.index, {Key? key}) : super(key: key);
final int index; final int index;
...@@ -521,7 +521,7 @@ class ItemGalleryBox extends StatelessWidget { ...@@ -521,7 +521,7 @@ class ItemGalleryBox extends StatelessWidget {
child: Container( child: Container(
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
child: Center( child: Center(
child: Text(tabName, style: Theme.of(context).textTheme.headline5.copyWith(color: Colors.white)), child: Text(tabName, style: Theme.of(context).textTheme.headline5!.copyWith(color: Colors.white)),
), ),
), ),
), ),
...@@ -560,7 +560,7 @@ class ItemGalleryBox extends StatelessWidget { ...@@ -560,7 +560,7 @@ class ItemGalleryBox extends StatelessWidget {
} }
class BottomBar extends StatelessWidget { class BottomBar extends StatelessWidget {
const BottomBar({Key key}) : super(key: key); const BottomBar({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -588,7 +588,7 @@ class BottomBar extends StatelessWidget { ...@@ -588,7 +588,7 @@ class BottomBar extends StatelessWidget {
} }
class BottomBarButton extends StatelessWidget { class BottomBarButton extends StatelessWidget {
const BottomBarButton(this.icon, this.title, {Key key}) : super(key: key); const BottomBarButton(this.icon, this.title, {Key? key}) : super(key: key);
final IconData icon; final IconData icon;
final String title; final String title;
...@@ -611,19 +611,19 @@ class BottomBarButton extends StatelessWidget { ...@@ -611,19 +611,19 @@ class BottomBarButton extends StatelessWidget {
} }
class GalleryDrawer extends StatelessWidget { class GalleryDrawer extends StatelessWidget {
const GalleryDrawer({ Key key }) : super(key: key); const GalleryDrawer({ Key? key }) : super(key: key);
void _changeTheme(BuildContext context, bool value) { void _changeTheme(BuildContext context, bool value) {
ComplexLayoutApp.of(context).lightTheme = value; ComplexLayoutApp.of(context)?.lightTheme = value;
} }
void _changeScrollMode(BuildContext context, ScrollMode mode) { void _changeScrollMode(BuildContext context, ScrollMode mode) {
ComplexLayoutApp.of(context).scrollMode = mode; ComplexLayoutApp.of(context)?.scrollMode = mode;
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final ScrollMode currentMode = ComplexLayoutApp.of(context).scrollMode; final ScrollMode currentMode = ComplexLayoutApp.of(context)!.scrollMode;
return Drawer( return Drawer(
// Note: for real apps, see the Gallery material Drawer demo. More // Note: for real apps, see the Gallery material Drawer demo. More
// typically, a drawer would have a fixed header with a scrolling body // typically, a drawer would have a fixed header with a scrolling body
...@@ -646,22 +646,22 @@ class GalleryDrawer extends StatelessWidget { ...@@ -646,22 +646,22 @@ class GalleryDrawer extends StatelessWidget {
leading: const Icon(Icons.brightness_5), leading: const Icon(Icons.brightness_5),
title: const Text('Light'), title: const Text('Light'),
onTap: () { _changeTheme(context, true); }, onTap: () { _changeTheme(context, true); },
selected: ComplexLayoutApp.of(context).lightTheme, selected: ComplexLayoutApp.of(context)!.lightTheme,
trailing: Radio<bool>( trailing: Radio<bool>(
value: true, value: true,
groupValue: ComplexLayoutApp.of(context).lightTheme, groupValue: ComplexLayoutApp.of(context)!.lightTheme,
onChanged: (bool value) { _changeTheme(context, value); }, onChanged: (bool? value) { _changeTheme(context, value!); },
), ),
), ),
ListTile( ListTile(
leading: const Icon(Icons.brightness_7), leading: const Icon(Icons.brightness_7),
title: const Text('Dark'), title: const Text('Dark'),
onTap: () { _changeTheme(context, false); }, onTap: () { _changeTheme(context, false); },
selected: !ComplexLayoutApp.of(context).lightTheme, selected: !ComplexLayoutApp.of(context)!.lightTheme,
trailing: Radio<bool>( trailing: Radio<bool>(
value: false, value: false,
groupValue: ComplexLayoutApp.of(context).lightTheme, groupValue: ComplexLayoutApp.of(context)!.lightTheme,
onChanged: (bool value) { _changeTheme(context, value); }, onChanged: (bool? value) { _changeTheme(context, value!); },
), ),
), ),
const Divider(), const Divider(),
...@@ -669,10 +669,10 @@ class GalleryDrawer extends StatelessWidget { ...@@ -669,10 +669,10 @@ class GalleryDrawer extends StatelessWidget {
leading: const Icon(Icons.hourglass_empty), leading: const Icon(Icons.hourglass_empty),
title: const Text('Animate Slowly'), title: const Text('Animate Slowly'),
selected: timeDilation != 1.0, selected: timeDilation != 1.0,
onTap: () { ComplexLayoutApp.of(context).toggleAnimationSpeed(); }, onTap: () { ComplexLayoutApp.of(context)!.toggleAnimationSpeed(); },
trailing: Checkbox( trailing: Checkbox(
value: timeDilation != 1.0, value: timeDilation != 1.0,
onChanged: (bool value) { ComplexLayoutApp.of(context).toggleAnimationSpeed(); }, onChanged: (bool? value) { ComplexLayoutApp.of(context)!.toggleAnimationSpeed(); },
), ),
), ),
], ],
...@@ -682,7 +682,7 @@ class GalleryDrawer extends StatelessWidget { ...@@ -682,7 +682,7 @@ class GalleryDrawer extends StatelessWidget {
} }
class FancyDrawerHeader extends StatelessWidget { class FancyDrawerHeader extends StatelessWidget {
const FancyDrawerHeader({Key key}) : super(key: key); const FancyDrawerHeader({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -2,7 +2,7 @@ name: complex_layout ...@@ -2,7 +2,7 @@ name: complex_layout
description: A benchmark of a relatively complex layout. description: A benchmark of a relatively complex layout.
environment: environment:
sdk: ">=2.2.2 <3.0.0" sdk: ">=2.12.0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
......
...@@ -66,7 +66,7 @@ class ResampleFlagVariant extends TestVariant<TestScenario> { ...@@ -66,7 +66,7 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
@override @override
final Set<TestScenario> values = Set<TestScenario>.from(TestScenario.values); final Set<TestScenario> values = Set<TestScenario>.from(TestScenario.values);
TestScenario currentValue; late TestScenario currentValue;
bool get resample { bool get resample {
switch(currentValue) { switch(currentValue) {
case TestScenario.resampleOn90Hz: case TestScenario.resampleOn90Hz:
...@@ -76,7 +76,6 @@ class ResampleFlagVariant extends TestVariant<TestScenario> { ...@@ -76,7 +76,6 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
case TestScenario.resampleOff59Hz: case TestScenario.resampleOff59Hz:
return false; return false;
} }
throw ArgumentError;
} }
double get frequency { double get frequency {
switch(currentValue) { switch(currentValue) {
...@@ -87,10 +86,9 @@ class ResampleFlagVariant extends TestVariant<TestScenario> { ...@@ -87,10 +86,9 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
case TestScenario.resampleOff59Hz: case TestScenario.resampleOff59Hz:
return 59.0; return 59.0;
} }
throw ArgumentError;
} }
Map<String, dynamic> result; Map<String, dynamic>? result;
@override @override
String describeValue(TestScenario value) { String describeValue(TestScenario value) {
...@@ -104,7 +102,6 @@ class ResampleFlagVariant extends TestVariant<TestScenario> { ...@@ -104,7 +102,6 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
case TestScenario.resampleOff59Hz: case TestScenario.resampleOff59Hz:
return 'resample off with 59Hz input'; return 'resample off with 59Hz input';
} }
throw ArgumentError;
} }
@override @override
...@@ -118,7 +115,7 @@ class ResampleFlagVariant extends TestVariant<TestScenario> { ...@@ -118,7 +115,7 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
@override @override
Future<void> tearDown(TestScenario value, bool memento) async { Future<void> tearDown(TestScenario value, bool memento) async {
binding.resamplingEnabled = memento; binding.resamplingEnabled = memento;
binding.reportData[describeValue(value)] = result; binding.reportData![describeValue(value)] = result;
} }
} }
...@@ -134,16 +131,16 @@ Future<void> main() async { ...@@ -134,16 +131,16 @@ Future<void> main() async {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final Finder scrollerFinder = find.byKey(const ValueKey<String>('complex-scroll')); final Finder scrollerFinder = find.byKey(const ValueKey<String>('complex-scroll'));
final ListView scroller = tester.widget<ListView>(scrollerFinder); final ListView scroller = tester.widget<ListView>(scrollerFinder);
final ScrollController controller = scroller.controller; final ScrollController? controller = scroller.controller;
final List<int> frameTimestamp = <int>[]; final List<int> frameTimestamp = <int>[];
final List<double> scrollOffset = <double>[]; final List<double> scrollOffset = <double>[];
final List<Duration> delays = <Duration>[]; final List<Duration> delays = <Duration>[];
binding.addPersistentFrameCallback((Duration timeStamp) { binding.addPersistentFrameCallback((Duration timeStamp) {
if (controller.hasClients) { if (controller?.hasClients == true) {
// This if is necessary because by the end of the test the widget tree // This if is necessary because by the end of the test the widget tree
// is destroyed. // is destroyed.
frameTimestamp.add(timeStamp.inMicroseconds); frameTimestamp.add(timeStamp.inMicroseconds);
scrollOffset.add(controller.offset); scrollOffset.add(controller!.offset);
} }
}); });
......
...@@ -8,7 +8,7 @@ import 'package:integration_test/integration_test_driver.dart' as driver; ...@@ -8,7 +8,7 @@ import 'package:integration_test/integration_test_driver.dart' as driver;
Future<void> main() => driver.integrationDriver( Future<void> main() => driver.integrationDriver(
timeout: const Duration(minutes: 5), timeout: const Duration(minutes: 5),
responseDataCallback: (Map<String, dynamic> data) async { responseDataCallback: (Map<String, dynamic>? data) async {
await driver.writeResponseData( await driver.writeResponseData(
data, data,
testOutputFilename: 'scroll_smoothness_test', testOutputFilename: 'scroll_smoothness_test',
......
...@@ -9,7 +9,7 @@ import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; ...@@ -9,7 +9,7 @@ import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
void main() { void main() {
group('scrolling performance test', () { group('scrolling performance test', () {
FlutterDriver driver; late FlutterDriver driver;
setUpAll(() async { setUpAll(() async {
driver = await FlutterDriver.connect(); driver = await FlutterDriver.connect();
......
...@@ -12,7 +12,7 @@ import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; ...@@ -12,7 +12,7 @@ import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
void main() { void main() {
group('semantics performance test', () { group('semantics performance test', () {
FlutterDriver driver; late FlutterDriver driver;
setUpAll(() async { setUpAll(() async {
driver = await FlutterDriver.connect(printCommunication: true); driver = await FlutterDriver.connect(printCommunication: true);
...@@ -33,10 +33,10 @@ void main() { ...@@ -33,10 +33,10 @@ void main() {
expect(await driver.setSemantics(true), isTrue); expect(await driver.setSemantics(true), isTrue);
}); });
final Iterable<TimelineEvent> semanticsEvents = timeline.events.where((TimelineEvent event) => event.name == 'Semantics'); final Iterable<TimelineEvent>? semanticsEvents = timeline.events?.where((TimelineEvent event) => event.name == 'Semantics');
if (semanticsEvents.length != 2) if (semanticsEvents?.length != 2)
fail('Expected exactly two semantics events, got ${semanticsEvents.length}'); fail('Expected exactly two semantics events, got ${semanticsEvents?.length}');
final Duration semanticsTreeCreation = Duration(microseconds: semanticsEvents.last.timestampMicros - semanticsEvents.first.timestampMicros); final Duration semanticsTreeCreation = Duration(microseconds: semanticsEvents!.last.timestampMicros! - semanticsEvents.first.timestampMicros!);
final String jsonEncoded = json.encode(<String, dynamic>{'initialSemanticsTreeCreation': semanticsTreeCreation.inMilliseconds}); final String jsonEncoded = json.encode(<String, dynamic>{'initialSemanticsTreeCreation': semanticsTreeCreation.inMilliseconds});
File(p.join(testOutputsDirectory, 'complex_layout_semantics_perf.json')).writeAsStringSync(jsonEncoded); File(p.join(testOutputsDirectory, 'complex_layout_semantics_perf.json')).writeAsStringSync(jsonEncoded);
......
...@@ -32,7 +32,7 @@ Future<void> main() async { ...@@ -32,7 +32,7 @@ Future<void> main() async {
child: ComplexLayoutApp(), child: ComplexLayoutApp(),
), ),
)); ));
await SchedulerBinding.instance.endOfFrame; await SchedulerBinding.instance?.endOfFrame;
/// Wait 50ms to allow the raster thread to actually put up the frame. (The /// Wait 50ms to allow the raster thread to actually put up the frame. (The
/// endOfFrame future ends when we send the data to the engine, before /// endOfFrame future ends when we send the data to the engine, before
...@@ -50,9 +50,9 @@ Future<void> main() async { ...@@ -50,9 +50,9 @@ Future<void> main() async {
child: ComplexLayoutApp(), child: ComplexLayoutApp(),
), ),
)); ));
await SchedulerBinding.instance.endOfFrame; await SchedulerBinding.instance?.endOfFrame;
final WidgetController controller = LiveWidgetController(WidgetsBinding.instance); final WidgetController controller = LiveWidgetController(WidgetsBinding.instance!);
// Scroll down // Scroll down
for (int iteration = 0; iteration < maxIterations; iteration += 1) { for (int iteration = 0; iteration < maxIterations; iteration += 1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment