Unverified Commit 9a4e8979 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Add `OverflowBox` example and update existing examples under `basic.dart` (#121213)

Add `OverflowBox` example and update existing examples under `basic.dart`
parent 5c334d10
......@@ -6,29 +6,26 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const AbsorbPointerApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class AbsorbPointerApp extends StatelessWidget {
const AbsorbPointerApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('AbsorbPointer Sample')),
body: const Center(
child: MyStatelessWidget(),
child: AbsorbPointerExample(),
),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class AbsorbPointerExample extends StatelessWidget {
const AbsorbPointerExample({super.key});
@override
Widget build(BuildContext context) {
......
......@@ -6,27 +6,24 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const AspectRatioApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class AspectRatioApp extends StatelessWidget {
const AspectRatioApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('AspectRatio Sample')),
body: const AspectRatioExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class AspectRatioExample extends StatelessWidget {
const AspectRatioExample({super.key});
@override
Widget build(BuildContext context) {
......
......@@ -6,27 +6,24 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const AspectRatioApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class AspectRatioApp extends StatelessWidget {
const AspectRatioApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('AspectRatio Sample')),
body: const AspectRatioExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class AspectRatioExample extends StatelessWidget {
const AspectRatioExample({super.key});
@override
Widget build(BuildContext context) {
......
......@@ -6,27 +6,24 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const AspectRatioApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class AspectRatioApp extends StatelessWidget {
const AspectRatioApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('AspectRatio Sample')),
body: const AspectRatioExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class AspectRatioExample extends StatelessWidget {
const AspectRatioExample({super.key});
@override
Widget build(BuildContext context) {
......
......@@ -6,52 +6,49 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const ExpandedApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class ExpandedApp extends StatelessWidget {
const ExpandedApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatelessWidget(),
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Expanded Column Sample'),
),
body: const ExpandedExample(),
)
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class ExpandedExample extends StatelessWidget {
const ExpandedExample({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Expanded Column Sample'),
),
body: Center(
child: Column(
children: <Widget>[
Container(
color: Colors.blue,
height: 100,
return Center(
child: Column(
children: <Widget>[
Container(
color: Colors.blue,
height: 100,
width: 100,
),
Expanded(
child: Container(
color: Colors.amber,
width: 100,
),
Expanded(
child: Container(
color: Colors.amber,
width: 100,
),
),
Container(
color: Colors.blue,
height: 100,
width: 100,
),
],
),
),
Container(
color: Colors.blue,
height: 100,
width: 100,
),
],
),
);
}
......
......@@ -6,54 +6,51 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const ExpandedApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class ExpandedApp extends StatelessWidget {
const ExpandedApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatelessWidget(),
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Expanded Row Sample'),
),
body: const ExpandedExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class ExpandedExample extends StatelessWidget {
const ExpandedExample({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Expanded Row Sample'),
),
body: Center(
child: Row(
children: <Widget>[
Expanded(
flex: 2,
child: Container(
color: Colors.amber,
height: 100,
),
),
Container(
color: Colors.blue,
return Center(
child: Row(
children: <Widget>[
Expanded(
flex: 2,
child: Container(
color: Colors.amber,
height: 100,
width: 50,
),
Expanded(
child: Container(
color: Colors.amber,
height: 100,
),
),
Container(
color: Colors.blue,
height: 100,
width: 50,
),
Expanded(
child: Container(
color: Colors.amber,
height: 100,
),
],
),
),
],
),
);
}
......
......@@ -6,29 +6,26 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const FittedBoxApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class FittedBoxApp extends StatelessWidget {
const FittedBoxApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('FittedBox Sample')),
body: const Center(
child: MyStatelessWidget(),
child: FittedBoxExample(),
),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class FittedBoxExample extends StatelessWidget {
const FittedBoxExample({super.key});
@override
Widget build(BuildContext context) {
......@@ -39,7 +36,8 @@ class MyStatelessWidget extends StatelessWidget {
child: FittedBox(
fit: BoxFit.fill,
child: Image.network(
'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'),
'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg',
),
),
);
}
......
......@@ -6,27 +6,24 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const FractionallySizedBoxApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class FractionallySizedBoxApp extends StatelessWidget {
const FractionallySizedBoxApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
appBar: AppBar(title: const Text('FractionallySizedBox Sample')),
body: const FractionallySizedBoxExample(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class FractionallySizedBoxExample extends StatelessWidget {
const FractionallySizedBoxExample({super.key});
@override
Widget build(BuildContext context) {
......
......@@ -6,30 +6,33 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const IgnorePointerApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class IgnorePointerApp extends StatelessWidget {
const IgnorePointerApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatefulWidget(),
return MaterialApp(
home: Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('IgnorePointer Sample'),
),
body: const Center(child: IgnorePointerExample()),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class IgnorePointerExample extends StatefulWidget {
const IgnorePointerExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<IgnorePointerExample> createState() => _IgnorePointerExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _IgnorePointerExampleState extends State<IgnorePointerExample> {
bool ignoring = false;
void setIgnoring(bool newValue) {
setState(() {
......@@ -39,10 +42,21 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: ElevatedButton(
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text('Ignoring: $ignoring'),
IgnorePointer(
ignoring: ignoring,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(24.0),
),
onPressed: () {},
child: const Text('Click me!'),
),
),
FilledButton(
onPressed: () {
setIgnoring(!ignoring);
},
......@@ -50,22 +64,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
ignoring ? 'Set ignoring to false' : 'Set ignoring to true',
),
),
),
body: Center(
child: IgnorePointer(
ignoring: ignoring,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text('Ignoring: $ignoring'),
ElevatedButton(
onPressed: () {},
child: const Text('Click me!'),
),
],
),
),
),
],
);
}
}
......@@ -2,37 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [IndexedStack.].
// Flutter code sample for [IndexedStack].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const IndexedStackApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class IndexedStackApp extends StatelessWidget {
const IndexedStackApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
appBar: AppBar(title: const Text('IndexedStack Sample')),
body: const IndexedStackExample(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class IndexedStackExample extends StatefulWidget {
const IndexedStackExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<IndexedStackExample> createState() => _IndexedStackExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _IndexedStackExampleState extends State<IndexedStackExample> {
List<String> names = <String>['Dash', 'John', 'Mary'];
int index = 0;
final TextEditingController fieldText = TextEditingController();
......
......@@ -6,35 +6,32 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const ListenerApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class ListenerApp extends StatelessWidget {
const ListenerApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('Listener Sample')),
body: const Center(
child: MyStatefulWidget(),
child: ListenerExample(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class ListenerExample extends StatefulWidget {
const ListenerExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<ListenerExample> createState() => _ListenerExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _ListenerExampleState extends State<ListenerExample> {
int _downCounter = 0;
int _upCounter = 0;
double x = 0.0;
......
......@@ -6,35 +6,32 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const MouseRegionApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class MouseRegionApp extends StatelessWidget {
const MouseRegionApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('MouseRegion Sample')),
body: const Center(
child: MyStatefulWidget(),
child: MouseRegionExample(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class MouseRegionExample extends StatefulWidget {
const MouseRegionExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<MouseRegionExample> createState() => _MouseRegionExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _MouseRegionExampleState extends State<MouseRegionExample> {
int _enterCounter = 0;
int _exitCounter = 0;
double x = 0.0;
......
......@@ -6,35 +6,32 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const MouseRegionApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class MouseRegionApp extends StatelessWidget {
const MouseRegionApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('MouseRegion.onExit Sample')),
body: const Center(
child: MyStatefulWidget(),
child: MouseRegionExample(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class MouseRegionExample extends StatefulWidget {
const MouseRegionExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<MouseRegionExample> createState() => _MouseRegionExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _MouseRegionExampleState extends State<MouseRegionExample> {
bool hovered = false;
@override
......
......@@ -6,21 +6,18 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const MouseRegionApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class MouseRegionApp extends StatelessWidget {
const MouseRegionApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('MouseRegion.onExit Sample')),
body: const Center(
child: MyStatefulWidget(),
child: MouseRegionExample(),
),
),
);
......@@ -65,36 +62,36 @@ class _MyTimedButton extends State<MyTimedButton> {
height: 100,
child: MouseRegion(
child: regionIsHidden
? null
: MouseRegion(
onEnter: (_) {
widget.onEnterButton();
setState(() {
hovered = true;
});
startCountdown();
},
onExit: (_) {
setState(() {
hovered = false;
});
widget.onExitButton();
},
child: Container(color: Colors.red),
),
? null
: MouseRegion(
onEnter: (_) {
widget.onEnterButton();
setState(() {
hovered = true;
});
startCountdown();
},
onExit: (_) {
setState(() {
hovered = false;
});
widget.onExitButton();
},
child: Container(color: Colors.red),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class MouseRegionExample extends StatefulWidget {
const MouseRegionExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<MouseRegionExample> createState() => _MouseRegionExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _MouseRegionExampleState extends State<MouseRegionExample> {
Key key = UniqueKey();
bool hovering = false;
......
......@@ -6,35 +6,32 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const OffstageApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class OffstageApp extends StatelessWidget {
const OffstageApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('Offstage Sample')),
body: const Center(
child: MyStatefulWidget(),
child: OffstageExample(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
class OffstageExample extends StatefulWidget {
const OffstageExample({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<OffstageExample> createState() => _OffstageExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _OffstageExampleState extends State<OffstageExample> {
final GlobalKey _key = GlobalKey();
bool _offstage = true;
......
// 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.
// Flutter code sample for [OverflowBox].
import 'package:flutter/material.dart';
void main() => runApp(const OverflowBoxApp());
class OverflowBoxApp extends StatelessWidget {
const OverflowBoxApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('OverflowBox Sample')),
body: const Center(
child: OverflowBoxExample(),
),
),
);
}
}
class OverflowBoxExample extends StatelessWidget {
const OverflowBoxExample({super.key});
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('Cover Me'),
// This parent container has fixed width and
// height of 100 pixels.
Container(
width: 100,
height: 100,
color: Theme.of(context).colorScheme.secondaryContainer,
// This OverflowBox imposes its own constraints of maxWidth
// and maxHeight of 200 pixels on its child which allows the
// child to overflow the parent container.
child: const OverflowBox(
maxWidth: 200,
maxHeight: 200,
// Without the OverflowBox, the child widget would be
// constrained to the size of the parent container
// and would not overflow the parent container.
child: FlutterLogo(size: 200),
),
),
],
);
}
}
......@@ -6,51 +6,46 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const PhysicalShapeApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
class PhysicalShapeApp extends StatelessWidget {
const PhysicalShapeApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatelessWidget(),
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('PhysicalShape Sample'),
),
body: const Center(child: PhysicalShapeExample()),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
class PhysicalShapeExample extends StatelessWidget {
const PhysicalShapeExample({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('PhysicalShape Sample'),
return PhysicalShape(
elevation: 5.0,
clipper: ShapeBorderClipper(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
body: Center(
child: PhysicalShape(
elevation: 5.0,
clipper: ShapeBorderClipper(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
color: Colors.orange,
child: const SizedBox(
height: 200.0,
width: 200.0,
child: Center(
child: Text(
'Hello, World!',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
color: Colors.orange,
child: const SizedBox(
height: 200.0,
width: 200.0,
child: Center(
child: Text(
'Hello, World!',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
),
......
// 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);
});
}
// 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);
});
}
// 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));
});
}
// 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));
});
}
// 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));
});
}
// 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));
});
}
// 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);
});
}
// 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));
});
}
// 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);
});
}
// 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'));
......
// 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);
});
}
// 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);
});
}
// 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));
});
}
// 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);
});
}
// 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);
});
}
// 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);
});
}
// 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);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment