list_item.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import 'package:flutter/material.dart';
  2. import 'package:easy_refresh/src/painter/paths_painter.dart';
  3. /// List item.
  4. class ListItem extends StatelessWidget {
  5. const ListItem({
  6. Key? key,
  7. required this.title,
  8. this.subtitle,
  9. this.leading,
  10. this.icon,
  11. this.iconPaths,
  12. this.trailing,
  13. this.onTap,
  14. this.selected = false,
  15. this.divider = false,
  16. }) : super(key: key);
  17. final String title;
  18. final String? subtitle;
  19. final Widget? leading;
  20. final IconData? icon;
  21. final List<String>? iconPaths;
  22. final Widget? trailing;
  23. final bool selected;
  24. final VoidCallback? onTap;
  25. final bool divider;
  26. Widget? get _leading {
  27. if (leading != null) {
  28. return leading!;
  29. }
  30. if (icon != null) {
  31. return Container(
  32. height: 36,
  33. width: 36,
  34. decoration: BoxDecoration(
  35. color: Colors.white,
  36. borderRadius: const BorderRadius.all(Radius.circular(18)),
  37. ),
  38. alignment: Alignment.center,
  39. child: Icon(
  40. icon!,
  41. color: Colors.white,
  42. ),
  43. );
  44. }
  45. if (iconPaths != null) {
  46. return Container(
  47. height: 36,
  48. width: 36,
  49. decoration: BoxDecoration(
  50. color: Colors.white,
  51. borderRadius: const BorderRadius.all(Radius.circular(18)),
  52. ),
  53. alignment: Alignment.center,
  54. child: PathsPaint(
  55. paths: iconPaths!,
  56. colors: List.filled(
  57. iconPaths!.length, Colors.white),
  58. width: 24,
  59. ),
  60. );
  61. }
  62. return null;
  63. }
  64. @override
  65. Widget build(BuildContext context) {
  66. return Column(
  67. children: [
  68. ListTile(
  69. title: Text(title),
  70. subtitle: subtitle == null ? null : Text(subtitle!),
  71. leading: _leading,
  72. trailing: trailing,
  73. selected: selected,
  74. onTap: onTap,
  75. ),
  76. if (divider)
  77. Padding(
  78. padding: EdgeInsets.only(
  79. left: leading == null && icon == null ? 16 : 72, right: 16),
  80. child: const Divider(
  81. thickness: 1,
  82. height: 1,
  83. ),
  84. ),
  85. ],
  86. );
  87. }
  88. }