non_normalized_constraints_test.dart 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// THIS TEST IS SENSITIVE TO LINE NUMBERS AT THE TOP OF THIS FILE
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
10
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

class RenderFoo extends RenderShiftedBox {
  RenderFoo({ RenderBox? child }) : super(child);

  @override
  void performLayout() {
    child?.layout(const BoxConstraints(  // THIS MUST BE LINE 17
      minWidth: 100.0, maxWidth: 50.0,
    ));
  }
}

class Foo extends SingleChildRenderObjectWidget {
  const Foo({ super.key, super.child });

  @override
  RenderFoo createRenderObject(BuildContext context) {
    return RenderFoo();
  }
}

// END OF SENSITIVE SECTION

void main() {
35
  testWidgetsWithLeakTracking('Stack parsing in non-normalized constraints error', (WidgetTester tester) async {
36 37 38 39 40 41 42 43
    await tester.pumpWidget(const Foo(child: Placeholder()), Duration.zero, EnginePhase.layout);
    final Object? exception = tester.takeException();
    final String text = exception.toString();
    expect(text, contains('BoxConstraints has non-normalized width constraints.'));
    expect(text, contains('which probably computed the invalid constraints in question:\n  RenderFoo.performLayout ('));
    expect(text, contains('non_normalized_constraints_test.dart:17:12'));
  }, skip: kIsWeb); // [intended] stack traces on web are insufficiently predictable
}