main
1import 'package:flutter/material.dart';
2
3/// Card to place a complex opened input on.
4class InputCard extends StatelessWidget {
5 /// Create a card to host a complex input.
6 const InputCard({super.key,
7 required this.child,
8 this.title,
9 this.onClosed
10 });
11
12 /// Main content of the card
13 final Widget child;
14
15 /// Description of the card or the state of the card.
16 final Widget? title;
17
18 /// When provided a close icon at the top left corner is shown.
19 final void Function()? onClosed;
20
21 Widget _buildCloseIcon() => Align(
22 alignment: Alignment.topRight,
23 child: IconButton(
24 icon: const Icon(Icons.close),
25 onPressed: onClosed!,
26 ),
27 );
28
29 Widget _buildTitle(BuildContext context) => Align(
30 alignment: Alignment.topLeft,
31 child: Padding(
32 padding: const EdgeInsets.only(
33 top: 8.0,
34 left: 16.0,
35 ),
36 child: DefaultTextStyle(
37 style: Theme.of(context).textTheme.titleMedium ?? const TextStyle(),
38 child: title!,
39 ),
40 ),
41 );
42
43 Widget _buildBody() => Padding( // content
44 padding: EdgeInsets.only(
45 top: (title == null) ? 12.0 : 42.0,
46 bottom: 8.0,
47 left: 8.0,
48 right: 8.0,
49 ),
50 child: Center(
51 child: child,
52 ),
53 );
54
55 @override
56 Widget build(BuildContext context) => Card(
57 color: Theme.of(context).cardColor,
58 margin: const EdgeInsets.only(top: 8.0, bottom: 16.0),
59 child: Stack(
60 children: [
61 _buildBody(),
62 if (title != null)
63 _buildTitle(context),
64 if (onClosed != null)
65 _buildCloseIcon(),
66 ],
67 ),
68 );
69
70}