import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import '../../theme.dart'; class SlideTileAction { const SlideTileAction({ required this.actionScale, required this.onPressed, this.key, this.icon, this.label, }); final Key? key; final ScaleKind actionScale; final String? label; final IconData? icon; final SlidableActionCallback? onPressed; } class StyledSlideTile extends StatelessWidget { const StyledSlideTile( {required this.disabled, required this.selected, required this.tileScale, required this.title, this.subtitle = '', this.endActions = const [], this.startActions = const [], this.onTap, this.onDoubleTap, this.leading, this.trailing, super.key}); final bool disabled; final bool selected; final ScaleKind tileScale; final List endActions; final List startActions; final GestureTapCallback? onTap; final GestureTapCallback? onDoubleTap; final Widget? leading; final Widget? trailing; final String title; final String subtitle; @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties ..add(DiagnosticsProperty('disabled', disabled)) ..add(DiagnosticsProperty('selected', selected)) ..add(DiagnosticsProperty('tileScale', tileScale)) ..add(IterableProperty('endActions', endActions)) ..add(IterableProperty('startActions', startActions)) ..add(ObjectFlagProperty.has('onTap', onTap)) ..add(DiagnosticsProperty('leading', leading)) ..add(StringProperty('title', title)) ..add(StringProperty('subtitle', subtitle)) ..add(ObjectFlagProperty.has( 'onDoubleTap', onDoubleTap)) ..add(DiagnosticsProperty('trailing', trailing)); } @override Widget build(BuildContext context) { final theme = Theme.of(context); final scaleTheme = theme.extension()!; final scaleTileTheme = scaleTheme.tileTheme( disabled: disabled, selected: selected, scaleKind: tileScale); return Container( clipBehavior: Clip.antiAlias, decoration: ShapeDecoration( color: scaleTileTheme.backgroundColor, shape: scaleTileTheme.shapeBorder), child: Slidable( // Specify a key if the Slidable is dismissible. key: key, endActionPane: endActions.isEmpty ? null : ActionPane( motion: const DrawerMotion(), children: endActions.map((a) { final scaleActionTheme = scaleTheme.tileTheme( disabled: disabled, selected: true, scaleKind: a.actionScale); return SlidableAction( onPressed: disabled ? null : a.onPressed, backgroundColor: scaleActionTheme.backgroundColor, foregroundColor: scaleActionTheme.textColor, icon: subtitle.isEmpty ? a.icon : null, label: a.label, padding: const EdgeInsets.all(2).scaled(context), ); }).toList()), startActionPane: startActions.isEmpty ? null : ActionPane( motion: const DrawerMotion(), children: startActions.map((a) { final scaleActionTheme = scaleTheme.tileTheme( disabled: disabled, selected: true, scaleKind: a.actionScale); return SlidableAction( onPressed: disabled ? null : a.onPressed, backgroundColor: scaleActionTheme.backgroundColor, foregroundColor: scaleActionTheme.textColor, icon: subtitle.isEmpty ? a.icon : null, label: a.label, padding: const EdgeInsets.all(2).scaled(context), ); }).toList()), child: Padding( padding: scaleTheme.config.useVisualIndicators ? EdgeInsets.zero : const EdgeInsets.fromLTRB(0, 2, 0, 2).scaled(context), child: GestureDetector( onDoubleTap: onDoubleTap, child: ListTile( onTap: onTap, dense: true, title: Text( title, overflow: TextOverflow.fade, softWrap: false, ), subtitle: subtitle.isNotEmpty ? Text(subtitle) : null, contentPadding: const EdgeInsets.fromLTRB(8, 4, 8, 4) .scaled(context), iconColor: scaleTileTheme.textColor, textColor: scaleTileTheme.textColor, leading: leading != null ? FittedBox(child: leading) : null, trailing: trailing != null ? FittedBox(child: trailing) : null))))); } }