mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-14 11:18:54 +01:00
Refactor: extract class
This commit is contained in:
parent
e3e8169f47
commit
94c7e420d1
1 changed files with 37 additions and 11 deletions
|
@ -233,7 +233,35 @@ class _LandingPersonItem {
|
||||||
this.onTap,
|
this.onTap,
|
||||||
});
|
});
|
||||||
|
|
||||||
buildWidget(BuildContext context) {
|
Widget buildWidget(BuildContext context) => _LandingItemWidget(
|
||||||
|
account: account,
|
||||||
|
label: name,
|
||||||
|
coverUrl: faceUrl,
|
||||||
|
onTap: onTap,
|
||||||
|
fallbackBuilder: (_) => Icon(
|
||||||
|
Icons.person,
|
||||||
|
color: Colors.white.withOpacity(.8),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final Account account;
|
||||||
|
final String name;
|
||||||
|
final String faceUrl;
|
||||||
|
final VoidCallback? onTap;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LandingItemWidget extends StatelessWidget {
|
||||||
|
const _LandingItemWidget({
|
||||||
|
Key? key,
|
||||||
|
required this.account,
|
||||||
|
required this.label,
|
||||||
|
required this.coverUrl,
|
||||||
|
required this.fallbackBuilder,
|
||||||
|
this.onTap,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
build(BuildContext context) {
|
||||||
final content = Padding(
|
final content = Padding(
|
||||||
padding: const EdgeInsets.all(4),
|
padding: const EdgeInsets.all(4),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
@ -243,7 +271,7 @@ class _LandingPersonItem {
|
||||||
child: Center(
|
child: Center(
|
||||||
child: AspectRatio(
|
child: AspectRatio(
|
||||||
aspectRatio: 1,
|
aspectRatio: 1,
|
||||||
child: _buildFaceImage(context),
|
child: _buildCoverImage(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -251,7 +279,7 @@ class _LandingPersonItem {
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 88,
|
width: 88,
|
||||||
child: Text(
|
child: Text(
|
||||||
name + "\n",
|
label + "\n",
|
||||||
style: Theme.of(context).textTheme.bodyText1!.copyWith(
|
style: Theme.of(context).textTheme.bodyText1!.copyWith(
|
||||||
color: AppTheme.getPrimaryTextColor(context),
|
color: AppTheme.getPrimaryTextColor(context),
|
||||||
),
|
),
|
||||||
|
@ -273,14 +301,11 @@ class _LandingPersonItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildFaceImage(BuildContext context) {
|
Widget _buildCoverImage(BuildContext context) {
|
||||||
Widget cover;
|
Widget cover;
|
||||||
Widget buildPlaceholder() => Padding(
|
Widget buildPlaceholder() => Padding(
|
||||||
padding: const EdgeInsets.all(4),
|
padding: const EdgeInsets.all(4),
|
||||||
child: Icon(
|
child: fallbackBuilder(context),
|
||||||
Icons.person,
|
|
||||||
color: Colors.white.withOpacity(.8),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
cover = FittedBox(
|
cover = FittedBox(
|
||||||
|
@ -288,7 +313,7 @@ class _LandingPersonItem {
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
child: CachedNetworkImage(
|
child: CachedNetworkImage(
|
||||||
cacheManager: ThumbnailCacheManager.inst,
|
cacheManager: ThumbnailCacheManager.inst,
|
||||||
imageUrl: faceUrl!,
|
imageUrl: coverUrl,
|
||||||
httpHeaders: {
|
httpHeaders: {
|
||||||
"Authorization": Api.getAuthorizationHeaderValue(account),
|
"Authorization": Api.getAuthorizationHeaderValue(account),
|
||||||
},
|
},
|
||||||
|
@ -315,7 +340,8 @@ class _LandingPersonItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
final Account account;
|
final Account account;
|
||||||
final String name;
|
final String label;
|
||||||
final String? faceUrl;
|
final String coverUrl;
|
||||||
|
final Widget Function(BuildContext context) fallbackBuilder;
|
||||||
final VoidCallback? onTap;
|
final VoidCallback? onTap;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue