Skip to content

Remove clipboard_utils cross-imports from material and cupertino tests#184278

Open
xfce0 wants to merge 5 commits into
flutter:masterfrom
xfce0:fix-test-cross-imports
Open

Remove clipboard_utils cross-imports from material and cupertino tests#184278
xfce0 wants to merge 5 commits into
flutter:masterfrom
xfce0:fix-test-cross-imports

Conversation

@xfce0

@xfce0 xfce0 commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Part of #182636.

MockClipboard is a small (30-line) test utility with a trivial implementation, so duplication is the appropriate strategy per the issue guidelines. The file is copied into both test/material/ and
test/cupertino/, and all imports are updated to reference the local copy.

Pre-launch Checklist

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository labels Mar 28, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request relocates the MockClipboard utility to the cupertino and material test directories and updates several test files to use these local versions. Review feedback identifies a missing break statement in the Clipboard.setData case of the handleMethodCall method and recommends replacing the dynamic type for clipboardData with Map<String, dynamic> to improve type safety and align with Effective Dart guidelines.

Comment on lines +12 to +29
dynamic clipboardData = <String, dynamic>{'text': null};

Future<Object?> handleMethodCall(MethodCall methodCall) async {
switch (methodCall.method) {
case 'Clipboard.getData':
return clipboardData;
case 'Clipboard.hasStrings':
if (hasStringsThrows) {
throw Exception();
}
final clipboardDataMap = clipboardData as Map<String, dynamic>?;
final text = clipboardDataMap?['text'] as String?;
return <String, bool>{'value': text != null && text.isNotEmpty};
case 'Clipboard.setData':
clipboardData = methodCall.arguments;
}
return null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

There are a couple of issues here:

  1. The clipboardData field is dynamic. For better type safety and readability, it should be strongly typed as Map<String, dynamic>. This aligns with Effective Dart guidelines to avoid dynamic.
  2. The case 'Clipboard.setData' is missing a break; statement, which will cause a compilation error as Dart does not allow fall-through in non-empty case blocks.

The suggested change addresses both points.

Suggested change
dynamic clipboardData = <String, dynamic>{'text': null};
Future<Object?> handleMethodCall(MethodCall methodCall) async {
switch (methodCall.method) {
case 'Clipboard.getData':
return clipboardData;
case 'Clipboard.hasStrings':
if (hasStringsThrows) {
throw Exception();
}
final clipboardDataMap = clipboardData as Map<String, dynamic>?;
final text = clipboardDataMap?['text'] as String?;
return <String, bool>{'value': text != null && text.isNotEmpty};
case 'Clipboard.setData':
clipboardData = methodCall.arguments;
}
return null;
}
Map<String, dynamic> clipboardData = <String, dynamic>{'text': null};
Future<Object?> handleMethodCall(MethodCall methodCall) async {
switch (methodCall.method) {
case 'Clipboard.getData':
return clipboardData;
case 'Clipboard.hasStrings':
if (hasStringsThrows) {
throw Exception();
}
final text = clipboardData['text'] as String?;
return <String, bool>{'value': text != null && text.isNotEmpty};
case 'Clipboard.setData':
clipboardData = methodCall.arguments as Map<String, dynamic>;
break;
}
return null;
}
References
  1. The repository style guide recommends following Effective Dart (line 20), which advises against using dynamic when a more specific type is available. Using Map<String, dynamic> improves readability and type safety. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed both issues — typed clipboardData as Map<String, dynamic> and added break. Applied to both copies. Thanks!

Comment on lines +12 to +29
dynamic clipboardData = <String, dynamic>{'text': null};

Future<Object?> handleMethodCall(MethodCall methodCall) async {
switch (methodCall.method) {
case 'Clipboard.getData':
return clipboardData;
case 'Clipboard.hasStrings':
if (hasStringsThrows) {
throw Exception();
}
final clipboardDataMap = clipboardData as Map<String, dynamic>?;
final text = clipboardDataMap?['text'] as String?;
return <String, bool>{'value': text != null && text.isNotEmpty};
case 'Clipboard.setData':
clipboardData = methodCall.arguments;
}
return null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

There are a couple of issues here:

  1. The clipboardData field is dynamic. For better type safety and readability, it should be strongly typed as Map<String, dynamic>. This aligns with Effective Dart guidelines to avoid dynamic.
  2. The case 'Clipboard.setData' is missing a break; statement, which will cause a compilation error as Dart does not allow fall-through in non-empty case blocks.

The suggested change addresses both points.

Suggested change
dynamic clipboardData = <String, dynamic>{'text': null};
Future<Object?> handleMethodCall(MethodCall methodCall) async {
switch (methodCall.method) {
case 'Clipboard.getData':
return clipboardData;
case 'Clipboard.hasStrings':
if (hasStringsThrows) {
throw Exception();
}
final clipboardDataMap = clipboardData as Map<String, dynamic>?;
final text = clipboardDataMap?['text'] as String?;
return <String, bool>{'value': text != null && text.isNotEmpty};
case 'Clipboard.setData':
clipboardData = methodCall.arguments;
}
return null;
}
Map<String, dynamic> clipboardData = <String, dynamic>{'text': null};
Future<Object?> handleMethodCall(MethodCall methodCall) async {
switch (methodCall.method) {
case 'Clipboard.getData':
return clipboardData;
case 'Clipboard.hasStrings':
if (hasStringsThrows) {
throw Exception();
}
final text = clipboardData['text'] as String?;
return <String, bool>{'value': text != null && text.isNotEmpty};
case 'Clipboard.setData':
clipboardData = methodCall.arguments as Map<String, dynamic>;
break;
}
return null;
}
References
  1. The repository style guide recommends following Effective Dart (line 20), which advises against using dynamic when a more specific type is available. Using Map<String, dynamic> improves readability and type safety. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same fix applied here as well.

@victorsanni

Copy link
Copy Markdown
Contributor

Hi @xfce0, this PR is currently targeting main, can you repurpose it to target master? Thanks.

victorsanni
victorsanni previously approved these changes Apr 1, 2026
@victorsanni victorsanni requested a review from justinmc April 1, 2026 21:17
justinmc
justinmc previously approved these changes Apr 1, 2026

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 .I think I agree with the decision to duplicate here. We could always move it to flutter_test later if people want to use it. Thanks for helping out with this migration!

@justinmc justinmc added the CICD Run CI/CD label Apr 1, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026
@xfce0 xfce0 changed the base branch from main to master April 2, 2026 08:48
@xfce0 xfce0 dismissed stale reviews from justinmc and victorsanni April 2, 2026 08:48

The base branch was changed.

@xfce0 xfce0 force-pushed the fix-test-cross-imports branch from a47d8f9 to 03bc3fb Compare April 2, 2026 09:00
@xfce0

xfce0 commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

Done, retargeted to master. Thank you!

@loic-sharma loic-sharma requested a review from justinmc April 2, 2026 20:38
@xfce0

xfce0 commented Apr 3, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the latest master.

@xfce0 xfce0 force-pushed the fix-test-cross-imports branch from 03bc3fb to 51464b3 Compare April 3, 2026 10:13
justinmc
justinmc previously approved these changes Apr 3, 2026

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

victorsanni
victorsanni previously approved these changes Apr 4, 2026
@victorsanni victorsanni added the CICD Run CI/CD label Apr 4, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request is not mergeable in its current state, likely because of a merge conflict. Pre-submit CI jobs were not triggered. Pushing a new commit to this branch that resolves the issue will result in pre-submit jobs being scheduled.

@victorsanni

Copy link
Copy Markdown
Contributor

Hi @xfce0, can you fix the merge conflict in this PR?

@xfce0 xfce0 dismissed stale reviews from victorsanni and justinmc via 7f4a285 April 4, 2026 05:41
@xfce0 xfce0 force-pushed the fix-test-cross-imports branch from 51464b3 to 7f4a285 Compare April 4, 2026 05:41
@dkwingsmt dkwingsmt requested review from justinmc and victorsanni May 6, 2026 18:20
@github-actions github-actions Bot removed the CICD Run CI/CD label May 6, 2026
justinmc
justinmc previously approved these changes May 6, 2026

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. There were analyzer failures again but I've pushed a merge commit to hopefully resolve them.

@justinmc justinmc added the CICD Run CI/CD label May 6, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 8, 2026
victorsanni
victorsanni previously approved these changes May 8, 2026

@victorsanni victorsanni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR. Can you run dart format packages/flutter/test/material/adaptive_text_selection_toolbar_test.dart packages/flutter/test/material/text_selection_test.dart packages/flutter/test/material/selectable_text_test.dart packages/flutter/test/cupertino/text_field_test.dart packages/flutter/test/material/text_field_test.dart

to fix the failing linux analyze check? Thanks!

@victorsanni victorsanni added the CICD Run CI/CD label May 8, 2026
@xfce0 xfce0 dismissed stale reviews from victorsanni and justinmc via b9009e2 May 10, 2026 09:32
@xfce0 xfce0 force-pushed the fix-test-cross-imports branch from 166dd19 to b9009e2 Compare May 10, 2026 09:32
@github-actions github-actions Bot removed the CICD Run CI/CD label May 10, 2026
@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label May 10, 2026
@fluttergithubbot

Copy link
Copy Markdown
Contributor

An existing Git SHA, b9009e248f9adce0ee78f2ac61b153ed64882dbc, was detected, and no actions were taken.

To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with --force) that already was pushed before, push a blank commit (git commit --allow-empty -m "Trigger Build") or rebase to continue.

@github-actions github-actions Bot removed the CICD Run CI/CD label May 10, 2026
@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label May 10, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 10, 2026
@xfce0 xfce0 force-pushed the fix-test-cross-imports branch from 9c81ec8 to f909984 Compare May 10, 2026 16:30
@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label May 11, 2026
@AbdeMohlbi

Copy link
Copy Markdown
Member

@xfce0 can you format the files again ?

@dkwingsmt

Copy link
Copy Markdown
Contributor

Seems like there are still some analyzer error left. (from triage)

@xfce0

xfce0 commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

Hi @justinmc @victorsanni — all CI checks are now passing (87 checks green). Could you please re-review when you have a moment? Thanks!

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So sorry for all of the back and forth here, but would it be possible to undo the formatting changes? The formatting check is now disabled so the PR should still pass.

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

Labels

a: text input Entering text in a text field or keyboard related problems CICD Run CI/CD f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. override code freeze Override an active code freeze.

Projects

Development

Successfully merging this pull request may close these issues.

8 participants