layout_builder_mutations_test.dart 1.82 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/foundation.dart';
6 7 8 9 10 11 12 13
import 'package:flutter/src/widgets/basic.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/layout_builder.dart';
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher;

class Wrapper extends StatelessWidget {
  Wrapper({
    Key key,
14
    @required this.child
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  }) : super(key: key) {
    assert(child != null);
  }

  final Widget child;

  @override
  Widget build(BuildContext context) => child;
}

void main() {
  testWidgets('Moving a global key from another LayoutBuilder at layout time', (WidgetTester tester) async {
    final GlobalKey victimKey = new GlobalKey();

    await tester.pumpWidget(new Row(children: <Widget>[
      new Wrapper(
        child: new LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
32
          return const SizedBox();
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
        }),
      ),
      new Wrapper(
        child: new Wrapper(
          child: new LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
            return new Wrapper(
              child: new SizedBox(key: victimKey)
            );
          })
        )
      ),
    ]));

    await tester.pumpWidget(new Row(children: <Widget>[
      new Wrapper(
        child: new LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
          return new Wrapper(
            child: new SizedBox(key: victimKey)
          );
        })
      ),
      new Wrapper(
        child: new Wrapper(
          child: new LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
57
            return const SizedBox();
58 59 60 61 62 63
          })
        )
      ),
    ]));
  });
}