Add OverflowBox example and update existing examples under basic.dart (#121213)
Add `OverflowBox` example and update existing examples under `basic.dart`
This commit is contained in:
29
examples/api/test/widgets/basic/absorb_pointer.0_test.dart
Normal file
29
examples/api/test/widgets/basic/absorb_pointer.0_test.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/absorb_pointer.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('AbsorbPointer prevents hit testing on its child', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.AbsorbPointerApp(),
|
||||
);
|
||||
|
||||
// Get the center of the stack.
|
||||
final Offset center = tester.getCenter(find.byType(Stack).first);
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
|
||||
// Add the point to the center of the stack where the AbsorbPointer is.
|
||||
await gesture.addPointer(location: center);
|
||||
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
|
||||
|
||||
// Move the pointer to the left of the stack where the AbsorbPointer is not.
|
||||
await gesture.moveTo(center + const Offset(-100, 0));
|
||||
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
|
||||
});
|
||||
}
|
||||
25
examples/api/test/widgets/basic/aspect_ratio.0_test.dart
Normal file
25
examples/api/test/widgets/basic/aspect_ratio.0_test.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/aspect_ratio.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('AspectRatio applies 16 / 9 aspect ratio on its child', (WidgetTester tester) async {
|
||||
const double height = 100.0;
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.AspectRatioApp(),
|
||||
);
|
||||
|
||||
final Size parentContainer = tester.getSize(find.byType(Container).first);
|
||||
expect(parentContainer.width, 800.0);
|
||||
expect(parentContainer.height, height);
|
||||
|
||||
final Size childContainer = tester.getSize(find.byType(Container).last);
|
||||
expect(childContainer.width, height * 16 / 9);
|
||||
expect(childContainer.height, height);
|
||||
});
|
||||
}
|
||||
23
examples/api/test/widgets/basic/aspect_ratio.1_test.dart
Normal file
23
examples/api/test/widgets/basic/aspect_ratio.1_test.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/aspect_ratio.1.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('AspectRatio applies 2.0 aspect ratio on its child', (WidgetTester tester) async {
|
||||
const Size containerSize = Size(100, 100);
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.AspectRatioApp(),
|
||||
);
|
||||
|
||||
final Size parentContainer = tester.getSize(find.byType(Container).first);
|
||||
expect(parentContainer, containerSize);
|
||||
|
||||
final Size childContainer = tester.getSize(find.byType(Container).last);
|
||||
expect(childContainer, Size(containerSize.height, containerSize.height / 2.0));
|
||||
});
|
||||
}
|
||||
23
examples/api/test/widgets/basic/aspect_ratio.2_test.dart
Normal file
23
examples/api/test/widgets/basic/aspect_ratio.2_test.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/aspect_ratio.2.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('AspectRatio applies 0.5 aspect ratio on its child', (WidgetTester tester) async {
|
||||
const Size containerSize = Size(100, 100);
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.AspectRatioApp(),
|
||||
);
|
||||
|
||||
final Size parentContainer = tester.getSize(find.byType(Container).first);
|
||||
expect(parentContainer, containerSize);
|
||||
|
||||
final Size childContainer = tester.getSize(find.byType(Container).last);
|
||||
expect(childContainer, Size(containerSize.height * 0.5, containerSize.height));
|
||||
});
|
||||
}
|
||||
37
examples/api/test/widgets/basic/expanded.0_test.dart
Normal file
37
examples/api/test/widgets/basic/expanded.0_test.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/expanded.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Expanded widget in a Column', (WidgetTester tester) async {
|
||||
const double totalHeight = 600;
|
||||
const double appBarHeight = 56.0;
|
||||
const double columnWidth = 100.0;
|
||||
const double columnHeight = totalHeight - appBarHeight;
|
||||
const double containerOneHeight = 100;
|
||||
const double containerTwoHeight = columnHeight - 200;
|
||||
const double containerThreeHeight = 100;
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.ExpandedApp(),
|
||||
);
|
||||
|
||||
final Size column = tester.getSize(find.byType(Column));
|
||||
expect(column, const Size(columnWidth, columnHeight));
|
||||
|
||||
final Size containerOne = tester.getSize(find.byType(Container).at(0));
|
||||
expect(containerOne, const Size(columnWidth, containerOneHeight));
|
||||
|
||||
// This Container is wrapped in an Expanded widget, so it should take up
|
||||
// the remaining space in the Column.
|
||||
final Size containerTwo = tester.getSize(find.byType(Container).at(1));
|
||||
expect(containerTwo, const Size(columnWidth, containerTwoHeight));
|
||||
|
||||
final Size containerThree = tester.getSize(find.byType(Container).at(2));
|
||||
expect(containerThree, const Size(columnWidth, containerThreeHeight));
|
||||
});
|
||||
}
|
||||
37
examples/api/test/widgets/basic/expanded.1_test.dart
Normal file
37
examples/api/test/widgets/basic/expanded.1_test.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/expanded.1.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Expanded widgets in a Row', (WidgetTester tester) async {
|
||||
const double rowWidth = 800.0;
|
||||
const double rowHeight = 100.0;
|
||||
const double containerOneWidth = (rowWidth - 50) * 2 / 3;
|
||||
const double containerTwoWidth = 50;
|
||||
const double containerThreeWidth = (rowWidth - 50) * 1 / 3;
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.ExpandedApp(),
|
||||
);
|
||||
|
||||
final Size row = tester.getSize(find.byType(Row));
|
||||
expect(row, const Size(rowWidth, rowHeight));
|
||||
|
||||
// This container is wrapped in an Expanded widget, so it should take up
|
||||
// two thirds of the remaining space in the Row.
|
||||
final Size containerOne = tester.getSize(find.byType(Container).at(0));
|
||||
expect(containerOne, const Size(containerOneWidth, rowHeight));
|
||||
|
||||
final Size containerTwo = tester.getSize(find.byType(Container).at(1));
|
||||
expect(containerTwo, const Size(containerTwoWidth, rowHeight));
|
||||
|
||||
// This container is wrapped in an Expanded widget, so it should take up
|
||||
// one third of the remaining space in the Row.
|
||||
final Size containerThree = tester.getSize(find.byType(Container).at(2));
|
||||
expect(containerThree, const Size(containerThreeWidth, rowHeight));
|
||||
});
|
||||
}
|
||||
28
examples/api/test/widgets/basic/fitted_box.0_test.dart
Normal file
28
examples/api/test/widgets/basic/fitted_box.0_test.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/fitted_box.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
setUpAll(() {
|
||||
HttpOverrides.global = null;
|
||||
});
|
||||
|
||||
testWidgets('FittedBox scales the image to fill the parent container', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.FittedBoxApp(),
|
||||
);
|
||||
|
||||
final Size containerSize = tester.getSize(find.byType(Container));
|
||||
expect(containerSize, const Size(300, 400));
|
||||
|
||||
// FittedBox should scale the image to fill the parent container.
|
||||
final FittedBox fittedBox = tester.widget(find.byType(FittedBox));
|
||||
expect(fittedBox.fit, BoxFit.fill);
|
||||
});
|
||||
}
|
||||
35
examples/api/test/widgets/basic/flow.0_test.dart
Normal file
35
examples/api/test/widgets/basic/flow.0_test.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/flow.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Clicking on the menu icon opens the Flow menu', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.FlowApp(),
|
||||
);
|
||||
|
||||
// The menu icon is in the top left corner of the screen.
|
||||
Offset menuIcon = tester.getCenter(find.byIcon(Icons.menu));
|
||||
expect(menuIcon, const Offset(80.0, 144.0));
|
||||
|
||||
// The home icon is also in the top left corner of the screen.
|
||||
Offset homeIcon = tester.getCenter(find.byIcon(Icons.home));
|
||||
expect(homeIcon, const Offset(80.0, 144.0));
|
||||
|
||||
// Tap the menu icon to open the flow menu.
|
||||
await tester.tapAt(menuIcon);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The home icon is still in the top left corner of the screen.
|
||||
homeIcon = tester.getCenter(find.byIcon(Icons.home));
|
||||
expect(homeIcon, const Offset(80.0, 144.0));
|
||||
|
||||
// The menu icon is now in the top right corner of the screen.
|
||||
menuIcon = tester.getCenter(find.byIcon(Icons.menu));
|
||||
expect(menuIcon, const Offset(720.0, 144.0));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/fractionally_sized_box.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('FractionallySizedBox sizes DecoratedBox', (WidgetTester tester) async {
|
||||
const double appBarHeight = 56.0;
|
||||
const double widthFactor = 0.5;
|
||||
const double heightFactor = 0.5;
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.FractionallySizedBoxApp(),
|
||||
);
|
||||
|
||||
final FractionallySizedBox fractionallySizedBox = tester.widget(find.byType(FractionallySizedBox));
|
||||
expect(fractionallySizedBox.widthFactor, widthFactor);
|
||||
expect(fractionallySizedBox.heightFactor, heightFactor);
|
||||
|
||||
final Size boxSize = tester.getSize(find.byType(DecoratedBox));
|
||||
expect(boxSize.width, 800 * widthFactor);
|
||||
expect(boxSize.height, (600 - appBarHeight) * heightFactor);
|
||||
});
|
||||
}
|
||||
33
examples/api/test/widgets/basic/ignore_pointer.0_test.dart
Normal file
33
examples/api/test/widgets/basic/ignore_pointer.0_test.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/ignore_pointer.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('IgnorePointer ignores pointer on the ElevatedButton', (WidgetTester tester) async {
|
||||
const String clickButtonText = 'Click me!';
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.IgnorePointerApp(),
|
||||
);
|
||||
|
||||
// The ElevatedButton is clickable.
|
||||
expect(find.text('Ignoring: false'), findsOneWidget);
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
|
||||
await gesture.addPointer(location: tester.getCenter(find.text(clickButtonText)));
|
||||
// On hovering the ElevatedButton, the cursor should be SystemMouseCursors.click.
|
||||
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
|
||||
|
||||
// Tap to set ignoring pointer to true.
|
||||
await tester.tap(find.text('Set ignoring to true'));
|
||||
await tester.pump();
|
||||
|
||||
// The ElevatedButton is not clickable so the cursor should be SystemMouseCursors.basic.
|
||||
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
|
||||
});
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('has correct forward rendering mechanism', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const example.MyApp());
|
||||
await tester.pumpWidget(const example.IndexedStackApp());
|
||||
|
||||
final Finder gesture2 = find.byKey(const Key('gesture2'));
|
||||
final Element containerFinder = find.byKey(const Key('Dash')).evaluate().first;
|
||||
@@ -31,7 +31,7 @@ void main() {
|
||||
expect(containerFinder2.renderObject!.debugNeedsPaint, false);
|
||||
});
|
||||
testWidgets('has correct backward rendering mechanism', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const example.MyApp());
|
||||
await tester.pumpWidget(const example.IndexedStackApp());
|
||||
|
||||
final Finder gesture1 = find.byKey(const Key('gesture1'));
|
||||
final Element containerFinder = find.byKey(const Key('Dash')).evaluate().first;
|
||||
@@ -51,7 +51,7 @@ void main() {
|
||||
expect(containerFinder2.renderObject!.debugNeedsPaint, false);
|
||||
});
|
||||
testWidgets('has correct element addition handling', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const example.MyApp());
|
||||
await tester.pumpWidget(const example.IndexedStackApp());
|
||||
|
||||
expect(find.byType(example.PersonTracker), findsNWidgets(3));
|
||||
final Finder textField = find.byType(TextField);
|
||||
@@ -66,7 +66,7 @@ void main() {
|
||||
expect(find.byType(example.PersonTracker), findsNWidgets(5));
|
||||
});
|
||||
testWidgets('has state preservation', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const example.MyApp());
|
||||
await tester.pumpWidget(const example.IndexedStackApp());
|
||||
|
||||
final Finder gesture1 = find.byKey(const Key('gesture1'));
|
||||
final Finder gesture2 = find.byKey(const Key('gesture2'));
|
||||
|
||||
34
examples/api/test/widgets/basic/listener.0_test.dart
Normal file
34
examples/api/test/widgets/basic/listener.0_test.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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.
|
||||
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/listener.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Listener detects press & release, and cursor location', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: example.ListenerExample()),
|
||||
);
|
||||
|
||||
expect(find.text('0 presses\n0 releases'), findsOneWidget);
|
||||
expect(find.text('The cursor is here: (0.00, 0.00)'), findsOneWidget);
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await gesture.addPointer();
|
||||
await gesture.down(tester.getCenter(find.byType(ColoredBox)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('1 presses\n0 releases'), findsOneWidget);
|
||||
expect(find.text('The cursor is here: (400.00, 300.00)'), findsOneWidget);
|
||||
|
||||
await gesture.up();
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('1 presses\n1 releases'), findsOneWidget);
|
||||
expect(find.text('The cursor is here: (400.00, 300.00)'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
39
examples/api/test/widgets/basic/mouse_region.0_test.dart
Normal file
39
examples/api/test/widgets/basic/mouse_region.0_test.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/mouse_region.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('MouseRegion detects mouse entries, exists, and location', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: example.MouseRegionApp()),
|
||||
);
|
||||
|
||||
expect(find.text('0 Entries\n0 Exits'), findsOneWidget);
|
||||
expect(find.text('The cursor is here: (0.00, 0.00)'), findsOneWidget);
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await gesture.addPointer();
|
||||
await gesture.moveTo(tester.getCenter(find.byType(ColoredBox)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('1 Entries\n0 Exits'), findsOneWidget);
|
||||
expect(find.text('The cursor is here: (400.00, 328.00)'), findsOneWidget);
|
||||
|
||||
await gesture.moveTo(
|
||||
tester.getCenter(find.byType(ColoredBox)) + const Offset(50.0, 30.0),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('The cursor is here: (450.00, 358.00)'), findsOneWidget);
|
||||
|
||||
await gesture.moveTo(Offset.zero);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('1 Entries\n1 Exits'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/mouse_region.on_exit.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('MouseRegion detects mouse hover', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: example.MouseRegionApp()),
|
||||
);
|
||||
|
||||
Container container = tester.widget<Container>(find.byType(Container));
|
||||
expect(container.decoration, const BoxDecoration(color: Colors.blue));
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await gesture.addPointer();
|
||||
await gesture.moveTo(tester.getCenter(find.byType(Container)));
|
||||
await tester.pump();
|
||||
|
||||
container = tester.widget<Container>(find.byType(Container));
|
||||
expect(container.decoration, const BoxDecoration(color: Colors.yellow));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/mouse_region.on_exit.1.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('MouseRegion update mouse hover with a delay', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: example.MouseRegionApp()),
|
||||
);
|
||||
|
||||
expect(find.text('Not hovering'), findsOneWidget);
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await gesture.addPointer();
|
||||
await gesture.moveTo(tester.getCenter(find.byType(Container)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Hovering'), findsOneWidget);
|
||||
|
||||
await gesture.moveTo(Offset.zero);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
expect(find.text('Not hovering'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
31
examples/api/test/widgets/basic/offstage.0_test.dart
Normal file
31
examples/api/test/widgets/basic/offstage.0_test.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/offstage.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Can off/on stage Flutter logo widget', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: example.OffstageApp()),
|
||||
);
|
||||
|
||||
// The Flutter logo is off stage and not visible.
|
||||
expect(find.text('Flutter logo is offstage: true'), findsOneWidget);
|
||||
|
||||
// Tap to get the Flutter logo size.
|
||||
await tester.tap(find.text('Get Flutter Logo size'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Flutter Logo size is Size(150.0, 150.0)'), findsOneWidget);
|
||||
|
||||
// Tap to toggle the offstage value.
|
||||
await tester.tap(find.text('Toggle Offstage Value'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The Flutter logo is on stage and visible.
|
||||
expect(find.text('Flutter logo is offstage: false'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
31
examples/api/test/widgets/basic/overflowbox.0_test.dart
Normal file
31
examples/api/test/widgets/basic/overflowbox.0_test.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/overflowbox.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('OverflowBox allows child widget to overflow parent container', (WidgetTester tester) async {
|
||||
const Size containerSize = Size(100, 100);
|
||||
const Size maxSize = Size(200, 200);
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.OverflowBoxApp(),
|
||||
);
|
||||
|
||||
// The parent container has fixed width and height of 100 pixels.
|
||||
expect(tester.getSize(find.byType(Container).first), containerSize);
|
||||
|
||||
final OverflowBox overflowBox = tester.widget(find.byType(OverflowBox));
|
||||
// The OverflowBox imposes its own constraints of maxWidth and maxHeight of
|
||||
// 200 on its child which allows the child to overflow the parent container.
|
||||
expect(overflowBox.maxWidth, maxSize.width);
|
||||
expect(overflowBox.maxHeight, maxSize.height);
|
||||
|
||||
// The child widget overflows the parent container.
|
||||
expect(tester.getSize(find.byType(FlutterLogo)), greaterThan(containerSize));
|
||||
expect(tester.getSize(find.byType(FlutterLogo)), maxSize);
|
||||
});
|
||||
}
|
||||
25
examples/api/test/widgets/basic/physical_shape.0_test.dart
Normal file
25
examples/api/test/widgets/basic/physical_shape.0_test.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/basic/physical_shape.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('PhysicalShape is an ancestor of the text widget', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: example.PhysicalShapeApp()),
|
||||
);
|
||||
|
||||
final PhysicalShape physicalShape = tester.widget<PhysicalShape>(
|
||||
find.ancestor(
|
||||
of:find.text('Hello, World!'),
|
||||
matching: find.byType(PhysicalShape),
|
||||
),
|
||||
);
|
||||
expect(physicalShape.clipper, isNotNull);
|
||||
expect(physicalShape.color, Colors.orange);
|
||||
expect(physicalShape.elevation, 5.0);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user