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

Add `OverflowBox` example and update existing examples under `basic.dart`
This commit is contained in:
Taha Tesser
2023-02-27 20:52:00 +02:00
committed by GitHub
parent 5c334d10df
commit 9a4e897965
35 changed files with 828 additions and 304 deletions

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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(),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({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,
width: 100,
),
Expanded(
child: Container(
color: Colors.amber,
width: 100,
),
),
Container(
color: Colors.blue,
height: 100,
width: 100,
),
],
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Expanded Column Sample'),
),
body: const ExpandedExample(),
)
);
}
}
class ExpandedExample extends StatelessWidget {
const ExpandedExample({super.key});
@override
Widget build(BuildContext context) {
return Center(
child: Column(
children: <Widget>[
Container(
color: Colors.blue,
height: 100,
width: 100,
),
Expanded(
child: Container(
color: Colors.amber,
width: 100,
),
),
Container(
color: Colors.blue,
height: 100,
width: 100,
),
],
),
);
}

View File

@@ -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(),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({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,
height: 100,
width: 50,
),
Expanded(
child: Container(
color: Colors.amber,
height: 100,
),
),
],
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Expanded Row Sample'),
),
body: const ExpandedExample(),
),
);
}
}
class ExpandedExample extends StatelessWidget {
const ExpandedExample({super.key});
@override
Widget build(BuildContext context) {
return Center(
child: Row(
children: <Widget>[
Expanded(
flex: 2,
child: Container(
color: Colors.amber,
height: 100,
),
),
Container(
color: Colors.blue,
height: 100,
width: 50,
),
Expanded(
child: Container(
color: Colors.amber,
height: 100,
),
),
],
),
);
}

View File

@@ -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',
),
),
);
}

View File

@@ -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) {

View File

@@ -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!'),
),
],
),
),
),
],
);
}
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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: <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),
),
),
],
);
}
}

View File

@@ -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,
),
),
),