main
 1import 'package:flutter/material.dart';
 2
 3/// A floating banner to display information and perform actions.
 4///
 5/// This custom banner is needed to allow for rounded app bar corners, which
 6/// would conflict with the material design banner.
 7///
 8/// Example usage:
 9/// ```dart
10/// CustomBanner(
11///   content: Text(localizations.warnNeedsRestartForUsingApp),
12///   action: TextButton(
13///     onPressed: () => Restart.restartApp(),
14///     child: Text(localizations.restartNow),
15///   )
16/// )
17/// ```
18class CustomBanner extends MaterialBanner {
19  /// Create a banner that displays information and an action.
20  CustomBanner({
21    super.key,
22    required super.content,
23    this.action,
24  }) : super(
25    actions: [const SizedBox.shrink()],
26  );
27
28  /// Primary action of the banner.
29  ///
30  /// Usually a [TextButton].
31  ///
32  /// When this is larger than the screen width, overflow occurs.
33  final Widget? action;
34
35
36  @override
37  MaterialBanner withAnimation(Animation<double> newAnimation, {Key? fallbackKey})
38    => CustomBanner(content: content, action: action, key: key ?? fallbackKey,);
39  // TODO: animate
40
41  @override
42  State<CustomBanner> createState() => _CustomBannerState();
43}
44
45class _CustomBannerState extends State<CustomBanner> {
46  @override
47  Widget build(BuildContext context) => Container(
48    margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 4),
49    padding: const EdgeInsets.all(15),
50    decoration: BoxDecoration(
51      borderRadius: BorderRadius.circular(20),
52      color: Theme.of(context).cardColor,
53    ),
54    child: Row(
55      children: [
56        Expanded(child: widget.content),
57        if (widget.action != null)
58          widget.action!,
59      ],
60    ),
61  );
62}