e43cc867f9
Shared AppSheetHeader (title + Done) for the Runs filter/sort and Needs you sheets; Runs filter single-choice groups as check rows and statuses in sentence case; Cupertino decision options as a check list; run action sheet titled with the run; usage page without the duplicate title and with honest empty states; Settings Reconnect wording, compact notifications row and a tinted Cupertino Save workspace; friendly artifact preview failures with Retry.
123 lines
4.2 KiB
Dart
123 lines
4.2 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../notify/notification_models.dart';
|
|
|
|
/// The permission tile's root, so a caller can find it whichever host draws it.
|
|
const notificationTileKey = ValueKey<String>('notification-permission-tile');
|
|
|
|
/// The explicit-gesture Enable action, present only when a request is possible.
|
|
const notificationEnableKey = ValueKey<String>(
|
|
'notification-permission-enable',
|
|
);
|
|
|
|
/// The honest state line, which says plainly when the in-app surface is the
|
|
/// only channel.
|
|
const notificationStateKey = ValueKey<String>('notification-permission-state');
|
|
|
|
/// The reusable Notifications permission tile for Settings.
|
|
///
|
|
/// It renders the platform's own [state] with the browser's own copy, shows the
|
|
/// Android rationale verbatim, and offers the [notificationRequestLabel] action
|
|
/// only while a request is still possible. Nothing here asks for permission on
|
|
/// its own — [onRequest] is the caller's explicit-gesture handler, and the tile
|
|
/// never guesses a grant.
|
|
///
|
|
/// The caller owns the surrounding section/card and passes the live state; the
|
|
/// tile reads no store, bridge or clock.
|
|
class NotificationPermissionTile extends StatelessWidget {
|
|
const NotificationPermissionTile({
|
|
super.key,
|
|
required this.state,
|
|
this.asked = false,
|
|
this.onRequest,
|
|
this.cupertino,
|
|
});
|
|
|
|
final NotificationPermissionState state;
|
|
|
|
/// Whether the operator has already been asked; only changes the wording.
|
|
final bool asked;
|
|
|
|
/// The explicit-gesture handler. Absent means no action is drawn even when a
|
|
/// request would be possible.
|
|
final VoidCallback? onRequest;
|
|
|
|
/// Forces the native host in tests and fixtures; otherwise the ambient
|
|
/// [usesCupertinoHost] decides.
|
|
final bool? cupertino;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final view = notificationPermissionView(state, asked: asked);
|
|
final native = cupertino ?? usesCupertinoHost(context);
|
|
final action = view.canRequest && onRequest != null
|
|
? _action(native, view.actionLabel!, onRequest!)
|
|
: null;
|
|
final titleStyle = native
|
|
? CupertinoTheme.of(context).textTheme.textStyle
|
|
: Theme.of(context).textTheme.bodyLarge;
|
|
final helperStyle = native
|
|
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(
|
|
fontSize: 15,
|
|
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
|
)
|
|
: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
);
|
|
// One compact row: the state, one short helper line and Enable at the
|
|
// end. The full sentence for the state is what a screen reader hears.
|
|
// The Settings section supplies the `Notifications` heading.
|
|
return Row(
|
|
key: notificationTileKey,
|
|
children: [
|
|
Expanded(
|
|
child: Semantics(
|
|
liveRegion: true,
|
|
label: view.body,
|
|
excludeSemantics: true,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
view.headline,
|
|
key: notificationStateKey,
|
|
style: titleStyle,
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(view.helper, style: helperStyle),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
if (action != null) ...[const SizedBox(width: 12), action],
|
|
],
|
|
);
|
|
}
|
|
|
|
/// A short `Enable`, named in full for assistive technology.
|
|
Widget _action(bool native, String label, VoidCallback onRequest) {
|
|
const text = Text(notificationEnableShortLabel);
|
|
final Widget button = native
|
|
? CupertinoButton.tinted(
|
|
key: notificationEnableKey,
|
|
sizeStyle: CupertinoButtonSize.small,
|
|
onPressed: onRequest,
|
|
child: text,
|
|
)
|
|
: FilledButton.tonal(
|
|
key: notificationEnableKey,
|
|
onPressed: onRequest,
|
|
child: text,
|
|
);
|
|
return Semantics(
|
|
button: true,
|
|
label: label,
|
|
excludeSemantics: true,
|
|
onTap: onRequest,
|
|
child: button,
|
|
);
|
|
}
|
|
}
|