Skip to content

Fix Android showCreator() name prefill#241

Open
CrashKiki wants to merge 1 commit into
QuisApp:mainfrom
CrashKiki:fix/android-showcreator-name-prefill
Open

Fix Android showCreator() name prefill#241
CrashKiki wants to merge 1 commit into
QuisApp:mainfrom
CrashKiki:fix/android-showcreator-name-prefill

Conversation

@CrashKiki

Copy link
Copy Markdown

Note: I'm not familiar with Android development. I used AI to investigate the bug, draft this write-up, and implement/test a fix in a local fork. I've verified the fix works on a physical Android device in my app, but please review the approach — happy to adjust based on maintainer feedback.

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 Contact object pre-fills all fields as expected.

This appears to be a v2 regression: v1's openExternalInsert set Insert.NAME and worked for name prefill; v2's ShowCreatorImpl only uses Insert.DATA.

Environment

  • Package: flutter_contacts: ^2.2.2
  • Platform: Android (tested on a physical device)
  • Flutter: 3.44.1 (stable)
  • Dart: 3.12.1

Steps to reproduce

  1. Build a Contact with name, phone, and email:
final contact = Contact(
  name: Name(first: 'John', last: 'Smith'),
  phones: [Phone(number: '0821234567')],
  emails: [Email(address: 'john@example.com')],
);
  1. Call:
await FlutterContacts.native.showCreator(contact: contact);
  1. Observe the native Android "Add contact" screen.

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_CONTACTS and WRITE_CONTACTS are declared in AndroidManifest.xml. Permissions are granted before calling showCreator.

Suspected cause

In v2, ShowCreatorImpl.kt only passes Insert.DATA with StructuredName ContentValues. Many Android contact apps ignore structured name rows in Insert.DATA unless ContactsContract.Intents.Insert.NAME is also set.

In v1 (openExternalInsert), the plugin set Insert.NAME, which worked for name prefill:

intent.putExtra(ContactsContract.Intents.Insert.NAME, fullName)

Relevant v2 code (ShowCreatorImpl.kt):

val intent =
    Intent(Intent.ACTION_INSERT).apply { type = ContactsContract.Contacts.CONTENT_TYPE }
contact?.let {
    val dataList = ContactBuilder.buildInsertDataForIntent(it)
    if (dataList.isNotEmpty()) intent.putParcelableArrayListExtra(Insert.DATA, dataList)
}

Fix (included in this PR)

In ShowCreatorImpl.kt, when building the insert intent:

  • Set Insert.NAME with the full display name from name components
  • Omit the StructuredName row from Insert.DATA when Insert.NAME is set (using both caused conflicting prefill)
  • Keep phone, email, and other fields in Insert.DATA only — do not also set Insert.PHONE / Insert.EMAIL, as that duplicates those fields

Alternatives considered

Approach Result
StructuredName in Insert.DATA only (v2 current) Names do not show
Insert.NAME + StructuredName in DATA Name fields pre-fill but with conflicting/blue styled text
Insert.NAME + Insert.PHONE/EMAIL + DATA Duplicate phone number
Insert.NAME for name, other fields in DATA only Works — included in this PR

Testing

Tested on a physical Android device in a Flutter app using a local checkout of this package:

  • Name pre-fills correctly after fix
  • Phone and email pre-fill once (no duplicates)
  • iOS behaviour unchanged (this change is Android-only)

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. Separate StructuredName DATA rows alone are not reliably shown by the editor UI.

References

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>
@Eunno-An

Eunno-An commented Jul 9, 2026

Copy link
Copy Markdown

@CrashKiki thanks for your PR. I also found 'photo' variable not worked on android. Can you find why photo(or image, thumbnail) not worked?
I also commented a issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants