diff --git a/examples/api/lib/widgets/basic/absorb_pointer.0.dart b/examples/api/lib/widgets/basic/absorb_pointer.0.dart index e9e02cab0c61..421bb57d6ce8 100644 --- a/examples/api/lib/widgets/basic/absorb_pointer.0.dart +++ b/examples/api/lib/widgets/basic/absorb_pointer.0.dart @@ -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) { diff --git a/examples/api/lib/widgets/basic/aspect_ratio.0.dart b/examples/api/lib/widgets/basic/aspect_ratio.0.dart index e8e0834ba96d..bde5a3b09e31 100644 --- a/examples/api/lib/widgets/basic/aspect_ratio.0.dart +++ b/examples/api/lib/widgets/basic/aspect_ratio.0.dart @@ -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) { diff --git a/examples/api/lib/widgets/basic/aspect_ratio.1.dart b/examples/api/lib/widgets/basic/aspect_ratio.1.dart index 47a01fdc67cd..500032e68aa9 100644 --- a/examples/api/lib/widgets/basic/aspect_ratio.1.dart +++ b/examples/api/lib/widgets/basic/aspect_ratio.1.dart @@ -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) { diff --git a/examples/api/lib/widgets/basic/aspect_ratio.2.dart b/examples/api/lib/widgets/basic/aspect_ratio.2.dart index 40132e073c19..7d65983e9086 100644 --- a/examples/api/lib/widgets/basic/aspect_ratio.2.dart +++ b/examples/api/lib/widgets/basic/aspect_ratio.2.dart @@ -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) { diff --git a/examples/api/lib/widgets/basic/expanded.0.dart b/examples/api/lib/widgets/basic/expanded.0.dart index 0cedcb9dc0a9..df3c4dc75ac4 100644 --- a/examples/api/lib/widgets/basic/expanded.0.dart +++ b/examples/api/lib/widgets/basic/expanded.0.dart @@ -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: [ - Container( - color: Colors.blue, - height: 100, + return Center( + child: Column( + children: [ + 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, + ), + ], ), ); } diff --git a/examples/api/lib/widgets/basic/expanded.1.dart b/examples/api/lib/widgets/basic/expanded.1.dart index 7eb5c73cb7d0..f0cf2d6236bd 100644 --- a/examples/api/lib/widgets/basic/expanded.1.dart +++ b/examples/api/lib/widgets/basic/expanded.1.dart @@ -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: [ - Expanded( - flex: 2, - child: Container( - color: Colors.amber, - height: 100, - ), - ), - Container( - color: Colors.blue, + return Center( + child: Row( + children: [ + 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, ), - ], - ), + ), + ], ), ); } diff --git a/examples/api/lib/widgets/basic/fitted_box.0.dart b/examples/api/lib/widgets/basic/fitted_box.0.dart index cea3c3d41aaf..062602b0bd99 100644 --- a/examples/api/lib/widgets/basic/fitted_box.0.dart +++ b/examples/api/lib/widgets/basic/fitted_box.0.dart @@ -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', + ), ), ); } diff --git a/examples/api/lib/widgets/basic/fractionally_sized_box.0.dart b/examples/api/lib/widgets/basic/fractionally_sized_box.0.dart index 7be229474868..95c5d8501139 100644 --- a/examples/api/lib/widgets/basic/fractionally_sized_box.0.dart +++ b/examples/api/lib/widgets/basic/fractionally_sized_box.0.dart @@ -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) { diff --git a/examples/api/lib/widgets/basic/ignore_pointer.0.dart b/examples/api/lib/widgets/basic/ignore_pointer.0.dart index 935395f7f4fb..cd6452ce2735 100644 --- a/examples/api/lib/widgets/basic/ignore_pointer.0.dart +++ b/examples/api/lib/widgets/basic/ignore_pointer.0.dart @@ -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 createState() => _MyStatefulWidgetState(); + State createState() => _IgnorePointerExampleState(); } -class _MyStatefulWidgetState extends State { +class _IgnorePointerExampleState extends State { bool ignoring = false; void setIgnoring(bool newValue) { setState(() { @@ -39,10 +42,21 @@ class _MyStatefulWidgetState extends State { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - centerTitle: true, - title: ElevatedButton( + return Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + 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 { ignoring ? 'Set ignoring to false' : 'Set ignoring to true', ), ), - ), - body: Center( - child: IgnorePointer( - ignoring: ignoring, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Text('Ignoring: $ignoring'), - ElevatedButton( - onPressed: () {}, - child: const Text('Click me!'), - ), - ], - ), - ), - ), + ], ); } } diff --git a/examples/api/lib/widgets/basic/indexed_stack.0.dart b/examples/api/lib/widgets/basic/indexed_stack.0.dart index 08d9aa3b5fa8..bd5ec386e8b0 100644 --- a/examples/api/lib/widgets/basic/indexed_stack.0.dart +++ b/examples/api/lib/widgets/basic/indexed_stack.0.dart @@ -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 createState() => _MyStatefulWidgetState(); + State createState() => _IndexedStackExampleState(); } -class _MyStatefulWidgetState extends State { +class _IndexedStackExampleState extends State { List names = ['Dash', 'John', 'Mary']; int index = 0; final TextEditingController fieldText = TextEditingController(); diff --git a/examples/api/lib/widgets/basic/listener.0.dart b/examples/api/lib/widgets/basic/listener.0.dart index 4e9b00adf6ab..32a454afc981 100644 --- a/examples/api/lib/widgets/basic/listener.0.dart +++ b/examples/api/lib/widgets/basic/listener.0.dart @@ -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 createState() => _MyStatefulWidgetState(); + State createState() => _ListenerExampleState(); } -class _MyStatefulWidgetState extends State { +class _ListenerExampleState extends State { int _downCounter = 0; int _upCounter = 0; double x = 0.0; diff --git a/examples/api/lib/widgets/basic/mouse_region.0.dart b/examples/api/lib/widgets/basic/mouse_region.0.dart index 65fce481cdd6..1164ae33f983 100644 --- a/examples/api/lib/widgets/basic/mouse_region.0.dart +++ b/examples/api/lib/widgets/basic/mouse_region.0.dart @@ -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 createState() => _MyStatefulWidgetState(); + State createState() => _MouseRegionExampleState(); } -class _MyStatefulWidgetState extends State { +class _MouseRegionExampleState extends State { int _enterCounter = 0; int _exitCounter = 0; double x = 0.0; diff --git a/examples/api/lib/widgets/basic/mouse_region.on_exit.0.dart b/examples/api/lib/widgets/basic/mouse_region.on_exit.0.dart index 1d07f7b86c97..bbfe0ac8ceeb 100644 --- a/examples/api/lib/widgets/basic/mouse_region.on_exit.0.dart +++ b/examples/api/lib/widgets/basic/mouse_region.on_exit.0.dart @@ -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 createState() => _MyStatefulWidgetState(); + State createState() => _MouseRegionExampleState(); } -class _MyStatefulWidgetState extends State { +class _MouseRegionExampleState extends State { bool hovered = false; @override diff --git a/examples/api/lib/widgets/basic/mouse_region.on_exit.1.dart b/examples/api/lib/widgets/basic/mouse_region.on_exit.1.dart index b3cde3292ca2..1a3773b105b9 100644 --- a/examples/api/lib/widgets/basic/mouse_region.on_exit.1.dart +++ b/examples/api/lib/widgets/basic/mouse_region.on_exit.1.dart @@ -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 { 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 createState() => _MyStatefulWidgetState(); + State createState() => _MouseRegionExampleState(); } -class _MyStatefulWidgetState extends State { +class _MouseRegionExampleState extends State { Key key = UniqueKey(); bool hovering = false; diff --git a/examples/api/lib/widgets/basic/offstage.0.dart b/examples/api/lib/widgets/basic/offstage.0.dart index 6addd66efef1..dc843ca2a812 100644 --- a/examples/api/lib/widgets/basic/offstage.0.dart +++ b/examples/api/lib/widgets/basic/offstage.0.dart @@ -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 createState() => _MyStatefulWidgetState(); + State createState() => _OffstageExampleState(); } -class _MyStatefulWidgetState extends State { +class _OffstageExampleState extends State { final GlobalKey _key = GlobalKey(); bool _offstage = true; diff --git a/examples/api/lib/widgets/basic/overflowbox.0.dart b/examples/api/lib/widgets/basic/overflowbox.0.dart new file mode 100644 index 000000000000..626ebabd157a --- /dev/null +++ b/examples/api/lib/widgets/basic/overflowbox.0.dart @@ -0,0 +1,57 @@ +// 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: [ + 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), + ), + ), + ], + ); + } +} diff --git a/examples/api/lib/widgets/basic/physical_shape.0.dart b/examples/api/lib/widgets/basic/physical_shape.0.dart index 88978e63b465..aaf0bd41d6f2 100644 --- a/examples/api/lib/widgets/basic/physical_shape.0.dart +++ b/examples/api/lib/widgets/basic/physical_shape.0.dart @@ -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, ), ), ), diff --git a/examples/api/test/widgets/basic/absorb_pointer.0_test.dart b/examples/api/test/widgets/basic/absorb_pointer.0_test.dart new file mode 100644 index 000000000000..eeaaf4e34e08 --- /dev/null +++ b/examples/api/test/widgets/basic/absorb_pointer.0_test.dart @@ -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); + }); +} diff --git a/examples/api/test/widgets/basic/aspect_ratio.0_test.dart b/examples/api/test/widgets/basic/aspect_ratio.0_test.dart new file mode 100644 index 000000000000..b73845212546 --- /dev/null +++ b/examples/api/test/widgets/basic/aspect_ratio.0_test.dart @@ -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); + }); +} diff --git a/examples/api/test/widgets/basic/aspect_ratio.1_test.dart b/examples/api/test/widgets/basic/aspect_ratio.1_test.dart new file mode 100644 index 000000000000..e19d344938ee --- /dev/null +++ b/examples/api/test/widgets/basic/aspect_ratio.1_test.dart @@ -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)); + }); +} diff --git a/examples/api/test/widgets/basic/aspect_ratio.2_test.dart b/examples/api/test/widgets/basic/aspect_ratio.2_test.dart new file mode 100644 index 000000000000..cfd80da07b6c --- /dev/null +++ b/examples/api/test/widgets/basic/aspect_ratio.2_test.dart @@ -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)); + }); +} diff --git a/examples/api/test/widgets/basic/expanded.0_test.dart b/examples/api/test/widgets/basic/expanded.0_test.dart new file mode 100644 index 000000000000..66827372de0b --- /dev/null +++ b/examples/api/test/widgets/basic/expanded.0_test.dart @@ -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)); + }); +} diff --git a/examples/api/test/widgets/basic/expanded.1_test.dart b/examples/api/test/widgets/basic/expanded.1_test.dart new file mode 100644 index 000000000000..6d1a5d7277fd --- /dev/null +++ b/examples/api/test/widgets/basic/expanded.1_test.dart @@ -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)); + }); +} diff --git a/examples/api/test/widgets/basic/fitted_box.0_test.dart b/examples/api/test/widgets/basic/fitted_box.0_test.dart new file mode 100644 index 000000000000..adedfb222e10 --- /dev/null +++ b/examples/api/test/widgets/basic/fitted_box.0_test.dart @@ -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); + }); +} diff --git a/examples/api/test/widgets/basic/flow.0_test.dart b/examples/api/test/widgets/basic/flow.0_test.dart new file mode 100644 index 000000000000..ef45b416c8e6 --- /dev/null +++ b/examples/api/test/widgets/basic/flow.0_test.dart @@ -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)); + }); +} diff --git a/examples/api/test/widgets/basic/fractionally_sized_box.0_test.dart b/examples/api/test/widgets/basic/fractionally_sized_box.0_test.dart new file mode 100644 index 000000000000..65e3d6742653 --- /dev/null +++ b/examples/api/test/widgets/basic/fractionally_sized_box.0_test.dart @@ -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); + }); +} diff --git a/examples/api/test/widgets/basic/ignore_pointer.0_test.dart b/examples/api/test/widgets/basic/ignore_pointer.0_test.dart new file mode 100644 index 000000000000..fa7583ec6ca8 --- /dev/null +++ b/examples/api/test/widgets/basic/ignore_pointer.0_test.dart @@ -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); + }); +} diff --git a/examples/api/test/widgets/basic/indexed_stack.0_test.dart b/examples/api/test/widgets/basic/indexed_stack.0_test.dart index 8a2ec34303be..5f43808459f2 100644 --- a/examples/api/test/widgets/basic/indexed_stack.0_test.dart +++ b/examples/api/test/widgets/basic/indexed_stack.0_test.dart @@ -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')); diff --git a/examples/api/test/widgets/basic/listener.0_test.dart b/examples/api/test/widgets/basic/listener.0_test.dart new file mode 100644 index 000000000000..40fb5d6b5cc8 --- /dev/null +++ b/examples/api/test/widgets/basic/listener.0_test.dart @@ -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); + }); +} diff --git a/examples/api/test/widgets/basic/mouse_region.0_test.dart b/examples/api/test/widgets/basic/mouse_region.0_test.dart new file mode 100644 index 000000000000..028210d862ca --- /dev/null +++ b/examples/api/test/widgets/basic/mouse_region.0_test.dart @@ -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); + }); +} diff --git a/examples/api/test/widgets/basic/mouse_region.on_exit.0_test.dart b/examples/api/test/widgets/basic/mouse_region.on_exit.0_test.dart new file mode 100644 index 000000000000..1f8ac60f0fa4 --- /dev/null +++ b/examples/api/test/widgets/basic/mouse_region.on_exit.0_test.dart @@ -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(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(find.byType(Container)); + expect(container.decoration, const BoxDecoration(color: Colors.yellow)); + }); +} diff --git a/examples/api/test/widgets/basic/mouse_region.on_exit.1_test.dart b/examples/api/test/widgets/basic/mouse_region.on_exit.1_test.dart new file mode 100644 index 000000000000..6025575e32a7 --- /dev/null +++ b/examples/api/test/widgets/basic/mouse_region.on_exit.1_test.dart @@ -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); + }); +} diff --git a/examples/api/test/widgets/basic/offstage.0_test.dart b/examples/api/test/widgets/basic/offstage.0_test.dart new file mode 100644 index 000000000000..e459dee7e760 --- /dev/null +++ b/examples/api/test/widgets/basic/offstage.0_test.dart @@ -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); + }); +} diff --git a/examples/api/test/widgets/basic/overflowbox.0_test.dart b/examples/api/test/widgets/basic/overflowbox.0_test.dart new file mode 100644 index 000000000000..a3b86f8fb862 --- /dev/null +++ b/examples/api/test/widgets/basic/overflowbox.0_test.dart @@ -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); + }); +} diff --git a/examples/api/test/widgets/basic/physical_shape.0_test.dart b/examples/api/test/widgets/basic/physical_shape.0_test.dart new file mode 100644 index 000000000000..db6e9aea5379 --- /dev/null +++ b/examples/api/test/widgets/basic/physical_shape.0_test.dart @@ -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( + 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); + }); +}