Update CupertinoPicker example (#118248)

* Update `CupertinoPicker` example

* format lines

* Revert making variable public

* revert variable change
This commit is contained in:
Taha Tesser
2023-01-10 21:49:22 +02:00
committed by GitHub
parent 1d2e62b764
commit 3d3f8e85a6
2 changed files with 23 additions and 10 deletions

View File

@@ -2,6 +2,7 @@
// 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/picker/cupertino_picker.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
@@ -14,12 +15,15 @@ void main() {
);
// Open the Cupertino picker.
await tester.tap(find.text('Apple'));
await tester.tap(find.widgetWithText(CupertinoButton, 'Apple'));
await tester.pumpAndSettle();
// Test the initial item.
CupertinoPicker picker = tester.widget<CupertinoPicker>(find.byType(CupertinoPicker));
expect(picker.scrollController!.initialItem, 0);
// Drag the wheel to change fruit selection.
await tester.drag(find.text('Mango'), _kRowOffset, touchSlopY: 0, warnIfMissed: false); // see top of file
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
@@ -27,6 +31,13 @@ void main() {
await tester.tapAt(const Offset(1.0, 1.0));
await tester.pumpAndSettle();
expect(find.text('Banana'), findsOneWidget);
expect(find.widgetWithText(CupertinoButton, 'Banana'), findsOneWidget);
// Test if the initial item has updated.
await tester.tap(find.widgetWithText(CupertinoButton, 'Banana'));
await tester.pumpAndSettle();
picker = tester.widget<CupertinoPicker>(find.byType(CupertinoPicker));
expect(picker.scrollController!.initialItem, 2);
});
}