mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-11 14:27:48 +01:00
Glyph + spoken label replaces every app-written string the guard found: empty states, tile meta, sheet dates/fields, date presets, template/section headings, status footer, snackbars, GitHub and cloud-image results, upload/download badges, Material tooltips. Guard tests (text_free_*_test) walk the painted tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.0 KiB
Dart
59 lines
2.0 KiB
Dart
/// Transient feedback as a glyph, not a sentence (kuhy's textgate rule).
|
|
///
|
|
/// The design system's `showToast`/`showError` paint a message; this paints
|
|
/// an icon (plus an optional number) and keeps the old sentence as the
|
|
/// spoken label only. Colour is the second channel: errors use the danger
|
|
/// hue and stay up longer, as `showError` does.
|
|
library;
|
|
|
|
import 'package:design_system/design_system.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
const Duration _toastDuration = Duration(seconds: 3);
|
|
const Duration _errorDuration = Duration(seconds: 5);
|
|
|
|
/// Shows [icon] (and [count], if given) in a snack bar; [spoken] is what a
|
|
/// screen reader says. Returns quietly when no `ScaffoldMessenger` is above
|
|
/// [context] (an async callback outliving its screen).
|
|
void showCue(
|
|
BuildContext context,
|
|
IconData icon,
|
|
String spoken, {
|
|
bool error = false,
|
|
int? count,
|
|
}) {
|
|
final messenger = ScaffoldMessenger.maybeOf(context);
|
|
if (messenger == null) return;
|
|
final colors = context.statusColors;
|
|
final fg = error ? colors.onStatus : null;
|
|
// Replace rather than queue: a queued cue describes an action the user
|
|
// has already moved on from.
|
|
messenger
|
|
..clearSnackBars()
|
|
..showSnackBar(
|
|
SnackBar(
|
|
content: Semantics(
|
|
label: spoken,
|
|
excludeSemantics: true,
|
|
// Its own node: otherwise the label merges into the snack bar's.
|
|
container: true,
|
|
child: Row(
|
|
children: [
|
|
Icon(icon, color: fg),
|
|
if (count != null) ...[
|
|
const SizedBox(width: AppSpacing.sm),
|
|
Text('$count', style: TextStyle(color: fg)),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
backgroundColor: error ? colors.danger : null,
|
|
duration: error ? _errorDuration : _toastDuration,
|
|
behavior: SnackBarBehavior.floating,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(AppRadius.sm),
|
|
),
|
|
),
|
|
);
|
|
}
|