Adam Barth 63e7a0e80a Add BuildContext.size as a convenience getter (#6355)
Developers need to get the size of the BuildContext sufficiently often
that we should provide a convenient getter for the value. Having this
getter is also an opportunity to catch common mistakes and provide
useful error messages that guide developers towards better patterns.

Fixes #2321
2016-10-17 12:33:11 -07:00

46 lines
1.2 KiB
Dart

// Copyright 2015 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.
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
void main() {
testWidgets('Align smoke test', (WidgetTester tester) async {
await tester.pumpWidget(
new Align(
child: new Container(),
alignment: const FractionalOffset(0.75, 0.75)
)
);
await tester.pumpWidget(
new Align(
child: new Container(),
alignment: const FractionalOffset(0.5, 0.5)
)
);
});
testWidgets('Shrink wraps in finite space', (WidgetTester tester) async {
GlobalKey alignKey = new GlobalKey();
await tester.pumpWidget(
new ScrollableViewport(
child: new Align(
key: alignKey,
child: new Container(
width: 10.0,
height: 10.0
),
alignment: const FractionalOffset(0.50, 0.50)
)
)
);
final Size size = alignKey.currentContext.size;
expect(size.width, equals(800.0));
expect(size.height, equals(10.0));
});
}