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() { |
10 | runApp(const IconButtonApp()); |
11 | } |
12 | |
13 | class IconButtonApp extends StatelessWidget { |
14 | const IconButtonApp({super.key}); |
15 | |
16 | @override |
17 | Widget build(BuildContext context) { |
18 | return MaterialApp( |
19 | theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4)), |
20 | title: 'Icon Button Types' , |
21 | home: const Scaffold(body: ButtonTypesExample()), |
22 | ); |
23 | } |
24 | } |
25 | |
26 | class ButtonTypesExample extends StatelessWidget { |
27 | const ButtonTypesExample({super.key}); |
28 | |
29 | @override |
30 | Widget build(BuildContext context) { |
31 | return const Padding( |
32 | padding: EdgeInsets.all(4.0), |
33 | child: Row( |
34 | children: <Widget>[ |
35 | Spacer(), |
36 | ButtonTypesGroup(enabled: true), |
37 | ButtonTypesGroup(enabled: false), |
38 | Spacer(), |
39 | ], |
40 | ), |
41 | ); |
42 | } |
43 | } |
44 | |
45 | class ButtonTypesGroup extends StatelessWidget { |
46 | const ButtonTypesGroup({super.key, required this.enabled}); |
47 | |
48 | final bool enabled; |
49 | |
50 | @override |
51 | Widget build(BuildContext context) { |
52 | final VoidCallback? onPressed = enabled ? () {} : null; |
53 | |
54 | return Padding( |
55 | padding: const EdgeInsets.all(4.0), |
56 | child: Column( |
57 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
58 | children: <Widget>[ |
59 | IconButton(icon: const Icon(Icons.filter_drama), onPressed: onPressed), |
60 | |
61 | // Filled icon button |
62 | IconButton.filled(onPressed: onPressed, icon: const Icon(Icons.filter_drama)), |
63 | |
64 | // Filled tonal icon button |
65 | IconButton.filledTonal(onPressed: onPressed, icon: const Icon(Icons.filter_drama)), |
66 | |
67 | // Outlined icon button |
68 | IconButton.outlined(onPressed: onPressed, icon: const Icon(Icons.filter_drama)), |
69 | ], |
70 | ), |
71 | ); |
72 | } |
73 | } |
74 | |