|
| 1 | +import 'package:flutter/cupertino.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; |
| 4 | + |
| 5 | +/// Uses either a `ListTile` or a `CupertinoListTile` |
| 6 | +class PlatformListTile extends StatelessWidget { |
| 7 | + const PlatformListTile({ |
| 8 | + Key? key, |
| 9 | + this.widgetKey, |
| 10 | + this.leading, |
| 11 | + required this.title, |
| 12 | + this.subtitle, |
| 13 | + this.trailing, |
| 14 | + this.isThreeLine = false, |
| 15 | + this.onTap, |
| 16 | + this.onLongPress, |
| 17 | + this.visualDensity, |
| 18 | + this.selected = false, |
| 19 | + this.mouseCursor, |
| 20 | + this.dense, |
| 21 | + this.shape, |
| 22 | + this.contentPadding, |
| 23 | + this.enabled = true, |
| 24 | + this.focusColor, |
| 25 | + this.hoverColor, |
| 26 | + this.focusNode, |
| 27 | + this.autofocus = false, |
| 28 | + this.tileColor, |
| 29 | + this.selectedTileColor, |
| 30 | + this.enableFeedback, |
| 31 | + this.horizontalTitleGap, |
| 32 | + this.minVerticalPadding, |
| 33 | + this.minLeadingWidth, |
| 34 | + }) : super(key: key); |
| 35 | + |
| 36 | + final Key? widgetKey; |
| 37 | + final Widget? leading; |
| 38 | + final Widget title; |
| 39 | + final Widget? subtitle; |
| 40 | + final Widget? trailing; |
| 41 | + final bool isThreeLine; |
| 42 | + final void Function()? onTap; |
| 43 | + |
| 44 | + /// Callback for long press gesture - only usable on Material |
| 45 | + final void Function()? onLongPress; |
| 46 | + |
| 47 | + /// Material-only mouse cursor |
| 48 | + final MouseCursor? mouseCursor; |
| 49 | + final bool selected; |
| 50 | + final bool? dense; |
| 51 | + final VisualDensity? visualDensity; |
| 52 | + final ShapeBorder? shape; |
| 53 | + final EdgeInsetsGeometry? contentPadding; |
| 54 | + final bool enabled; |
| 55 | + final Color? focusColor; |
| 56 | + final Color? hoverColor; |
| 57 | + final Color? tileColor; |
| 58 | + final Color? selectedTileColor; |
| 59 | + final FocusNode? focusNode; |
| 60 | + final bool autofocus; |
| 61 | + final bool? enableFeedback; |
| 62 | + final double? horizontalTitleGap; |
| 63 | + final double? minVerticalPadding; |
| 64 | + final double? minLeadingWidth; |
| 65 | + |
| 66 | + @override |
| 67 | + Widget build(BuildContext context) { |
| 68 | + return PlatformWidget( |
| 69 | + material: (context, platform) => ListTile( |
| 70 | + key: widgetKey, |
| 71 | + leading: leading, |
| 72 | + title: title, |
| 73 | + subtitle: subtitle, |
| 74 | + trailing: trailing, |
| 75 | + isThreeLine: isThreeLine, |
| 76 | + dense: dense, |
| 77 | + visualDensity: visualDensity, |
| 78 | + shape: shape, |
| 79 | + contentPadding: contentPadding, |
| 80 | + enabled: enabled, |
| 81 | + onTap: onTap, |
| 82 | + onLongPress: onLongPress, |
| 83 | + mouseCursor: mouseCursor, |
| 84 | + selected: selected, |
| 85 | + focusColor: focusColor, |
| 86 | + hoverColor: hoverColor, |
| 87 | + focusNode: focusNode, |
| 88 | + autofocus: autofocus, |
| 89 | + tileColor: tileColor, |
| 90 | + selectedTileColor: selectedTileColor, |
| 91 | + enableFeedback: enableFeedback, |
| 92 | + horizontalTitleGap: horizontalTitleGap, |
| 93 | + minVerticalPadding: minVerticalPadding, |
| 94 | + minLeadingWidth: minLeadingWidth, |
| 95 | + ), |
| 96 | + cupertino: (context, platform) => CupertinoListTile( |
| 97 | + key: widgetKey, |
| 98 | + leading: leading, |
| 99 | + title: title, |
| 100 | + subtitle: subtitle, |
| 101 | + trailing: trailing, |
| 102 | + leadingSize: (dense ?? false) ? 14 : 28, |
| 103 | + onTap: onTap, |
| 104 | + ), |
| 105 | + ); |
| 106 | + } |
| 107 | +} |
0 commit comments