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+
15import 'package:flutter/material.dart' ;
26
37void main () {
4- runApp (const MyApp ());
8+ runApp (const ResizeApp ());
59}
610
7- /// The main application widget for the Fruit Catalog.
8- class MyApp extends StatefulWidget {
9- /// Creates the [MyApp] .
10- const MyApp ({super .key});
11+ class ResizeApp extends StatefulWidget {
12+ /// Creates the [ResizeApp] .
13+ const ResizeApp ({super .key});
1114
1215 @override
13- State <MyApp > createState () => _MyAppState ();
16+ State <ResizeApp > createState () => _ResizeAppState ();
1417}
1518
16- class _MyAppState extends State <MyApp > {
17- int _counter = 1 ;
18- void _incrementCounter () {
19+ class _ResizeAppState extends State <ResizeApp > {
20+ int _listSize = 1 ;
21+ void _addToList () {
1922 setState (() {
20- if (_counter > 40 ) {
21- _counter = 1 ;
22- }
23- _counter++ ;
23+ _listSize++ ;
2424 });
2525 }
2626
2727 @override
2828 Widget build (BuildContext context) {
29-
30- return Center (
31- heightFactor: 1 ,
32- child: Directionality (
33- textDirection: TextDirection .ltr,
34- child: Column (
35- mainAxisAlignment: MainAxisAlignment .end,
36- children: [
37- for (int i = 0 ; i < _counter; i++ )
38- Text (
39- "Hello from Flutter $i " ,
40- style: TextStyle (color: Colors .pink),
41- ),
42- Padding (
43- padding: const EdgeInsets .fromLTRB (8.0 , 50 , 8.0 , 8.0 ),
44- child: ElevatedButton (
45- onPressed: _incrementCounter,
46- child: Text ("Add to list" ),
47- ),
48- ),
49-
50- ],
29+ return GestureDetector (
30+ onTap: _addToList, // The tap anywhere logic
31+ child: Center (
32+ heightFactor: 1 ,
33+ child: Directionality (
34+ textDirection: TextDirection .ltr,
35+ child: Column (
36+ mainAxisSize: MainAxisSize .min,
37+ children: < Widget > [
38+ for (int i = 0 ; i < _listSize; i++ )
39+ Container (color: HSVColor .fromAHSV (1 , (10.0 * i), 1 , 1 ).toColor (), height: 50 , width: 100 ),
40+ ],
41+ ),
5142 ),
5243 ),
5344 );
5445 }
55- }
46+ }
0 commit comments