💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob] Add new screen for save person
Neeraj Gupta18cf3f2e60bd
diff --git a/mobile/lib/generated/intl/messages_en.dart b/mobile/lib/generated/intl/messages_en.dartindex 940af4877f..d8417292d1 100644--- a/mobile/lib/generated/intl/messages_en.dart+++ b/mobile/lib/generated/intl/messages_en.dart@@ -408,6 +408,7 @@ class MessageLookup extends MessageLookupByLibrary {"backupStatusDescription": MessageLookupByLibrary.simpleMessage("Items that have been backed up will show up here"),"backupVideos": MessageLookupByLibrary.simpleMessage("Backup videos"),+ "birthday": MessageLookupByLibrary.simpleMessage("Birthday"),"blackFridaySale":MessageLookupByLibrary.simpleMessage("Black Friday Sale"),"blog": MessageLookupByLibrary.simpleMessage("Blog"),@@ -739,9 +740,12 @@ class MessageLookup extends MessageLookupByLibrary {"enterCode": MessageLookupByLibrary.simpleMessage("Enter code"),"enterCodeDescription": MessageLookupByLibrary.simpleMessage("Enter the code provided by your friend to claim free storage for both of you"),+ "enterDateOfBirth":+ MessageLookupByLibrary.simpleMessage("Birthday (optional)"),"enterEmail": MessageLookupByLibrary.simpleMessage("Enter email"),"enterFileName":MessageLookupByLibrary.simpleMessage("Enter file name"),+ "enterName": MessageLookupByLibrary.simpleMessage("Enter name"),"enterNewPasswordToEncrypt": MessageLookupByLibrary.simpleMessage("Enter a new password we can use to encrypt your data"),"enterPassword": MessageLookupByLibrary.simpleMessage("Enter password"),@@ -1131,6 +1135,8 @@ class MessageLookup extends MessageLookupByLibrary {MessageLookupByLibrary.simpleMessage("OpenStreetMap contributors"),"optionalAsShortAsYouLike": MessageLookupByLibrary.simpleMessage("Optional, as short as you like..."),+ "orMergeWithExistingPerson": MessageLookupByLibrary.simpleMessage(+ "Or merge with existing person"),"orPickAnExistingOne":MessageLookupByLibrary.simpleMessage("Or pick an existing one"),"pair": MessageLookupByLibrary.simpleMessage("Pair"),@@ -1349,6 +1355,7 @@ class MessageLookup extends MessageLookupByLibrary {"saveCollage": MessageLookupByLibrary.simpleMessage("Save collage"),"saveCopy": MessageLookupByLibrary.simpleMessage("Save copy"),"saveKey": MessageLookupByLibrary.simpleMessage("Save key"),+ "savePerson": MessageLookupByLibrary.simpleMessage("Save person"),"saveYourRecoveryKeyIfYouHaventAlready":MessageLookupByLibrary.simpleMessage("Save your recovery key if you haven\'t already"),diff --git a/mobile/lib/generated/intl/messages_pl.dart b/mobile/lib/generated/intl/messages_pl.dartindex d446bb852b..2fcbcfe497 100644--- a/mobile/lib/generated/intl/messages_pl.dart+++ b/mobile/lib/generated/intl/messages_pl.dart@@ -21,7 +21,7 @@ class MessageLookup extends MessageLookupByLibrary {String get localeName => 'pl';static String m6(count) =>- "${Intl.plural(count, one: 'Dodaj współuczestnika', few: 'Dodaj współuczestników', many: 'Dodaj współuczestników', other: 'Dodaj współuczestników')}";+ "${Intl.plural(count, one: 'Dodaj współuczestnika', few: 'Dodaj współuczestników', other: 'Dodaj współuczestników')}";static String m7(count) =>"${Intl.plural(count, one: 'Dodaj element', few: 'Dodaj elementy', other: 'Dodaj elementów')}";@@ -30,7 +30,7 @@ class MessageLookup extends MessageLookupByLibrary {"Twój dodatek ${storageAmount} jest ważny do ${endDate}";static String m9(count) =>- "${Intl.plural(count, one: 'Dodaj widza', few: 'Dodaj widzów', many: 'Dodaj widzów', other: 'Dodaj widzów')}";+ "${Intl.plural(count, one: 'Dodaj widza', few: 'Dodaj widzów', other: 'Dodaj widzów')}";static String m10(emailOrName) => "Dodane przez ${emailOrName}";diff --git a/mobile/lib/generated/l10n.dart b/mobile/lib/generated/l10n.dartindex a33c0511ea..c8cf88c93a 100644--- a/mobile/lib/generated/l10n.dart+++ b/mobile/lib/generated/l10n.dart@@ -8995,6 +8995,56 @@ class S {);}+ /// `Enter name`+ String get enterName {+ return Intl.message(+ 'Enter name',+ name: 'enterName',+ desc: '',+ args: [],+ );+ }++ /// `Save person`+ String get savePerson {+ return Intl.message(+ 'Save person',+ name: 'savePerson',+ desc: '',+ args: [],+ );+ }++ /// `Or merge with existing person`+ String get orMergeWithExistingPerson {+ return Intl.message(+ 'Or merge with existing person',+ name: 'orMergeWithExistingPerson',+ desc: '',+ args: [],+ );+ }++ /// `Birthday (optional)`+ String get enterDateOfBirth {+ return Intl.message(+ 'Birthday (optional)',+ name: 'enterDateOfBirth',+ desc: '',+ args: [],+ );+ }++ /// `Birthday`+ String get birthday {+ return Intl.message(+ 'Birthday',+ name: 'birthday',+ desc: '',+ args: [],+ );+ }+/// `Remove person label`String get removePersonLabel {return Intl.message(diff --git a/mobile/lib/l10n/intl_en.arb b/mobile/lib/l10n/intl_en.arbindex 88629cf49f..e7d445aaef 100644--- a/mobile/lib/l10n/intl_en.arb+++ b/mobile/lib/l10n/intl_en.arb@@ -1260,6 +1260,11 @@"createCollaborativeLink": "Create collaborative link","search": "Search","enterPersonName": "Enter person name",+ "enterName": "Enter name",+ "savePerson": "Save person",+ "orMergeWithExistingPerson" : "Or merge with existing person",+ "enterDateOfBirth": "Birthday (optional)",+ "birthday": "Birthday","removePersonLabel": "Remove person label","autoPairDesc": "Auto pair works only with devices that support Chromecast.","manualPairDesc": "Pair with PIN works with any screen you wish to view your album on.",diff --git a/mobile/lib/l10n/intl_pl.arb b/mobile/lib/l10n/intl_pl.arbindex 182563ad0c..1dfd9ef9df 100644--- a/mobile/lib/l10n/intl_pl.arb+++ b/mobile/lib/l10n/intl_pl.arb@@ -1247,8 +1247,8 @@"descriptions": "Opisy","addAName": "Dodaj nazwę","findPeopleByName": "Szybko szukaj osób po imieniu",- "addViewers": "{count, plural, one {Dodaj widza} few {Dodaj widzów} many {Dodaj widzów} other {Dodaj widzów}}",- "addCollaborators": "{count, plural, one {Dodaj współuczestnika} few {Dodaj współuczestników} many {Dodaj współuczestników} other {Dodaj współuczestników}}",+ "addViewers": "{count, plural, one {Dodaj widza} few {Dodaj widzów} other {Dodaj widzów}}",+ "addCollaborators": "{count, plural, one {Dodaj współuczestnika} few {Dodaj współuczestników} other {Dodaj współuczestników}}","longPressAnEmailToVerifyEndToEndEncryption": "Naciśnij i przytrzymaj e-mail, aby zweryfikować szyfrowanie end-to-end.","developerSettingsWarning": "Czy na pewno chcesz zmodyfikować ustawienia programisty?","developerSettings": "Ustawienia dla programistów",diff --git a/mobile/lib/ui/common/date_input.dart b/mobile/lib/ui/common/date_input.dartnew file mode 100644index 0000000000..a1b7e32806--- /dev/null+++ b/mobile/lib/ui/common/date_input.dart@@ -0,0 +1,171 @@+import 'package:flutter/material.dart';+import 'package:intl/intl.dart';+import "package:photos/theme/ente_theme.dart";++class DatePickerField extends StatefulWidget {+ final String? initialValue;+ final String? hintText;+ final void Function(DateTime?)? onChanged;+ final DateTime? firstDate;+ final DateTime? lastDate;+ final bool isRequired; // New parameter for optional/required state++ const DatePickerField({+ super.key,+ this.initialValue,+ this.hintText,+ this.onChanged,+ this.firstDate,+ this.lastDate,+ this.isRequired = true, // Default to required for backward compatibility+ });++ @override+ State<DatePickerField> createState() => _DatePickerFieldState();+}++class _DatePickerFieldState extends State<DatePickerField> {+ final TextEditingController _controller = TextEditingController();+ DateTime? _selectedDate;+ bool _hasError = false;++ @override+ void initState() {+ super.initState();+ if (widget.initialValue != null) {+ _controller.text = widget.initialValue!;+ _tryParseDate(widget.initialValue!);+ }+ }++ void _tryParseDate(String value) {+ // If the field is empty and not required, reset error state and clear date+ if (value.isEmpty && !widget.isRequired) {+ setState(() {+ _selectedDate = null;+ _hasError = false;+ });+ widget.onChanged?.call(null);+ return;+ }++ // Skip validation for empty optional fields+ if (value.isEmpty) {+ return;+ }++ try {+ // Try parsing different date formats+ DateTime? parsed;+ final List<String> formats = ['MM/dd/yyyy', 'MM-dd-yyyy', 'yyyy-MM-dd'];++ for (String format in formats) {+ try {+ parsed = DateFormat(format).parseStrict(value);+ break;+ } catch (_) {+ continue;+ }+ }++ if (parsed != null) {+ // Validate date range if specified+ bool isValid = true;+ if (widget.firstDate != null && parsed.isBefore(widget.firstDate!)) {+ isValid = false;+ }+ if (widget.lastDate != null && parsed.isAfter(widget.lastDate!)) {+ isValid = false;+ }++ setState(() {+ _selectedDate = isValid ? parsed : null;+ _hasError = !isValid;+ });++ if (isValid) {+ widget.onChanged?.call(parsed);+ }+ } else {+ setState(() {+ _selectedDate = null;+ _hasError = true;+ });+ }+ } catch (e) {+ setState(() {+ _selectedDate = null;+ _hasError = true;+ });+ }+ }++ Future<void> _showDatePicker() async {+ final DateTime? picked = await showDatePicker(+ context: context,+ initialDate: _selectedDate ?? DateTime.now(),+ firstDate: widget.firstDate ?? DateTime(1900),+ lastDate: widget.lastDate ?? DateTime(2100),+ );++ if (picked != null) {+ setState(() {+ _selectedDate = picked;+ _hasError = false;+ _controller.text = DateFormat('MM/dd/yyyy').format(picked);+ });+ widget.onChanged?.call(picked);+ }+ }++ @override+ Widget build(BuildContext context) {+ return TextFormField(+ controller: _controller,+ onChanged: (value) => _tryParseDate(value),+ decoration: InputDecoration(+ focusedBorder: OutlineInputBorder(+ borderRadius: const BorderRadius.all(Radius.circular(8.0)),+ borderSide: BorderSide(+ color: getEnteColorScheme(context).strokeMuted,+ ),+ ),+ fillColor: getEnteColorScheme(context).fillFaint,+ filled: true,+ hintText: widget.hintText ??+ "Enter date (DD/MM/YYYY)${widget.isRequired ? '' : ' (optional)'}",+ hintStyle: getEnteTextTheme(context).bodyFaint,+ contentPadding: const EdgeInsets.symmetric(+ horizontal: 16,+ vertical: 14,+ ),+ border: UnderlineInputBorder(+ borderSide: BorderSide.none,+ borderRadius: BorderRadius.circular(8),+ ),+ error: _hasError+ ? Align(+ alignment: Alignment.centerLeft,+ child: Text(+ 'Use format (MM-dd-YYYY or MM/dd/YYYY)',+ style: getEnteTextTheme(context).miniMuted,+ ),+ )+ : null,+ suffixIcon: IconButton(+ icon: const Icon(Icons.calendar_today),+ onPressed: _showDatePicker,+ color: _hasError+ ? getEnteColorScheme(context).warning500+ : getEnteColorScheme(context).strokeMuted,+ ),+ ),+ );+ }++ @override+ void dispose() {+ _controller.dispose();+ super.dispose();+ }+}diff --git a/mobile/lib/ui/viewer/people/add_person_action_sheet.dart b/mobile/lib/ui/viewer/people/add_person_action_sheet.dartindex 9aa05b16e4..bfdc61cb9f 100644--- a/mobile/lib/ui/viewer/people/add_person_action_sheet.dart+++ b/mobile/lib/ui/viewer/people/add_person_action_sheet.dart@@ -23,9 +23,10 @@ import 'package:photos/ui/components/buttons/button_widget.dart';import 'package:photos/ui/components/models/button_type.dart';import "package:photos/ui/components/text_input_widget.dart";import 'package:photos/ui/components/title_bar_title_widget.dart';-import "package:photos/ui/viewer/people/new_person_item_widget.dart";import "package:photos/ui/viewer/people/person_row_item.dart";+import "package:photos/ui/viewer/people/save_person.dart";import "package:photos/utils/dialog_util.dart";+import "package:photos/utils/navigation_util.dart";import "package:photos/utils/toast_util.dart";enum PersonActionType {@@ -48,29 +49,37 @@ String _actionName(Future<dynamic> showAssignPersonAction(BuildContext context, {required String clusterID,+ EnteFile? file,PersonActionType actionType = PersonActionType.assignPerson,bool showOptionToAddNewPerson = true,-}) {- return showBarModalBottomSheet(- context: context,- builder: (context) {- return PersonActionSheet(- actionType: actionType,- showOptionToCreateNewPerson: showOptionToAddNewPerson,- cluserID: clusterID,- );- },- shape: const RoundedRectangleBorder(- side: BorderSide(width: 0),- borderRadius: BorderRadius.vertical(- top: Radius.circular(5),- ),+}) async {+ return routeToPage(+ context,+ SavePerson(+ clusterID,+ file: file,),- topControl: const SizedBox.shrink(),- backgroundColor: getEnteColorScheme(context).backgroundElevated,- barrierColor: backdropFaintDark,- enableDrag: false,);+ // return showBarModalBottomSheet(+ // context: context,+ // builder: (context) {+ // return PersonActionSheet(+ // actionType: actionType,+ // showOptionToCreateNewPerson: showOptionToAddNewPerson,+ // cluserID: clusterID,+ // );+ // },+ // shape: const RoundedRectangleBorder(+ // side: BorderSide(width: 0),+ // borderRadius: BorderRadius.vertical(+ // top: Radius.circular(5),+ // ),+ // ),+ // topControl: const SizedBox.shrink(),+ // backgroundColor: getEnteColorScheme(context).backgroundElevated,+ // barrierColor: backdropFaintDark,+ // enableDrag: false,+ // );}class PersonActionSheet extends StatefulWidget {@@ -176,7 +185,7 @@ class _PersonActionSheetState extends State<PersonActionSheet> {Flexible _getPersonItems() {return Flexible(child: Padding(- padding: const EdgeInsets.fromLTRB(16, 24, 4, 0),+ padding: const EdgeInsets.symmetric(vertical: 16),child: FutureBuilder<List<(PersonEntity, EnteFile)>>(future: _getPersonsWithRecentFile(),builder: (context, snapshot) {@@ -208,8 +217,6 @@ class _PersonActionSheetState extends State<PersonActionSheet> {searchResults.sort((a, b) => a.$1.data.name.compareTo(b.$1.data.name),);- final shouldShowAddPerson = widget.showOptionToCreateNewPerson &&- (_searchQuery.isEmpty || searchResults.isEmpty);return Scrollbar(thumbVisibility: true,@@ -219,34 +226,8 @@ class _PersonActionSheetState extends State<PersonActionSheet> {child: ListView.separated(itemCount: searchResults.length + 1,itemBuilder: (context, index) {- if (index == 0 && shouldShowAddPerson) {- return GestureDetector(- behavior: HitTestBehavior.opaque,- child: const NewPersonItemWidget(),- onTap: () async => {- addNewPerson(- context,- initValue: _searchQuery.trim(),- clusterID: widget.cluserID,- ),- },- );- }- if (index == 0 && !shouldShowAddPerson) {- return Padding(- padding: const EdgeInsets.fromLTRB(0, 8, 0, 16),- child: Center(- child: Text(- S.of(context).mergeWithExisting,- style: getEnteTextTheme(context).body.copyWith(- color:- getEnteColorScheme(context).textMuted,- ),- ),- ),- );- }final person = searchResults[index - 1];+return PersonRowItem(person: person.$1,personFile: person.$2,diff --git a/mobile/lib/ui/viewer/people/cluster_page.dart b/mobile/lib/ui/viewer/people/cluster_page.dartindex 38f629d6e7..1565482b33 100644--- a/mobile/lib/ui/viewer/people/cluster_page.dart+++ b/mobile/lib/ui/viewer/people/cluster_page.dart@@ -148,6 +148,7 @@ class _ClusterPageState extends State<ClusterPage> {final result = await showAssignPersonAction(context,clusterID: widget.clusterID,+ file: files.isEmpty ? null : files.first,);if (result != null) {Navigator.pop(context);diff --git a/mobile/lib/ui/viewer/people/person_row_item.dart b/mobile/lib/ui/viewer/people/person_row_item.dartindex fa3dc38e23..9718364ca0 100644--- a/mobile/lib/ui/viewer/people/person_row_item.dart+++ b/mobile/lib/ui/viewer/people/person_row_item.dart@@ -36,3 +36,47 @@ class PersonRowItem extends StatelessWidget {);}}++class PersonGridItem extends StatelessWidget {+ final PersonEntity person;+ final EnteFile personFile;+ final VoidCallback onTap;++ const PersonGridItem({+ super.key,+ required this.person,+ required this.personFile,+ required this.onTap,+ });++ @override+ Widget build(BuildContext context) {+ return GestureDetector(+ onTap: onTap,+ child: Padding(+ padding: const EdgeInsets.all(8.0),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ SizedBox(+ width: 112,+ height: 112,+ child: ClipRRect(+ borderRadius: const BorderRadius.all(+ Radius.elliptical(16, 12),+ ),+ child: PersonFaceWidget(personFile, personId: person.remoteID),+ ),+ ),+ const SizedBox(height: 4),+ Text(+ person.data.name,+ style: Theme.of(context).textTheme.bodyMedium,+ overflow: TextOverflow.ellipsis,+ ),+ ],+ ),+ ),+ );+ }+}diff --git a/mobile/lib/ui/viewer/people/save_person.dart b/mobile/lib/ui/viewer/people/save_person.dartindex 907f4a2850..1b5db110d6 100644--- a/mobile/lib/ui/viewer/people/save_person.dart+++ b/mobile/lib/ui/viewer/people/save_person.dart@@ -1,13 +1,40 @@+import "dart:developer";++import "package:flutter/foundation.dart";import "package:flutter/material.dart";+import "package:logging/logging.dart";+import "package:photos/core/event_bus.dart";+import "package:photos/db/ml/db.dart";+import "package:photos/events/people_changed_event.dart";import "package:photos/generated/l10n.dart";+import "package:photos/l10n/l10n.dart";+import "package:photos/models/file/file.dart";+import "package:photos/models/ml/face/person.dart";+import "package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart";+import "package:photos/services/machine_learning/face_ml/person/person_service.dart";+import "package:photos/services/search_service.dart";import "package:photos/theme/ente_theme.dart";-import "package:photos/ui/common/email_input.dart";+import "package:photos/ui/common/date_input.dart";+import "package:photos/ui/common/loading_widget.dart";+import "package:photos/ui/components/buttons/button_widget.dart";+import "package:photos/ui/components/models/button_type.dart";+import "package:photos/ui/viewer/file/no_thumbnail_widget.dart";+import "package:photos/ui/viewer/people/person_row_item.dart";+import "package:photos/ui/viewer/search/result/person_face_widget.dart";+import "package:photos/utils/dialog_util.dart";+import "package:photos/utils/toast_util.dart";class SavePerson extends StatefulWidget {final String clusterID;+ final EnteFile? file;final bool isEditing;- const SavePerson(this.clusterID, {super.key, this.isEditing = false});+ const SavePerson(+ this.clusterID, {+ super.key,+ this.file,+ this.isEditing = false,+ });@overrideState<SavePerson> createState() => _SavePersonState();@@ -15,28 +42,56 @@ class SavePerson extends StatefulWidget {class _SavePersonState extends State<SavePerson> {bool isKeypadOpen = false;+ String _inputName = "";+ bool userAlreadyAssigned = false;+ late final Logger _logger = Logger("_SavePersonState");@overrideWidget build(BuildContext context) {return Scaffold(resizeToAvoidBottomInset: isKeypadOpen,appBar: AppBar(- title: Text(- widget.isEditing- ? S.of(context).addViewer- : S.of(context).addCollaborator,+ title: Align(+ alignment: Alignment.centerLeft,+ child: Text(+ context.l10n.savePerson,+ ),),),- body: Padding(- padding: EdgeInsets.symmetric(horizontal: 8.0),+ body: SingleChildScrollView(+ padding: const EdgeInsets.only(bottom: 16.0, left: 16.0, right: 16.0),child: Column(- crossAxisAlignment: CrossAxisAlignment.start,children: [- const SizedBox(height: 12),+ const SizedBox(height: 48),+ SizedBox(+ height: 110,+ width: 110,+ child: widget.file != null+ ? ClipRRect(+ borderRadius: const BorderRadius.all(+ Radius.elliptical(16, 12),+ ),+ child: PersonFaceWidget(+ widget.file!,+ clusterID: widget.clusterID,+ ),+ )+ : const ClipRRect(+ borderRadius: BorderRadius.all(+ Radius.elliptical(16, 12),+ ),+ child: NoThumbnailWidget(+ addBorder: false,+ ),+ ),+ ),+ const SizedBox(height: 36),TextFormField(- // controller: controller,- // focusNode: focusNode,- // onChanged: onChanged,+ onChanged: (value) {+ setState(() {+ _inputName = value;+ });+ },decoration: InputDecoration(focusedBorder: OutlineInputBorder(borderRadius: const BorderRadius.all(Radius.circular(8.0)),@@ -46,7 +101,7 @@ class _SavePersonState extends State<SavePerson> {),fillColor: getEnteColorScheme(context).fillFaint,filled: true,- hintText: "Enter name",+ hintText: context.l10n.enterName,hintStyle: getEnteTextTheme(context).bodyFaint,contentPadding: const EdgeInsets.symmetric(horizontal: 16,@@ -58,25 +113,179 @@ class _SavePersonState extends State<SavePerson> {),),),- const SizedBox(height: 8),- EmailInputField(- suggestions: [- "[email protected]",- "[email protected]",- "[email protected]",- "[email protected]",- "[email protected]",- "[email protected]",- ],+ const SizedBox(height: 16),+ DatePickerField(+ hintText: context.l10n.enterDateOfBirth,+ firstDate: DateTime(1900),+ lastDate: DateTime.now(),+ isRequired: false,),- const SizedBox(height: 8),- Text(- "aasdas",- style: getEnteTextTheme(context).body,+ const SizedBox(height: 32),+ ButtonWidget(+ buttonType: ButtonType.primary,+ labelText: context.l10n.save,+ isDisabled: _inputName.isEmpty,+ onTap: () async {+ await addNewPerson(+ context,+ text: _inputName,+ clusterID: widget.clusterID,+ );+ },),+ const SizedBox(height: 32),+ _getPersonItems(),],),),);}++ Widget _getPersonItems() {+ return Padding(+ padding: const EdgeInsets.fromLTRB(0, 12, 4, 0),+ child: FutureBuilder<List<(PersonEntity, EnteFile)>>(+ future: _getPersonsWithRecentFile(),+ builder: (context, snapshot) {+ if (snapshot.hasError) {+ log("Error: ${snapshot.error} ${snapshot.stackTrace}}");+ if (kDebugMode) {+ return Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ Text('${snapshot.error}'),+ Text('${snapshot.stackTrace}'),+ ],+ );+ } else {+ return const SizedBox.shrink();+ }+ } else if (snapshot.hasData) {+ final persons = snapshot.data!;+ final searchResults = _inputName.isNotEmpty+ ? persons+ .where(+ (element) => element.$1.data.name+ .toLowerCase()+ .contains(_inputName.toLowerCase()),+ )+ .toList()+ : persons;+ searchResults.sort(+ (a, b) => a.$1.data.name.compareTo(b.$1.data.name),+ );++ return Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ // left align+ Padding(+ padding: const EdgeInsets.only(top: 12, bottom: 12),+ child: Text(+ context.l10n.orMergeWithExistingPerson,+ style: getEnteTextTheme(context).largeBold,+ ),+ ),++ SizedBox(+ height: 160, // Adjust this height based on your needs+ child: ScrollConfiguration(+ behavior: ScrollConfiguration.of(context).copyWith(+ scrollbars: true,+ ),+ child: ListView.separated(+ scrollDirection: Axis.horizontal,+ padding: const EdgeInsets.only(right: 8),+ itemCount: searchResults.length,+ itemBuilder: (context, index) {+ final person = searchResults[index];+ return PersonGridItem(+ person: person.$1,+ personFile: person.$2,+ onTap: () async {+ if (userAlreadyAssigned) {+ return;+ }+ userAlreadyAssigned = true;+ await MLDataDB.instance.assignClusterToPerson(+ personID: person.$1.remoteID,+ clusterID: widget.clusterID,+ );+ Bus.instance.fire(PeopleChangedEvent());++ Navigator.pop(context, person);+ },+ );+ },+ separatorBuilder: (context, index) {+ return const SizedBox(width: 6);+ },+ ),+ ),+ ),+ ]);+ } else {+ return const EnteLoadingWidget();+ }+ },+ ),+ );+ }++ Future<void> addNewPerson(+ BuildContext context, {+ String text = '',+ required String clusterID,+ }) async {+ try {+ if (userAlreadyAssigned) {+ return;+ }+ if (text.trim() == "") {+ return;+ }+ userAlreadyAssigned = true;+ final personEntity =+ await PersonService.instance.addPerson(text, clusterID);+ final bool extraPhotosFound =+ await ClusterFeedbackService.instance.checkAndDoAutomaticMerges(+ personEntity,+ personClusterID: clusterID,+ );+ if (extraPhotosFound) {+ showShortToast(context, S.of(context).extraPhotosFound);+ }+ Bus.instance.fire(PeopleChangedEvent());+ Navigator.pop(context, personEntity);+ } catch (e) {+ _logger.severe("Error adding new person", e);+ userAlreadyAssigned = false;+ await showGenericErrorDialog(context: context, error: e);+ }+ }++ Future<List<(PersonEntity, EnteFile)>> _getPersonsWithRecentFile({+ bool excludeHidden = true,+ }) async {+ final persons = await PersonService.instance.getPersons();+ if (excludeHidden) {+ persons.removeWhere((person) => person.data.isIgnored);+ }+ final List<(PersonEntity, EnteFile)> personAndFileID = [];+ for (final person in persons) {+ final clustersToFiles =+ await SearchService.instance.getClusterFilesForPersonID(+ person.remoteID,+ );+ final files = clustersToFiles.values.expand((e) => e).toList();+ if (files.isEmpty) {+ debugPrint(+ "Person ${kDebugMode ? person.data.name : person.remoteID} has no files",+ );+ continue;+ }+ personAndFileID.add((person, files.first));+ }+ return personAndFileID;+ }}