From 2e8bebd178db1b8e1aa0071e013175cba412d398 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Fri, 27 Jan 2023 12:42:42 -0800 Subject: [PATCH] Remove single window assumption from macrobenchmark (#119368) --- .../macrobenchmarks/lib/src/clipper_cache.dart | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/dev/benchmarks/macrobenchmarks/lib/src/clipper_cache.dart b/dev/benchmarks/macrobenchmarks/lib/src/clipper_cache.dart index 85098ef34cb..0db2c02021c 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/clipper_cache.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/clipper_cache.dart @@ -23,11 +23,6 @@ class _ClipperCachePageState extends State @override void initState() { super.initState(); - const double itemHeight = 140; - _topMargin = (window.physicalSize.height / window.devicePixelRatio - itemHeight * 3) / 2; - if (_topMargin < 0) { - _topMargin = 0; - } _controller.addListener(() { if (_controller.offset < 10) { _controller.animateTo(_animateOffset, duration: const Duration(milliseconds: 1000), curve: Curves.ease); @@ -40,6 +35,18 @@ class _ClipperCachePageState extends State }); } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + const double itemHeight = 140; + final FlutterView view = View.of(context); + _topMargin = (view.physicalSize.height / view.devicePixelRatio - itemHeight * 3) / 2; + if (_topMargin < 0) { + _topMargin = 0; + } + } + @override Widget build(BuildContext context) { return Scaffold(