1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
---|---|
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | import 'package:flutter/material.dart'; |
6 | |
7 | /// Flutter code sample for [OverflowBox]. |
8 | |
9 | void main() => runApp(const OverflowBoxApp()); |
10 | |
11 | class OverflowBoxApp extends StatelessWidget { |
12 | const OverflowBoxApp({super.key}); |
13 | |
14 | @override |
15 | Widget build(BuildContext context) { |
16 | return MaterialApp( |
17 | home: Scaffold( |
18 | appBar: AppBar(title: const Text('OverflowBox Sample')), |
19 | body: const Center(child: OverflowBoxExample()), |
20 | ), |
21 | ); |
22 | } |
23 | } |
24 | |
25 | class OverflowBoxExample extends StatelessWidget { |
26 | const OverflowBoxExample({super.key}); |
27 | |
28 | @override |
29 | Widget build(BuildContext context) { |
30 | return Column( |
31 | mainAxisAlignment: MainAxisAlignment.center, |
32 | children: <Widget>[ |
33 | const Text('Cover Me'), |
34 | // This parent container has fixed width and |
35 | // height of 100 pixels. |
36 | Container( |
37 | width: 100, |
38 | height: 100, |
39 | color: Theme.of(context).colorScheme.secondaryContainer, |
40 | // This OverflowBox imposes its own constraints of maxWidth |
41 | // and maxHeight of 200 pixels on its child which allows the |
42 | // child to overflow the parent container. |
43 | child: const OverflowBox( |
44 | maxWidth: 200, |
45 | maxHeight: 200, |
46 | // Without the OverflowBox, the child widget would be |
47 | // constrained to the size of the parent container |
48 | // and would not overflow the parent container. |
49 | child: FlutterLogo(size: 200), |
50 | ), |
51 | ), |
52 | ], |
53 | ); |
54 | } |
55 | } |
56 |