forked from mirrors/material_3_expressive
Refactor badge handling across components to use m3e colors, remove unused _SmallDot widget, and clean up redundant code.
This commit is contained in:
parent
4940d3ce69
commit
05c489991a
6 changed files with 21 additions and 32 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:m3e_design/m3e_design.dart';
|
||||
|
||||
import 'enums.dart';
|
||||
|
||||
|
|
@ -44,6 +45,7 @@ class IconButtonM3E extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final m3e = context.m3e;
|
||||
|
||||
final Size visual = size.visual(width);
|
||||
final Size target = size.target(width);
|
||||
|
|
@ -133,19 +135,27 @@ class IconButtonM3E extends StatelessWidget {
|
|||
badge = null;
|
||||
} else if (v is num) {
|
||||
final int c = v.round().clamp(0, 999999);
|
||||
badge = Badge.count(
|
||||
count: c,
|
||||
backgroundColor: scheme.error,
|
||||
textColor: scheme.onError,
|
||||
);
|
||||
if (c == 0) {
|
||||
badge = Badge(
|
||||
smallSize: 8,
|
||||
backgroundColor: m3e.colors.primary,
|
||||
textColor: m3e.colors.onPrimary,
|
||||
);
|
||||
} else {
|
||||
badge = Badge.count(
|
||||
count: c,
|
||||
backgroundColor: m3e.colors.primary,
|
||||
textColor: m3e.colors.onPrimary,
|
||||
);
|
||||
}
|
||||
} else if (v is String) {
|
||||
if (v.isEmpty) {
|
||||
badge = null;
|
||||
} else {
|
||||
badge = Badge(
|
||||
label: Text(v),
|
||||
backgroundColor: scheme.error,
|
||||
textColor: scheme.onError,
|
||||
backgroundColor: m3e.colors.primary,
|
||||
textColor: m3e.colors.onPrimary,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -13,9 +13,10 @@ dependencies:
|
|||
sdk: flutter
|
||||
|
||||
dev_dependencies:
|
||||
flutter_lints: ^4.0.0
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^4.0.0
|
||||
|
||||
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
|
|
|
|||
|
|
@ -135,7 +135,6 @@ class _NavigationRailM3EState extends State<NavigationRailM3E>
|
|||
|
||||
void _insertOverlay() {
|
||||
final overlay = Overlay.of(context, rootOverlay: true);
|
||||
if (overlay == null) return;
|
||||
_modalEntry = OverlayEntry(builder: (ctx) => _buildModalOverlay(ctx));
|
||||
overlay.insert(_modalEntry!);
|
||||
}
|
||||
|
|
@ -147,7 +146,6 @@ class _NavigationRailM3EState extends State<NavigationRailM3E>
|
|||
|
||||
void _insertCollapsedPeekOverlay() {
|
||||
final overlay = Overlay.of(context, rootOverlay: true);
|
||||
if (overlay == null) return;
|
||||
_collapsedPeekEntry =
|
||||
OverlayEntry(builder: (ctx) => _buildCollapsedPeekOverlay(ctx));
|
||||
overlay.insert(_collapsedPeekEntry!);
|
||||
|
|
|
|||
|
|
@ -65,19 +65,3 @@ class RailBadgeM3E extends StatelessWidget {
|
|||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
class _SmallDot extends StatelessWidget {
|
||||
const _SmallDot({required this.color});
|
||||
final Color color;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,11 +36,9 @@ class NavigationRailTokensAdapter {
|
|||
}
|
||||
|
||||
Color get badgeBackground =>
|
||||
_maybe(() => context.m3e.colors.error) ?? _cs.error;
|
||||
_maybe(() => context.m3e.colors.primary) ?? _cs.primary;
|
||||
Color get badgeLargeLabel =>
|
||||
_maybe(() => context.m3e.colors.onError) ?? _cs.onError;
|
||||
Color get badgeSmallDot =>
|
||||
_maybe(() => context.m3e.colors.error) ?? _cs.error;
|
||||
_maybe(() => context.m3e.colors.onPrimary) ?? _cs.onPrimary;
|
||||
|
||||
ShapeBorder get indicatorShapeFull {
|
||||
// Full corner per M3E: use the most rounded token, fallback to StadiumBorder.
|
||||
|
|
|
|||
|
|
@ -368,8 +368,6 @@ class _SplitButtonM3EState<T> extends State<SplitButtonM3E<T>> {
|
|||
setState(() => _menuOpen = true);
|
||||
|
||||
// Ensure menu item text/icon colors match the button's foreground (onCont)
|
||||
final theme = Theme.of(context);
|
||||
final m3e = context.m3e;
|
||||
final (
|
||||
Color _cont,
|
||||
Color onCont,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue