Fix Android showCreator() name prefill#241
Open
CrashKiki wants to merge 1 commit into
Open
Conversation
Use Insert.NAME for name prefill and omit the StructuredName DATA row to avoid conflicting duplicate prefill (blue styled text). Keep phone and email in Insert.DATA only — do not also set Insert.PHONE/EMAIL, which duplicates those fields. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@CrashKiki thanks for your PR. I also found 'photo' variable not worked on android. Can you find why photo(or image, thumbnail) not worked? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On Android,
FlutterContacts.native.showCreator(contact: ...)pre-fills phone and email correctly, but first name and last name are empty in the native contact creator UI.On iOS, the same
Contactobject pre-fills all fields as expected.This appears to be a v2 regression: v1's
openExternalInsertsetInsert.NAMEand worked for name prefill; v2'sShowCreatorImplonly usesInsert.DATA.Environment
flutter_contacts: ^2.2.2Steps to reproduce
Contactwith name, phone, and email:Expected behavior
First name and last name fields are pre-filled (as on iOS).
Actual behavior (before fix)
Phone and email are pre-filled; name fields are empty.
App setup
READ_CONTACTSandWRITE_CONTACTSare declared inAndroidManifest.xml. Permissions are granted before callingshowCreator.Suspected cause
In v2,
ShowCreatorImpl.ktonly passesInsert.DATAwithStructuredNameContentValues. Many Android contact apps ignore structured name rows inInsert.DATAunlessContactsContract.Intents.Insert.NAMEis also set.In v1 (
openExternalInsert), the plugin setInsert.NAME, which worked for name prefill:Relevant v2 code (
ShowCreatorImpl.kt):Fix (included in this PR)
In
ShowCreatorImpl.kt, when building the insert intent:Insert.NAMEwith the full display name from name componentsStructuredNamerow fromInsert.DATAwhenInsert.NAMEis set (using both caused conflicting prefill)Insert.DATAonly — do not also setInsert.PHONE/Insert.EMAIL, as that duplicates those fieldsAlternatives considered
StructuredNameinInsert.DATAonly (v2 current)Insert.NAME+StructuredNameinDATAInsert.NAME+Insert.PHONE/EMAIL+DATAInsert.NAMEfor name, other fields inDATAonlyTesting
Tested on a physical Android device in a Flutter app using a local checkout of this package:
Known Android UX limitation
When pre-filling via
Insert.NAME, some contact apps (e.g. Google Contacts) show the full name in a single blue field first. Tapping it splits into structured first/last fields and the text turns white (matching email/phone). This appears to be standard platform behaviour for intent-based name prefill, not a bug in the fix. SeparateStructuredNameDATArows alone are not reliably shown by the editor UI.References
NAME,PHONE,EMAIL, andDATAextras forACTION_INSERTDATA"will be dropped" if not visible in the editor UIIntents.Insertkeys viaputExtra()to pre-populate the native insert screenFlutterContacts.ktopenExternalPickOrInsert