Refactoring: extract label views

This commit is contained in:
Ming Ming 2021-08-10 18:10:22 +08:00
parent 975a574ffd
commit 88ab3113f6
2 changed files with 62 additions and 27 deletions

View file

@ -831,15 +831,8 @@ class _LabelListItem extends _ListItem {
@override @override
buildWidget(BuildContext context) { buildWidget(BuildContext context) {
return Container( return PhotoListLabel(
alignment: AlignmentDirectional.centerStart, text: text,
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
text,
style: Theme.of(context).textTheme.subtitle1,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
); );
} }
@ -866,24 +859,9 @@ class _EditLabelListItem extends _LabelListItem {
@override @override
buildWidget(BuildContext context) { buildWidget(BuildContext context) {
return Stack( return PhotoListLabelEdit(
children: [ text: text,
// needed to expand the touch sensitive area to the whole row onEditPressed: onEditPressed,
Container(
color: Colors.transparent,
),
super.buildWidget(context),
PositionedDirectional(
top: 0,
bottom: 0,
end: 0,
child: IconButton(
icon: Icon(Icons.edit),
tooltip: L10n.of(context).editTooltip,
onPressed: onEditPressed,
),
),
],
); );
} }

View file

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:nc_photos/account.dart'; import 'package:nc_photos/account.dart';
import 'package:nc_photos/api/api.dart'; import 'package:nc_photos/api/api.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/theme.dart'; import 'package:nc_photos/theme.dart';
class PhotoListImage extends StatelessWidget { class PhotoListImage extends StatelessWidget {
@ -130,3 +131,59 @@ class PhotoListVideo extends StatelessWidget {
final Account account; final Account account;
final String previewUrl; final String previewUrl;
} }
class PhotoListLabel extends StatelessWidget {
const PhotoListLabel({
Key? key,
required this.text,
}) : super(key: key);
@override
build(BuildContext context) {
return Container(
alignment: AlignmentDirectional.centerStart,
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
text,
style: Theme.of(context).textTheme.subtitle1,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
);
}
final String text;
}
class PhotoListLabelEdit extends PhotoListLabel {
const PhotoListLabelEdit({
Key? key,
required String text,
required this.onEditPressed,
}) : super(key: key, text: text);
@override
build(BuildContext context) {
return Stack(
children: [
// needed to expand the touch sensitive area to the whole row
Container(
color: Colors.transparent,
),
super.build(context),
PositionedDirectional(
top: 0,
bottom: 0,
end: 0,
child: IconButton(
icon: Icon(Icons.edit),
tooltip: L10n.of(context).editTooltip,
onPressed: onEditPressed,
),
),
],
);
}
final VoidCallback? onEditPressed;
}