diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 836be534b31d..cb85e87f971f 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -433,7 +433,6 @@ final Set _knownMissingTests = { 'examples/api/test/widgets/image/image.loading_builder.0_test.dart', 'examples/api/test/widgets/shortcuts/logical_key_set.0_test.dart', 'examples/api/test/widgets/shortcuts/shortcuts.0_test.dart', - 'examples/api/test/widgets/shortcuts/single_activator.single_activator.0_test.dart', 'examples/api/test/widgets/shortcuts/shortcuts.1_test.dart', 'examples/api/test/widgets/shortcuts/callback_shortcuts.0_test.dart', 'examples/api/test/widgets/page_storage/page_storage.0_test.dart', diff --git a/examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart b/examples/api/lib/widgets/shortcuts/single_activator.0.dart similarity index 96% rename from examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart rename to examples/api/lib/widgets/shortcuts/single_activator.0.dart index 5cb5eb8b688d..4552c96a8324 100644 --- a/examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart +++ b/examples/api/lib/widgets/shortcuts/single_activator.0.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -/// Flutter code sample for [SingleActivator.SingleActivator]. +/// Flutter code sample for [SingleActivator]. void main() => runApp(const SingleActivatorExampleApp()); diff --git a/examples/api/test/widgets/shortcuts/single_activator.0_test.dart b/examples/api/test/widgets/shortcuts/single_activator.0_test.dart new file mode 100644 index 000000000000..2be8c3212615 --- /dev/null +++ b/examples/api/test/widgets/shortcuts/single_activator.0_test.dart @@ -0,0 +1,47 @@ +// 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. + +import 'package:flutter/services.dart'; +import 'package:flutter_api_samples/widgets/shortcuts/single_activator.0.dart' + as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + Future pressControlC(WidgetTester tester) async { + await tester.sendKeyDownEvent(LogicalKeyboardKey.control); + await tester.sendKeyDownEvent(LogicalKeyboardKey.keyC); + await tester.sendKeyUpEvent(LogicalKeyboardKey.keyC); + await tester.sendKeyUpEvent(LogicalKeyboardKey.control); + } + + group('SingleActivatorExampleApp', () { + testWidgets('displays correct labels', (WidgetTester tester) async { + await tester.pumpWidget( + const example.SingleActivatorExampleApp(), + ); + + expect( + find.text('Add to the counter by pressing Ctrl+C'), + findsOneWidget, + ); + expect(find.text('count: 0'), findsOneWidget); + }); + + testWidgets( + 'updates counter when Ctrl-C combination pressed', + (WidgetTester tester) async { + await tester.pumpWidget( + const example.SingleActivatorExampleApp(), + ); + + for (int counter = 0; counter < 10; counter++) { + expect(find.text('count: $counter'), findsOneWidget); + + await pressControlC(tester); + await tester.pump(); + } + }, + ); + }); +} diff --git a/packages/flutter/lib/src/widgets/shortcuts.dart b/packages/flutter/lib/src/widgets/shortcuts.dart index fa344fbfc19b..31c93a80cda2 100644 --- a/packages/flutter/lib/src/widgets/shortcuts.dart +++ b/packages/flutter/lib/src/widgets/shortcuts.dart @@ -432,7 +432,7 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S /// In the following example, the shortcut `Control + C` increases the /// counter: /// - /// ** See code in examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart ** + /// ** See code in examples/api/lib/widgets/shortcuts/single_activator.0.dart ** /// {@end-tool} const SingleActivator( this.trigger, {