import 'package:flutter/material.dart'; import '../notify/notification_models.dart'; /// The permission tile's root, so a caller can find it. const notificationTileKey = ValueKey('notification-permission-tile'); /// The explicit-gesture Enable action, present only when a request is possible. const notificationEnableKey = ValueKey( 'notification-permission-enable', ); /// The honest state line, which says plainly when the in-app surface is the /// only channel. const notificationStateKey = ValueKey('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, }); 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; @override Widget build(BuildContext context) { final view = notificationPermissionView(state, asked: asked); final action = view.canRequest && onRequest != null ? _action(view.actionLabel!, onRequest!) : null; final titleStyle = Theme.of(context).textTheme.bodyLarge; final helperStyle = 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(String label, VoidCallback onRequest) { const text = Text(notificationEnableShortLabel); final Widget button = FilledButton.tonal( key: notificationEnableKey, onPressed: onRequest, child: text, ); return Semantics( button: true, label: label, excludeSemantics: true, onTap: onRequest, child: button, ); } }