Refactoring: extract widget class

This commit is contained in:
Ming Ming 2021-10-12 01:06:49 +08:00
parent afd859d414
commit 481387e8fb

View file

@ -155,21 +155,8 @@ class _SharingBrowserState extends State<SharingBrowser> {
final dateStr = DateFormat(DateFormat.YEAR_ABBR_MONTH_DAY,
Localizations.localeOf(context).languageCode)
.format(shares.first.share.stime.toLocal());
return InkWell(
onTap: () {
Navigator.of(context).pushNamed(SharedFileViewer.routeName,
arguments: SharedFileViewerArguments(
widget.account,
shares.first.file,
shares.map((e) => e.share).toList(),
));
},
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
shares.first.share.itemType == ShareItemType.folder
return _ListTile(
leading: shares.first.share.itemType == ShareItemType.folder
? const Icon(
Icons.folder_outlined,
size: leadingSize,
@ -189,34 +176,22 @@ class _SharingBrowserState extends State<SharingBrowser> {
filterQuality: FilterQuality.high,
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
shares.first.share.filename,
style: Theme.of(context).textTheme.subtitle1,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
shares.first.share.uidOwner == widget.account.username
label: shares.first.share.filename,
description: shares.first.share.uidOwner == widget.account.username
? L10n.global().fileLastSharedDescription(dateStr)
: L10n.global().fileLastSharedByOthersDescription(
shares.first.share.displaynameOwner, dateStr),
style: TextStyle(
color: AppTheme.getSecondaryTextColor(context),
),
),
],
),
),
if (shares.any((element) => element.share.url?.isNotEmpty == true))
const Icon(Icons.link)
],
),
),
trailing: (shares.any((element) => element.share.url?.isNotEmpty == true))
? const Icon(Icons.link)
: null,
onTap: () {
Navigator.of(context).pushNamed(SharedFileViewer.routeName,
arguments: SharedFileViewerArguments(
widget.account,
shares.first.file,
shares.map((e) => e.share).toList(),
));
},
);
}
@ -270,3 +245,56 @@ class _SharingBrowserState extends State<SharingBrowser> {
static final _log = Logger("widget.sharing_browser._SharingBrowserState");
}
class _ListTile extends StatelessWidget {
const _ListTile({
required this.leading,
required this.label,
required this.description,
this.trailing,
required this.onTap,
});
@override
build(BuildContext context) {
return InkWell(
onTap: onTap,
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
leading,
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: Theme.of(context).textTheme.subtitle1,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
description,
style: TextStyle(
color: AppTheme.getSecondaryTextColor(context),
),
),
],
),
),
if (trailing != null) trailing!,
],
),
),
);
}
final Widget leading;
final String label;
final String description;
final Widget? trailing;
final VoidCallback onTap;
}