mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Remove unused context parameter (#124254)
Tidying up the spell check API.
This commit is contained in:
parent
39becb7770
commit
9d6883135a
@ -45,7 +45,6 @@ class CupertinoSpellCheckSuggestionsToolbar extends StatelessWidget {
|
||||
/// Builds the button items for the toolbar based on the available
|
||||
/// spell check suggestions.
|
||||
static List<ContextMenuButtonItem>? buildButtonItems(
|
||||
BuildContext context,
|
||||
EditableTextState editableTextState,
|
||||
) {
|
||||
// Determine if composing region is misspelled.
|
||||
@ -58,8 +57,9 @@ class CupertinoSpellCheckSuggestionsToolbar extends StatelessWidget {
|
||||
return null;
|
||||
}
|
||||
if (spanAtCursorIndex.suggestions.isEmpty) {
|
||||
assert(debugCheckHasCupertinoLocalizations(context));
|
||||
final CupertinoLocalizations localizations = CupertinoLocalizations.of(context);
|
||||
assert(debugCheckHasCupertinoLocalizations(editableTextState.context));
|
||||
final CupertinoLocalizations localizations =
|
||||
CupertinoLocalizations.of(editableTextState.context);
|
||||
return <ContextMenuButtonItem>[
|
||||
ContextMenuButtonItem(
|
||||
onPressed: () {},
|
||||
|
||||
@ -802,7 +802,7 @@ class CupertinoTextField extends StatefulWidget {
|
||||
EditableTextState editableTextState,
|
||||
) {
|
||||
final List<ContextMenuButtonItem>? buttonItems =
|
||||
CupertinoSpellCheckSuggestionsToolbar.buildButtonItems(context, editableTextState);
|
||||
CupertinoSpellCheckSuggestionsToolbar.buildButtonItems(editableTextState);
|
||||
|
||||
if (buttonItems == null || buttonItems.isEmpty){
|
||||
return const SizedBox.shrink();
|
||||
|
||||
@ -62,7 +62,6 @@ class SpellCheckSuggestionsToolbar extends StatelessWidget {
|
||||
/// Builds the button items for the toolbar based on the available
|
||||
/// spell check suggestions.
|
||||
static List<ContextMenuButtonItem>? buildButtonItems(
|
||||
BuildContext context,
|
||||
EditableTextState editableTextState,
|
||||
) {
|
||||
// Determine if composing region is misspelled.
|
||||
|
||||
@ -816,7 +816,7 @@ class TextField extends StatefulWidget {
|
||||
final Offset anchor =
|
||||
SpellCheckSuggestionsToolbar.getToolbarAnchor(editableTextState.contextMenuAnchors);
|
||||
final List<ContextMenuButtonItem>? buttonItems =
|
||||
SpellCheckSuggestionsToolbar.buildButtonItems(context, editableTextState);
|
||||
SpellCheckSuggestionsToolbar.buildButtonItems(editableTextState);
|
||||
|
||||
if (buttonItems == null){
|
||||
return const SizedBox.shrink();
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
// 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/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
testWidgets('buildButtonItems builds a "No Replacements Found" button when no suggestions', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: _FakeEditableText(),
|
||||
),
|
||||
);
|
||||
final _FakeEditableTextState editableTextState =
|
||||
tester.state(find.byType(_FakeEditableText));
|
||||
final List<ContextMenuButtonItem>? buttonItems =
|
||||
CupertinoSpellCheckSuggestionsToolbar.buildButtonItems(editableTextState);
|
||||
|
||||
expect(buttonItems, isNotNull);
|
||||
expect(buttonItems!.length, 1);
|
||||
expect(buttonItems.first.label, 'No Replacements Found');
|
||||
});
|
||||
}
|
||||
|
||||
class _FakeEditableText extends EditableText {
|
||||
_FakeEditableText() : super(
|
||||
controller: TextEditingController(),
|
||||
focusNode: FocusNode(),
|
||||
backgroundCursorColor: CupertinoColors.white,
|
||||
cursorColor: CupertinoColors.white,
|
||||
style: const TextStyle(),
|
||||
);
|
||||
|
||||
@override
|
||||
_FakeEditableTextState createState() => _FakeEditableTextState();
|
||||
}
|
||||
|
||||
class _FakeEditableTextState extends EditableTextState {
|
||||
@override
|
||||
TextEditingValue get currentTextEditingValue => TextEditingValue.empty;
|
||||
|
||||
@override
|
||||
SuggestionSpan? findSuggestionSpanAtCursorIndex(int cursorIndex) {
|
||||
return const SuggestionSpan(
|
||||
TextRange(
|
||||
start: 0,
|
||||
end: 0,
|
||||
),
|
||||
<String>[],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart' show CupertinoTextSelectionToolbar;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
// Vertical position at which to anchor the toolbar for testing.
|
||||
@ -85,4 +86,29 @@ void main() {
|
||||
final double toolbarY = tester.getTopLeft(findSpellCheckSuggestionsToolbar()).dy;
|
||||
expect(toolbarY, equals(expectedToolbarY));
|
||||
});
|
||||
|
||||
test('buildButtonItems builds only a delete button when no suggestions', () {
|
||||
final _FakeEditableTextState editableTextState = _FakeEditableTextState();
|
||||
final List<ContextMenuButtonItem>? buttonItems =
|
||||
SpellCheckSuggestionsToolbar.buildButtonItems(editableTextState);
|
||||
|
||||
expect(buttonItems, hasLength(1));
|
||||
expect(buttonItems!.first.type, ContextMenuButtonType.delete);
|
||||
});
|
||||
}
|
||||
|
||||
class _FakeEditableTextState extends EditableTextState {
|
||||
@override
|
||||
TextEditingValue get currentTextEditingValue => TextEditingValue.empty;
|
||||
|
||||
@override
|
||||
SuggestionSpan? findSuggestionSpanAtCursorIndex(int cursorIndex) {
|
||||
return const SuggestionSpan(
|
||||
TextRange(
|
||||
start: 0,
|
||||
end: 0,
|
||||
),
|
||||
<String>[],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user