auto-submit[bot] ab86f66e94
Reverts "Standardize on Test* widgets in *_tester.dart files (#182395)" (#182406)
<!-- start_original_pr_link -->
Reverts: flutter/flutter#182395
<!-- end_original_pr_link -->
<!-- start_initiating_author -->
Initiated by: gaaclarke
<!-- end_initiating_author -->
<!-- start_revert_reason -->
Reason for reverting: this is causing breakages on the dashboard

example:
https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8689933991528003217/+/u/run_test.dart_for_framework_tests_shard_and_subshard_libraries/stdout

```
10:36 +9458 ~24: /b/s/w/ir/x/w/flutter/packages/flutter/test/material/dialog_test.dart: Dialog children padding is correct AlertDialog padding is correct when only icon, title a
<!-- end_revert_reason -->
<!-- start_original_pr_author -->
Original PR Author: justinmc
<!-- end_original_pr_author -->

<!-- start_reviewers -->
Reviewed By: {Renzo-Olivares, victorsanni, navaronbracke}
<!-- end_reviewers -->

<!-- start_revert_body -->
This change reverts the following previous change:
This PR moves:

 * TestTextField from editable_text_utils.dart to editable_text_tester.dart
 * TestListTile from list_tile_test_utils.dart to list_tile_tester.dart
 * TestButton from utils.dart to button_tester.dart
 
The purpose is to align with other Test* widgets, such as TestWidgetsApp in [widgets_app_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/widgets_app_tester.dart) and TestSemantics in [semantics_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/semantics_tester.dart).

We should continue to follow this pattern in the future, such as in https://github.com/flutter/flutter/pull/181722.
<!-- end_revert_body -->

Co-authored-by: auto-submit[bot] <flutter-engprod-team@google.com>
2026-02-14 01:46:47 +00:00

63 lines
1.6 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file defines basic widgets for use in tests for Widgets in `flutter/widgets`.
import 'package:flutter/widgets.dart';
/// Get a color for use in a widget test.
///
/// The returned color will be fully opaque,
/// but the [Color.r], [Color.g], and [Color.b] channels
/// will vary sequentially based on index, cycling every sixth integer.
Color getTestColor(int index) {
const colors = [
Color(0xFFFF0000),
Color(0xFF00FF00),
Color(0xFF0000FF),
Color(0xFFFFFF00),
Color(0xFFFF00FF),
Color(0xFF00FFFF),
];
return colors[index % colors.length];
}
// TODO(justinmc): replace with `RawButton` or equivalent when available.
/// A very basic button for use in widget tests.
class TestButton extends StatelessWidget {
const TestButton({
required this.child,
this.focusNode,
this.autofocus = false,
this.onPressed,
super.key,
});
final bool autofocus;
final FocusNode? focusNode;
final VoidCallback? onPressed;
final Widget child;
void _onFocus() => focusNode?.requestFocus();
@override
Widget build(BuildContext context) {
return Semantics(
label: 'button',
button: true,
enabled: onPressed != null,
onTap: onPressed,
onFocus: _onFocus,
focusable: true,
child: FocusableActionDetector(
enabled: onPressed != null,
focusNode: focusNode,
autofocus: autofocus,
child: GestureDetector(onTap: onPressed, child: child),
),
);
}
}