11import 'package:fluent_ui/fluent_ui.dart' ;
22
3+ typedef InfoBadgeSeverity = InfoBarSeverity ;
4+
35/// Badging is a non-intrusive and intuitive way to display notifications or
46/// bring focus to an area within an app - whether that be for notifications,
57/// indicating new content, or showing an alert. An `InfoBadge` is a small
@@ -20,56 +22,106 @@ import 'package:fluent_ui/fluent_ui.dart';
2022/// * [NavigationView] , which provides top-level navigation for your app
2123class InfoBadge extends StatelessWidget {
2224 /// Creates an info badge.
23- const InfoBadge ({super .key, this .source, this .color, this .foregroundColor});
25+ const InfoBadge ({
26+ super .key,
27+ this .source,
28+ this .color,
29+ this .foregroundColor,
30+ this .severity = InfoBarSeverity .info,
31+ });
32+
33+ /// Creates an attention info badge.
34+ ///
35+ /// Uses the default accent color to draw attention to important content.
36+ const InfoBadge .attention ({super .key, this .source, this .foregroundColor})
37+ : severity = InfoBarSeverity .warning,
38+ color = null ;
39+
40+ /// Creates an informational info badge.
41+ ///
42+ /// Uses the default accent color to indicate informational content.
43+ const InfoBadge .informational ({super .key, this .source, this .foregroundColor})
44+ : severity = InfoBarSeverity .info,
45+ color = null ;
46+
47+ /// Creates a success info badge.
48+ ///
49+ /// Uses the success color to indicate successful completion or positive status.
50+ const InfoBadge .success ({super .key, this .source, this .foregroundColor})
51+ : severity = InfoBarSeverity .success,
52+ color = null ;
53+
54+ /// Creates a critical info badge.
55+ ///
56+ /// Uses the error color to indicate critical issues or errors.
57+ const InfoBadge .critical ({super .key, this .source, this .foregroundColor})
58+ : severity = InfoBarSeverity .error,
59+ color = null ;
2460
2561 /// The source of the badge.
2662 ///
2763 /// Usually a [Text] or an [Icon]
2864 final Widget ? source;
2965
30- /// The background color of the badge. If null, the current
31- /// [FluentTheme.accentColor] is used
32- ///
33- /// Some other used colors are:
34- ///
35- /// * [Colors.errorPrimaryColor]
36- /// * [Colors.successPrimaryColor]
37- /// * [Colors.warningPrimaryColor]
66+ /// The background color of the badge. If not provided, the color will
67+ /// be decided based on the [severity] .
3868 final Color ? color;
3969
4070 /// The foreground color.
41- ///
42- /// Applied to [Text] s and [Icon] s
4371 final Color ? foregroundColor;
4472
73+ /// The severity of the badge.
74+ final InfoBadgeSeverity severity;
75+
4576 @override
4677 Widget build (BuildContext context) {
4778 assert (debugCheckHasFluentTheme (context));
4879
4980 final theme = FluentTheme .of (context);
5081 final color =
51- this .color ?? theme.accentColor.defaultBrushFor (theme.brightness);
82+ this .color ??
83+ switch (severity) {
84+ InfoBarSeverity .info => theme.accentColor.defaultBrushFor (
85+ theme.brightness,
86+ ),
87+ InfoBarSeverity .warning =>
88+ theme.resources.systemFillColorSolidAttentionBackground,
89+ InfoBarSeverity .success => theme.resources.systemFillColorSuccess,
90+ InfoBarSeverity .error => theme.resources.systemFillColorCritical,
91+ };
5292 final foregroundColor =
5393 this .foregroundColor ?? theme.resources.textOnAccentFillColorPrimary;
5494
95+ if (source == null ) {
96+ return Container (
97+ width: 6 ,
98+ height: 6 ,
99+ decoration: BoxDecoration (
100+ color: color,
101+ borderRadius: BorderRadius .circular (100 ),
102+ ),
103+ );
104+ }
105+
55106 return Container (
56- constraints: source == null
57- ? const BoxConstraints (maxWidth: 10 , maxHeight: 10 )
58- : const BoxConstraints (minWidth: 16 , minHeight: 16 , maxHeight: 16 ),
107+ constraints: const BoxConstraints (
108+ minWidth: 16 ,
109+ minHeight: 16 ,
110+ maxHeight: 16 ,
111+ ),
112+ padding: const EdgeInsetsDirectional .only (start: 4 , end: 4 , bottom: 1 ),
59113 decoration: BoxDecoration (
60114 color: color,
61115 borderRadius: BorderRadius .circular (100 ),
62116 ),
63- child: source == null
64- ? null
65- : DefaultTextStyle .merge (
66- textAlign: TextAlign .center,
67- style: TextStyle (color: foregroundColor, fontSize: 11 ),
68- child: IconTheme .merge (
69- data: IconThemeData (color: foregroundColor, size: 8 ),
70- child: source! ,
71- ),
72- ),
117+ child: DefaultTextStyle .merge (
118+ textAlign: TextAlign .center,
119+ style: TextStyle (color: foregroundColor, fontSize: 11 ),
120+ child: IconTheme .merge (
121+ data: IconThemeData (color: foregroundColor, size: 12 ),
122+ child: source! ,
123+ ),
124+ ),
73125 );
74126 }
75127}
0 commit comments