Unverified Commit d80f3e39 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Cupertino examples improvements and clean up (#103044)

parent 27fee486
...@@ -6,42 +6,43 @@ ...@@ -6,42 +6,43 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const CupertinoTabBarApp());
class MyApp extends StatelessWidget { class CupertinoTabBarApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const CupertinoTabBarApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: MyStatefulWidget(), home: CupertinoTabBarExample(),
); );
} }
} }
class MyStatefulWidget extends StatefulWidget { class CupertinoTabBarExample extends StatelessWidget {
const MyStatefulWidget({Key? key}) : super(key: key); const CupertinoTabBarExample({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoTabScaffold( return CupertinoTabScaffold(
tabBar: CupertinoTabBar( tabBar: CupertinoTabBar(
items: const <BottomNavigationBarItem>[ items: const <BottomNavigationBarItem>[
BottomNavigationBarItem( BottomNavigationBarItem(
icon: Icon(CupertinoIcons.circle), icon: Icon(CupertinoIcons.star_fill),
label: 'Tab 1', label: 'Favourites',
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.clock_solid),
label: 'Recents',
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.person_alt_circle_fill),
label: 'Contacts',
), ),
BottomNavigationBarItem( BottomNavigationBarItem(
icon: Icon(CupertinoIcons.add), icon: Icon(CupertinoIcons.circle_grid_3x3_fill),
label: 'Tab 2', label: 'Keypad',
), ),
], ],
), ),
......
...@@ -6,28 +6,27 @@ ...@@ -6,28 +6,27 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const CupertinoButtonApp());
class MyApp extends StatelessWidget { class CupertinoButtonApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const CupertinoButtonApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: MyStatelessWidget(), home: CupertinoButtonExample(),
); );
} }
} }
class MyStatelessWidget extends StatelessWidget { class CupertinoButtonExample extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key); const CupertinoButtonExample({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Center( return CupertinoPageScaffold(
child: Center(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
...@@ -52,6 +51,7 @@ class MyStatelessWidget extends StatelessWidget { ...@@ -52,6 +51,7 @@ class MyStatelessWidget extends StatelessWidget {
), ),
], ],
), ),
),
); );
} }
} }
...@@ -6,30 +6,28 @@ ...@@ -6,30 +6,28 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const DatePickerApp());
class MyApp extends StatelessWidget { class DatePickerApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const DatePickerApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: MyStatelessWidget(), home: DatePickerExample(),
); );
} }
} }
class MyStatelessWidget extends StatefulWidget { class DatePickerExample extends StatefulWidget {
const MyStatelessWidget({Key? key}) : super(key: key); const DatePickerExample({Key? key}) : super(key: key);
@override @override
State<MyStatelessWidget> createState() => _MyStatelessWidgetState(); State<DatePickerExample> createState() => _DatePickerExampleState();
} }
class _MyStatelessWidgetState extends State<MyStatelessWidget> { class _DatePickerExampleState extends State<DatePickerExample> {
DateTime date = DateTime(2016, 10, 26); DateTime date = DateTime(2016, 10, 26);
DateTime time = DateTime(2016, 5, 10, 22, 35); DateTime time = DateTime(2016, 5, 10, 22, 35);
DateTime dateTime = DateTime(2016, 8, 3, 17, 45); DateTime dateTime = DateTime(2016, 8, 3, 17, 45);
......
...@@ -6,30 +6,28 @@ ...@@ -6,30 +6,28 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const TimerPickerApp());
class MyApp extends StatelessWidget { class TimerPickerApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const TimerPickerApp({Key? key}) : super(key: key);
static const String _title = 'CupertinoTimerPicker Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: CupertinoTimerPickerSample(), home: TimerPickerExample(),
); );
} }
} }
class CupertinoTimerPickerSample extends StatefulWidget { class TimerPickerExample extends StatefulWidget {
const CupertinoTimerPickerSample({Key? key}) : super(key: key); const TimerPickerExample({Key? key}) : super(key: key);
@override @override
State<CupertinoTimerPickerSample> createState() => _CupertinoTimerPickerSampleState(); State<TimerPickerExample> createState() => _TimerPickerExampleState();
} }
class _CupertinoTimerPickerSampleState extends State<CupertinoTimerPickerSample> { class _TimerPickerExampleState extends State<TimerPickerExample> {
Duration duration = const Duration(hours: 1, minutes: 23); Duration duration = const Duration(hours: 1, minutes: 23);
// This shows a CupertinoModalPopup with a reasonable fixed height which hosts CupertinoTimerPicker. // This shows a CupertinoModalPopup with a reasonable fixed height which hosts CupertinoTimerPicker.
......
...@@ -6,26 +6,22 @@ ...@@ -6,26 +6,22 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const ActionSheetApp());
class MyApp extends StatelessWidget { class ActionSheetApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const ActionSheetApp({Key? key}) : super(key: key);
static const String _title = 'CupertinoActionSheet Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: ActionSheetSample(title: _title), home: ActionSheetExample(),
); );
} }
} }
class ActionSheetSample extends StatelessWidget { class ActionSheetExample extends StatelessWidget {
const ActionSheetSample({Key? key, required this.title}) : super(key: key); const ActionSheetExample({Key? key}) : super(key: key);
final String title;
// This shows a CupertinoModalPopup which hosts a CupertinoActionSheet. // This shows a CupertinoModalPopup which hosts a CupertinoActionSheet.
void _showActionSheet(BuildContext context) { void _showActionSheet(BuildContext context) {
...@@ -68,8 +64,8 @@ class ActionSheetSample extends StatelessWidget { ...@@ -68,8 +64,8 @@ class ActionSheetSample extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar( navigationBar: const CupertinoNavigationBar(
middle: Text(title), middle: Text('CupertinoActionSheet Sample'),
), ),
child: Center( child: Center(
child: CupertinoButton( child: CupertinoButton(
......
...@@ -6,26 +6,22 @@ ...@@ -6,26 +6,22 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const AlertDialogApp());
class MyApp extends StatelessWidget { class AlertDialogApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const AlertDialogApp({Key? key}) : super(key: key);
static const String _title = 'CupertinoAlertDialog Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: ActionSheetSample(title: _title), home: AlertDialogExample(),
); );
} }
} }
class ActionSheetSample extends StatelessWidget { class AlertDialogExample extends StatelessWidget {
const ActionSheetSample({Key? key, required this.title}) : super(key: key); const AlertDialogExample({Key? key}) : super(key: key);
final String title;
// This shows a CupertinoModalPopup which hosts a CupertinoAlertDialog. // This shows a CupertinoModalPopup which hosts a CupertinoAlertDialog.
void _showAlertDialog(BuildContext context) { void _showAlertDialog(BuildContext context) {
...@@ -62,8 +58,8 @@ class ActionSheetSample extends StatelessWidget { ...@@ -62,8 +58,8 @@ class ActionSheetSample extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar( navigationBar: const CupertinoNavigationBar(
middle: Text(title), middle: Text('CupertinoAlertDialog Sample'),
), ),
child: Center( child: Center(
child: CupertinoButton( child: CupertinoButton(
......
...@@ -6,37 +6,35 @@ ...@@ -6,37 +6,35 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const NavBarApp());
class MyApp extends StatelessWidget { class NavBarApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const NavBarApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: MyStatefulWidget(), home: NavBarExample(),
); );
} }
} }
class MyStatefulWidget extends StatefulWidget { class NavBarExample extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key); const NavBarExample({Key? key}) : super(key: key);
@override @override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); State<NavBarExample> createState() => _NavBarExampleState();
} }
class _MyStatefulWidgetState extends State<MyStatefulWidget> { class _NavBarExampleState extends State<NavBarExample> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar( navigationBar: CupertinoNavigationBar(
// Try removing opacity to observe the lack of a blur effect and of sliding content. // Try removing opacity to observe the lack of a blur effect and of sliding content.
backgroundColor: CupertinoColors.systemGrey.withOpacity(0.5), backgroundColor: CupertinoColors.systemGrey.withOpacity(0.5),
middle: const Text('Sample Code'), middle: const Text('CupertinoNavigationBar Sample'),
), ),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
......
...@@ -6,24 +6,22 @@ ...@@ -6,24 +6,22 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const SliverNavBarApp());
class MyApp extends StatelessWidget { class SliverNavBarApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const SliverNavBarApp({Key? key}) : super(key: key);
static const String _title = 'CupertinoSliverNavigationBar Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: CupertinoNavBarSample(), home: SliverNavBarExample(),
); );
} }
} }
class CupertinoNavBarSample extends StatelessWidget { class SliverNavBarExample extends StatelessWidget {
const CupertinoNavBarSample({Key? key}) : super(key: key); const SliverNavBarExample({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -16,30 +16,27 @@ const List<String> _fruitNames = <String>[ ...@@ -16,30 +16,27 @@ const List<String> _fruitNames = <String>[
'Strawberry', 'Strawberry',
]; ];
void main() => runApp(const MyApp()); void main() => runApp(const CupertinoPickerApp());
class MyApp extends StatelessWidget { class CupertinoPickerApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const CupertinoPickerApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: CupertinoPickerSample(), home: CupertinoPickerExample(),
); );
} }
} }
class CupertinoPickerExample extends StatefulWidget {
class CupertinoPickerSample extends StatefulWidget { const CupertinoPickerExample({Key? key}) : super(key: key);
const CupertinoPickerSample({Key? key}) : super(key: key);
@override @override
State<CupertinoPickerSample> createState() => _CupertinoPickerSampleState(); State<CupertinoPickerExample> createState() => _CupertinoPickerExampleState();
} }
class _CupertinoPickerSampleState extends State<CupertinoPickerSample> { class _CupertinoPickerExampleState extends State<CupertinoPickerExample> {
int _selectedFruit = 0; int _selectedFruit = 0;
// This shows a CupertinoModalPopup with a reasonable fixed height which hosts CupertinoPicker. // This shows a CupertinoModalPopup with a reasonable fixed height which hosts CupertinoPicker.
......
...@@ -14,30 +14,28 @@ Map<Sky, Color> skyColors = <Sky, Color> { ...@@ -14,30 +14,28 @@ Map<Sky, Color> skyColors = <Sky, Color> {
Sky.cerulean: const Color(0xff007ba7), Sky.cerulean: const Color(0xff007ba7),
}; };
void main() => runApp(const MyApp()); void main() => runApp(const SegmentControlApp());
class MyApp extends StatelessWidget { class SegmentControlApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const SegmentControlApp({Key? key}) : super(key: key);
static const String _title = 'CupertinoSegmentedControl Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: SegmentedControlSample(), home: SegmentedControlExample(),
); );
} }
} }
class SegmentedControlSample extends StatefulWidget { class SegmentedControlExample extends StatefulWidget {
const SegmentedControlSample({Key? key}) : super(key: key); const SegmentedControlExample({Key? key}) : super(key: key);
@override @override
State<SegmentedControlSample> createState() => _SegmentedControlSampleState(); State<SegmentedControlExample> createState() => _SegmentedControlExampleState();
} }
class _SegmentedControlSampleState extends State<SegmentedControlSample> { class _SegmentedControlExampleState extends State<SegmentedControlExample> {
Sky _selectedSegment = Sky.midnight; Sky _selectedSegment = Sky.midnight;
@override @override
...@@ -61,24 +59,15 @@ class _SegmentedControlSampleState extends State<SegmentedControlSample> { ...@@ -61,24 +59,15 @@ class _SegmentedControlSampleState extends State<SegmentedControlSample> {
children: const <Sky, Widget>{ children: const <Sky, Widget>{
Sky.midnight: Padding( Sky.midnight: Padding(
padding: EdgeInsets.symmetric(horizontal: 20), padding: EdgeInsets.symmetric(horizontal: 20),
child: Text( child: Text('Midnight'),
'Midnight',
style: TextStyle(color: CupertinoColors.white),
),
), ),
Sky.viridian: Padding( Sky.viridian: Padding(
padding: EdgeInsets.symmetric(horizontal: 20), padding: EdgeInsets.symmetric(horizontal: 20),
child: Text( child: Text('Viridian'),
'Viridian',
style: TextStyle(color: CupertinoColors.white),
),
), ),
Sky.cerulean: Padding( Sky.cerulean: Padding(
padding: EdgeInsets.symmetric(horizontal: 20), padding: EdgeInsets.symmetric(horizontal: 20),
child: Text( child: Text('Cerulean'),
'Cerulean',
style: TextStyle(color: CupertinoColors.white),
),
), ),
}, },
), ),
......
...@@ -14,30 +14,28 @@ Map<Sky, Color> skyColors = <Sky, Color> { ...@@ -14,30 +14,28 @@ Map<Sky, Color> skyColors = <Sky, Color> {
Sky.cerulean: const Color(0xff007ba7), Sky.cerulean: const Color(0xff007ba7),
}; };
void main() => runApp(const MyApp()); void main() => runApp(const SegmentControlApp());
class MyApp extends StatelessWidget { class SegmentControlApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const SegmentControlApp({Key? key}) : super(key: key);
static const String _title = 'CupertinoSlidingSegmentedControl Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: SegmentedControlSample(), home: SegmentedControlExample(),
); );
} }
} }
class SegmentedControlSample extends StatefulWidget { class SegmentedControlExample extends StatefulWidget {
const SegmentedControlSample({Key? key}) : super(key: key); const SegmentedControlExample({Key? key}) : super(key: key);
@override @override
State<SegmentedControlSample> createState() => _SegmentedControlSampleState(); State<SegmentedControlExample> createState() => _SegmentedControlExampleState();
} }
class _SegmentedControlSampleState extends State<SegmentedControlSample> { class _SegmentedControlExampleState extends State<SegmentedControlExample> {
Sky _selectedSegment = Sky.midnight; Sky _selectedSegment = Sky.midnight;
@override @override
......
...@@ -6,30 +6,28 @@ ...@@ -6,30 +6,28 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const CupertinoSliderApp());
class MyApp extends StatelessWidget { class CupertinoSliderApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const CupertinoSliderApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: CupertinoSliderSample(), home: CupertinoSliderExample(),
); );
} }
} }
class CupertinoSliderSample extends StatefulWidget { class CupertinoSliderExample extends StatefulWidget {
const CupertinoSliderSample({Key? key}) : super(key: key); const CupertinoSliderExample({Key? key}) : super(key: key);
@override @override
State<CupertinoSliderSample> createState() => _CupertinoSliderSampleState(); State<CupertinoSliderExample> createState() => _CupertinoSliderExampleState();
} }
class _CupertinoSliderSampleState extends State<CupertinoSliderSample> { class _CupertinoSliderExampleState extends State<CupertinoSliderExample> {
double _currentSliderValue = 0.0; double _currentSliderValue = 0.0;
String? _sliderStatus; String? _sliderStatus;
......
...@@ -6,30 +6,28 @@ ...@@ -6,30 +6,28 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const CupertinoTextFieldApp());
class MyApp extends StatelessWidget { class CupertinoTextFieldApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const CupertinoTextFieldApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const CupertinoApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: MyStatefulWidget(), home: CupertinoTextFieldExample(),
); );
} }
} }
class MyStatefulWidget extends StatefulWidget { class CupertinoTextFieldExample extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key); const CupertinoTextFieldExample({Key? key}) : super(key: key);
@override @override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); State<CupertinoTextFieldExample> createState() => _CupertinoTextFieldExampleState();
} }
class _MyStatefulWidgetState extends State<MyStatefulWidget> { class _CupertinoTextFieldExampleState extends State<CupertinoTextFieldExample> {
late TextEditingController _textController; late TextEditingController _textController;
@override @override
......
// 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/bottom_tab_bar/cupertino_tab_bar.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can switch between tabs', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoTabBarApp(),
);
expect(find.byType(CupertinoTabBar), findsOneWidget);
expect(find.text('Content of tab 0'), findsOneWidget);
await tester.tap(find.text('Contacts'));
await tester.pump();
expect(find.text('Content of tab 2'), findsOneWidget);
});
}
...@@ -9,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -9,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Has 4 CupertinoButton variants', (WidgetTester tester) async { testWidgets('Has 4 CupertinoButton variants', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.CupertinoButtonApp(),
); );
expect(find.byType(CupertinoButton), findsNWidgets(4)); expect(find.byType(CupertinoButton), findsNWidgets(4));
......
...@@ -10,7 +10,7 @@ const Offset _kRowOffset = Offset(0.0, -50.0); ...@@ -10,7 +10,7 @@ const Offset _kRowOffset = Offset(0.0, -50.0);
void main() { void main() {
testWidgets('Can change date, time and dateTime using CupertinoDatePicker', (WidgetTester tester) async { testWidgets('Can change date, time and dateTime using CupertinoDatePicker', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.DatePickerApp(),
); );
// Open the date picker. // Open the date picker.
await tester.tap(find.text('10-26-2016')); await tester.tap(find.text('10-26-2016'));
......
...@@ -10,7 +10,7 @@ const Offset _kRowOffset = Offset(0.0, -50.0); ...@@ -10,7 +10,7 @@ const Offset _kRowOffset = Offset(0.0, -50.0);
void main() { void main() {
testWidgets('Can pick a duration from CupertinoTimerPicker', (WidgetTester tester) async { testWidgets('Can pick a duration from CupertinoTimerPicker', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.TimerPickerApp(),
); );
// Launch the timer picker. // Launch the timer picker.
......
...@@ -10,7 +10,7 @@ void main() { ...@@ -10,7 +10,7 @@ void main() {
testWidgets('Perform an action on CupertinoActionSheet', (WidgetTester tester) async { testWidgets('Perform an action on CupertinoActionSheet', (WidgetTester tester) async {
const String actionText = 'Destructive Action'; const String actionText = 'Destructive Action';
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.ActionSheetApp(),
); );
// Launch the CupertinoActionSheet. // Launch the CupertinoActionSheet.
......
...@@ -10,7 +10,7 @@ void main() { ...@@ -10,7 +10,7 @@ void main() {
testWidgets('Perform an action on CupertinoAlertDialog', (WidgetTester tester) async { testWidgets('Perform an action on CupertinoAlertDialog', (WidgetTester tester) async {
const String actionText = 'Yes'; const String actionText = 'Yes';
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.AlertDialogApp(),
); );
// Launch the CupertinoAlertDialog. // Launch the CupertinoAlertDialog.
......
// 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/nav_bar/cupertino_navigation_bar.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoNavigationBar is semi transparent', (WidgetTester tester) async {
await tester.pumpWidget(
const example.NavBarApp(),
);
final Finder navBarFinder = find.byType(CupertinoNavigationBar);
expect(navBarFinder, findsOneWidget);
final CupertinoNavigationBar cupertinoNavigationBar = tester.widget<CupertinoNavigationBar>(navBarFinder);
expect(cupertinoNavigationBar.backgroundColor, CupertinoColors.systemGrey.withOpacity(0.5));
});
}
...@@ -11,7 +11,7 @@ const Offset dragUp = Offset(0.0, -150.0); ...@@ -11,7 +11,7 @@ const Offset dragUp = Offset(0.0, -150.0);
void main() { void main() {
testWidgets('Collapse and expand CupertinoSliverNavigationBar changes title position', (WidgetTester tester) async { testWidgets('Collapse and expand CupertinoSliverNavigationBar changes title position', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.SliverNavBarApp(),
); );
// Large title is visible and at lower position. // Large title is visible and at lower position.
...@@ -25,7 +25,7 @@ void main() { ...@@ -25,7 +25,7 @@ void main() {
testWidgets('Middle widget is visible in both collapsed and expanded states', (WidgetTester tester) async { testWidgets('Middle widget is visible in both collapsed and expanded states', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.SliverNavBarApp(),
); );
// Navigate to a page that has both middle and large titles. // Navigate to a page that has both middle and large titles.
...@@ -48,7 +48,7 @@ void main() { ...@@ -48,7 +48,7 @@ void main() {
testWidgets('CupertinoSliverNavigationBar with previous route has back button', (WidgetTester tester) async { testWidgets('CupertinoSliverNavigationBar with previous route has back button', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.SliverNavBarApp(),
); );
// Navigate to a page that has back button // Navigate to a page that has back button
......
...@@ -10,7 +10,7 @@ const Offset _kRowOffset = Offset(0.0, -50.0); ...@@ -10,7 +10,7 @@ const Offset _kRowOffset = Offset(0.0, -50.0);
void main() { void main() {
testWidgets('Change selected fruit using CupertinoPicker', (WidgetTester tester) async { testWidgets('Change selected fruit using CupertinoPicker', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.CupertinoPickerApp(),
); );
// Open the Cupertino picker. // Open the Cupertino picker.
......
...@@ -8,12 +8,14 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -8,12 +8,14 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Can change a selected segmented control', (WidgetTester tester) async { testWidgets('Can change a selected segmented control', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.SegmentControlApp(),
); );
expect(find.text('Selected Segment: midnight'), findsOneWidget); expect(find.text('Selected Segment: midnight'), findsOneWidget);
await tester.tap(find.text('Cerulean')); await tester.tap(find.text('Cerulean'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('Selected Segment: cerulean'), findsOneWidget); expect(find.text('Selected Segment: cerulean'), findsOneWidget);
}); });
} }
...@@ -8,7 +8,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Can change a selected segmented control', (WidgetTester tester) async { testWidgets('Can change a selected segmented control', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.SegmentControlApp(),
); );
expect(find.text('Selected Segment: midnight'), findsOneWidget); expect(find.text('Selected Segment: midnight'), findsOneWidget);
......
...@@ -16,7 +16,7 @@ void main() { ...@@ -16,7 +16,7 @@ void main() {
testWidgets('Can change value using CupertinoSlider', (WidgetTester tester) async { testWidgets('Can change value using CupertinoSlider', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.CupertinoSliderApp(),
); );
// Check for the initial slider value. // Check for the initial slider value.
......
...@@ -2,15 +2,22 @@ ...@@ -2,15 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/text_field/cupertino_text_field.0.dart' as example; import 'package:flutter_api_samples/cupertino/text_field/cupertino_text_field.0.dart' as example;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('CupertinoTextField has initial text', (WidgetTester tester) async { testWidgets('CupertinoTextField has initial text', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const example.MyApp(), const example.CupertinoTextFieldApp(),
); );
expect(find.byType(CupertinoTextField), findsOneWidget);
expect(find.text('initial text'), findsOneWidget); expect(find.text('initial text'), findsOneWidget);
await tester.enterText(find.byType(CupertinoTextField), 'new text');
await tester.pump();
expect(find.text('new text'), findsOneWidget);
}); });
} }
...@@ -48,7 +48,7 @@ const Color _kDefaultTabBarInactiveColor = CupertinoColors.inactiveGray; ...@@ -48,7 +48,7 @@ const Color _kDefaultTabBarInactiveColor = CupertinoColors.inactiveGray;
/// {@tool dartpad} /// {@tool dartpad}
/// This example shows a [CupertinoTabBar] placed in a [CupertinoTabScaffold]. /// This example shows a [CupertinoTabBar] placed in a [CupertinoTabScaffold].
/// ///
/// ** See code in examples/api/lib/cupertino/bottom_tab_bar/bottom_tab_bar.0.dart ** /// ** See code in examples/api/lib/cupertino/bottom_tab_bar/cupertino_tab_bar.0.dart **
/// {@end-tool} /// {@end-tool}
/// ///
/// See also: /// See also:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment