2026-07-30 12:39:24 -07:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
2025-07-29 22:07:53 -05:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2026-08-15 16:55:45 +05:30
|
|
|
import 'package:immich_mobile/domain/models/person.model.dart';
|
2025-07-29 22:07:53 -05:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2026-06-10 11:05:07 +01:00
|
|
|
import 'package:immich_mobile/extensions/string_extensions.dart';
|
2026-08-11 14:41:13 +05:30
|
|
|
import 'package:immich_mobile/generated/translations.g.dart';
|
2026-02-05 12:16:42 -05:00
|
|
|
import 'package:immich_mobile/presentation/widgets/images/remote_image_provider.dart';
|
2026-07-30 01:56:46 -07:00
|
|
|
import 'package:immich_mobile/providers/infrastructure/people.provider.dart';
|
2025-07-29 22:07:53 -05:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
|
|
|
|
import 'package:immich_mobile/utils/image_url_builder.dart';
|
|
|
|
|
import 'package:immich_mobile/utils/people.utils.dart';
|
|
|
|
|
import 'package:immich_mobile/widgets/common/search_field.dart';
|
|
|
|
|
|
|
|
|
|
@RoutePage()
|
|
|
|
|
class DriftPeopleCollectionPage extends ConsumerStatefulWidget {
|
|
|
|
|
const DriftPeopleCollectionPage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
ConsumerState<DriftPeopleCollectionPage> createState() => _DriftPeopleCollectionPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _DriftPeopleCollectionPageState extends ConsumerState<DriftPeopleCollectionPage> {
|
|
|
|
|
final FocusNode _formFocus = FocusNode();
|
|
|
|
|
String? _search;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_formFocus.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-08-12 21:12:12 +05:30
|
|
|
final people = ref.watch(getAllPeopleProvider);
|
2025-07-29 22:07:53 -05:00
|
|
|
|
|
|
|
|
return LayoutBuilder(
|
|
|
|
|
builder: (context, constraints) {
|
|
|
|
|
final isTablet = constraints.maxWidth > 600;
|
|
|
|
|
final isPortrait = context.orientation == Orientation.portrait;
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
automaticallyImplyLeading: _search == null,
|
|
|
|
|
title: _search != null
|
|
|
|
|
? SearchField(
|
|
|
|
|
focusNode: _formFocus,
|
|
|
|
|
onTapOutside: (_) => _formFocus.unfocus(),
|
|
|
|
|
onChanged: (value) => setState(() => _search = value),
|
|
|
|
|
filled: true,
|
2026-08-11 14:41:13 +05:30
|
|
|
hintText: context.t.filter_people,
|
2025-07-29 22:07:53 -05:00
|
|
|
autofocus: true,
|
|
|
|
|
)
|
2026-08-11 14:41:13 +05:30
|
|
|
: Text(context.t.people),
|
2025-07-29 22:07:53 -05:00
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(_search != null ? Icons.close : Icons.search),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
setState(() => _search = _search == null ? '' : null);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
child: people.when(
|
|
|
|
|
data: (people) {
|
2026-08-15 16:55:45 +05:30
|
|
|
final List<Person> filtered;
|
2025-07-29 22:07:53 -05:00
|
|
|
if (_search != null) {
|
2026-08-15 16:55:45 +05:30
|
|
|
filtered = people.where((person) {
|
2026-06-10 11:05:07 +01:00
|
|
|
return person.name.toLowerCase().removeDiacritics().contains(
|
|
|
|
|
_search!.toLowerCase().removeDiacritics(),
|
|
|
|
|
);
|
2025-07-29 22:07:53 -05:00
|
|
|
}).toList();
|
2026-08-15 16:55:45 +05:30
|
|
|
} else {
|
|
|
|
|
filtered = people;
|
2025-07-29 22:07:53 -05:00
|
|
|
}
|
|
|
|
|
return GridView.builder(
|
|
|
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
|
|
|
crossAxisCount: isTablet ? 6 : 3,
|
|
|
|
|
childAspectRatio: 0.85,
|
|
|
|
|
mainAxisSpacing: isPortrait && isTablet ? 36 : 0,
|
|
|
|
|
),
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 32),
|
2026-08-15 16:55:45 +05:30
|
|
|
itemCount: filtered.length,
|
2025-07-29 22:07:53 -05:00
|
|
|
itemBuilder: (context, index) {
|
2026-08-15 16:55:45 +05:30
|
|
|
final person = filtered[index];
|
2025-07-29 22:07:53 -05:00
|
|
|
|
|
|
|
|
return Column(
|
2026-03-23 16:50:56 +01:00
|
|
|
key: ValueKey(person.id),
|
2025-07-29 22:07:53 -05:00
|
|
|
children: [
|
|
|
|
|
GestureDetector(
|
|
|
|
|
onTap: () {
|
2026-07-30 12:39:24 -07:00
|
|
|
unawaited(context.pushRoute(DriftPersonRoute(person: person)));
|
2025-07-29 22:07:53 -05:00
|
|
|
},
|
|
|
|
|
child: Material(
|
|
|
|
|
shape: const CircleBorder(side: BorderSide.none),
|
|
|
|
|
elevation: 3,
|
|
|
|
|
child: CircleAvatar(
|
2026-04-14 17:05:09 +02:00
|
|
|
key: ValueKey(person.id),
|
2025-07-29 22:07:53 -05:00
|
|
|
maxRadius: isTablet ? 100 / 2 : 96 / 2,
|
2026-07-29 22:50:26 +06:00
|
|
|
backgroundImage: RemoteImageProvider(
|
|
|
|
|
url: getFaceThumbnailUrl(person.id, updatedAt: person.updatedAt),
|
|
|
|
|
),
|
2025-07-29 22:07:53 -05:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
GestureDetector(
|
|
|
|
|
onTap: () => showNameEditModal(context, person),
|
|
|
|
|
child: person.name.isEmpty
|
|
|
|
|
? Text(
|
2026-08-11 14:41:13 +05:30
|
|
|
context.t.add_a_name,
|
2025-07-29 22:07:53 -05:00
|
|
|
style: context.textTheme.titleSmall?.copyWith(
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
color: context.colorScheme.primary,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
person.name,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
style: context.textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w500),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
error: (error, stack) => const Text("error"),
|
|
|
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|