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 [IconButton]. |
8 | |
9 | void main() => runApp(const IconButtonExampleApp()); |
10 | |
11 | class IconButtonExampleApp extends StatelessWidget { |
12 | const IconButtonExampleApp({super.key}); |
13 | |
14 | @override |
15 | Widget build(BuildContext context) { |
16 | return MaterialApp( |
17 | home: Scaffold( |
18 | appBar: AppBar(title: const Text('IconButton Sample' )), |
19 | body: const Center(child: IconButtonExample()), |
20 | ), |
21 | ); |
22 | } |
23 | } |
24 | |
25 | double _volume = 0.0; |
26 | |
27 | class IconButtonExample extends StatefulWidget { |
28 | const IconButtonExample({super.key}); |
29 | |
30 | @override |
31 | State<IconButtonExample> createState() => _IconButtonExampleState(); |
32 | } |
33 | |
34 | class _IconButtonExampleState extends State<IconButtonExample> { |
35 | @override |
36 | Widget build(BuildContext context) { |
37 | return Column( |
38 | mainAxisSize: MainAxisSize.min, |
39 | children: <Widget>[ |
40 | IconButton( |
41 | icon: const Icon(Icons.volume_up), |
42 | tooltip: 'Increase volume by 10' , |
43 | onPressed: () { |
44 | setState(() { |
45 | _volume += 10; |
46 | }); |
47 | }, |
48 | ), |
49 | Text('Volume : $_volume' ), |
50 | ], |
51 | ); |
52 | } |
53 | } |
54 | |