123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- import 'package:flutter/material.dart';
- import 'package:easy_refresh/src/painter/paths_painter.dart';
- /// List item.
- class ListItem extends StatelessWidget {
- const ListItem({
- Key? key,
- required this.title,
- this.subtitle,
- this.leading,
- this.icon,
- this.iconPaths,
- this.trailing,
- this.onTap,
- this.selected = false,
- this.divider = false,
- }) : super(key: key);
- final String title;
- final String? subtitle;
- final Widget? leading;
- final IconData? icon;
- final List<String>? iconPaths;
- final Widget? trailing;
- final bool selected;
- final VoidCallback? onTap;
- final bool divider;
- Widget? get _leading {
- if (leading != null) {
- return leading!;
- }
- if (icon != null) {
- return Container(
- height: 36,
- width: 36,
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: const BorderRadius.all(Radius.circular(18)),
- ),
- alignment: Alignment.center,
- child: Icon(
- icon!,
- color: Colors.white,
- ),
- );
- }
- if (iconPaths != null) {
- return Container(
- height: 36,
- width: 36,
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: const BorderRadius.all(Radius.circular(18)),
- ),
- alignment: Alignment.center,
- child: PathsPaint(
- paths: iconPaths!,
- colors: List.filled(
- iconPaths!.length, Colors.white),
- width: 24,
- ),
- );
- }
- return null;
- }
- @override
- Widget build(BuildContext context) {
- return Column(
- children: [
- ListTile(
- title: Text(title),
- subtitle: subtitle == null ? null : Text(subtitle!),
- leading: _leading,
- trailing: trailing,
- selected: selected,
- onTap: onTap,
- ),
- if (divider)
- Padding(
- padding: EdgeInsets.only(
- left: leading == null && icon == null ? 16 : 72, right: 16),
- child: const Divider(
- thickness: 1,
- height: 1,
- ),
- ),
- ],
- );
- }
- }
|