Refactoring: extract generic widget class

This commit is contained in:
Ming Ming 2021-10-17 18:21:50 +08:00
parent 6a394cc93a
commit 39eae6dd1f
2 changed files with 74 additions and 31 deletions

View file

@ -29,6 +29,7 @@ import 'package:nc_photos/widget/album_browser_util.dart' as album_browser_util;
import 'package:nc_photos/widget/empty_list_indicator.dart';
import 'package:nc_photos/widget/processing_dialog.dart';
import 'package:nc_photos/widget/shared_file_viewer.dart';
import 'package:nc_photos/widget/unbounded_list_tile.dart';
class SharingBrowserArguments {
SharingBrowserArguments(this.account);
@ -379,38 +380,16 @@ class _ListTile extends StatelessWidget {
@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!,
],
),
return UnboundedListTile(
leading: leading,
title: Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
subtitle: Text(description),
trailing: trailing,
onTap: onTap,
);
}

View file

@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:nc_photos/theme.dart';
/// A [ListTile]-like widget with unbounded height
class UnboundedListTile extends StatelessWidget {
const UnboundedListTile({
Key? key,
this.leading,
required this.title,
this.subtitle,
this.trailing,
this.onTap,
}) : super(key: key);
@override
build(BuildContext context) {
final content = Padding(
padding: const EdgeInsets.all(16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (leading != null) ...[
leading!,
const SizedBox(width: 16),
],
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DefaultTextStyle(
style: Theme.of(context).textTheme.subtitle1!,
child: title,
),
if (subtitle != null)
DefaultTextStyle(
style: TextStyle(
color: AppTheme.getSecondaryTextColor(context),
),
child: subtitle!,
),
],
),
),
if (trailing != null) trailing!,
],
),
);
if (onTap != null) {
return InkWell(
onTap: onTap,
child: content,
);
} else {
return content;
}
}
final Widget? leading;
final Widget title;
final Widget? subtitle;
final Widget? trailing;
final VoidCallback? onTap;
}