CupertinoSearchTextField: Add interactive examples (#103042)

* `CupertinoSearchTextField`: Add interactive examples

* Update docs
This commit is contained in:
Taha Tesser
2022-05-05 08:58:15 +03:00
committed by GitHub
parent 666a5c9078
commit 81fd748ac2
5 changed files with 204 additions and 47 deletions

View File

@@ -0,0 +1,26 @@
// 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_api_samples/cupertino/search_field/cupertino_search_field.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoTextField has initial text', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SearchTextFieldApp(),
);
expect(find.byType(CupertinoSearchTextField), findsOneWidget);
expect(find.text('initial text'), findsOneWidget);
await tester.tap(find.byIcon(CupertinoIcons.xmark_circle_fill));
await tester.pump();
expect(find.text('initial text'), findsNothing);
await tester.enterText(find.byType(CupertinoSearchTextField), 'photos');
await tester.pump();
expect(find.text('photos'), findsOneWidget);
});
}

View File

@@ -0,0 +1,27 @@
// 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_api_samples/cupertino/search_field/cupertino_search_field.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Value changed callback updates entered text', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SearchTextFieldApp(),
);
expect(find.byType(CupertinoSearchTextField), findsOneWidget);
await tester.enterText(find.byType(CupertinoSearchTextField), 'photos');
await tester.pump();
expect(find.text('The text has changed to: photos'), findsOneWidget);
await tester.enterText(find.byType(CupertinoSearchTextField), 'photos from vacation');
await tester.showKeyboard(find.byType(CupertinoTextField));
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pump();
expect(find.text('Submitted text: photos from vacation'), findsOneWidget);
});
}