Unverified Commit 803f9959 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Update Cupertino examples and add missing tests (#103128)

parent b05b44e8
...@@ -25,8 +25,10 @@ class CupertinoIndicatorExample extends StatelessWidget { ...@@ -25,8 +25,10 @@ class CupertinoIndicatorExample extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoActivityIndicator Sample'),
),
child: Center( child: Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
......
...@@ -26,6 +26,9 @@ class CupertinoButtonExample extends StatelessWidget { ...@@ -26,6 +26,9 @@ class CupertinoButtonExample extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoButton Sample'),
),
child: Center( child: Center(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
......
...@@ -5,52 +5,74 @@ ...@@ -5,52 +5,74 @@
// Flutter code sample for CupertinoContextMenu // Flutter code sample for CupertinoContextMenu
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() => runApp(const MyApp()); void main() => runApp(const ContextMenuApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample'; class ContextMenuApp extends StatelessWidget {
const ContextMenuApp({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const MaterialApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: MyStatelessWidget(), home: ContextMenuExample(),
); );
} }
} }
class MyStatelessWidget extends StatelessWidget { class ContextMenuExample extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key); const ContextMenuExample({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return CupertinoPageScaffold(
body: Center( navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoContextMenu Sample'),
),
child: Center(
child: SizedBox( child: SizedBox(
width: 100, width: 100,
height: 100, height: 100,
child: CupertinoContextMenu( child: CupertinoContextMenu(
actions: <Widget>[ actions: <Widget>[
CupertinoContextMenuAction( CupertinoContextMenuAction(
child: const Text('Action one'),
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
}, },
isDefaultAction: true,
trailingIcon: CupertinoIcons.doc_on_clipboard_fill,
child: const Text('Copy'),
),
CupertinoContextMenuAction(
onPressed: () {
Navigator.pop(context);
},
trailingIcon: CupertinoIcons.share,
child: const Text('Share '),
), ),
CupertinoContextMenuAction( CupertinoContextMenuAction(
child: const Text('Action two'),
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
}, },
trailingIcon: CupertinoIcons.heart,
child: const Text('Favorite'),
),
CupertinoContextMenuAction(
onPressed: () {
Navigator.pop(context);
},
isDestructiveAction: true,
trailingIcon: CupertinoIcons.delete,
child: const Text('Delete'),
), ),
], ],
child: Container( child: Container(
color: Colors.red, decoration: BoxDecoration(
color: CupertinoColors.systemYellow,
borderRadius: BorderRadius.circular(20.0),
),
child: const FlutterLogo(size: 500.0),
), ),
), ),
), ),
......
...@@ -57,6 +57,9 @@ class _DatePickerExampleState extends State<DatePickerExample> { ...@@ -57,6 +57,9 @@ class _DatePickerExampleState extends State<DatePickerExample> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoDatePicker Sample'),
),
child: DefaultTextStyle( child: DefaultTextStyle(
style: TextStyle( style: TextStyle(
color: CupertinoColors.label.resolveFrom(context), color: CupertinoColors.label.resolveFrom(context),
......
...@@ -55,6 +55,9 @@ class _TimerPickerExampleState extends State<TimerPickerExample> { ...@@ -55,6 +55,9 @@ class _TimerPickerExampleState extends State<TimerPickerExample> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoTimerPicker Sample'),
),
child: DefaultTextStyle( child: DefaultTextStyle(
style: TextStyle( style: TextStyle(
color: CupertinoColors.label.resolveFrom(context), color: CupertinoColors.label.resolveFrom(context),
......
...@@ -33,6 +33,11 @@ class _CupertinoFormRowExampleState extends State<CupertinoFormRowExample> { ...@@ -33,6 +33,11 @@ class _CupertinoFormRowExampleState extends State<CupertinoFormRowExample> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoFormSection Sample'),
),
// Add safe area widget to place the CupertinoFormSection below the navigation bar.
child: SafeArea(
child: CupertinoFormSection( child: CupertinoFormSection(
header: const Text('Connectivity'), header: const Text('Connectivity'),
children: <Widget>[ children: <Widget>[
...@@ -102,6 +107,7 @@ class _CupertinoFormRowExampleState extends State<CupertinoFormRowExample> { ...@@ -102,6 +107,7 @@ class _CupertinoFormRowExampleState extends State<CupertinoFormRowExample> {
), ),
], ],
), ),
),
); );
} }
} }
......
...@@ -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 PageScaffoldApp());
class MyApp extends StatelessWidget { class PageScaffoldApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const PageScaffoldApp({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: PageScaffoldExample(),
); );
} }
} }
class MyStatefulWidget extends StatefulWidget { class PageScaffoldExample extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key); const PageScaffoldExample({Key? key}) : super(key: key);
@override @override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); State<PageScaffoldExample> createState() => _PageScaffoldExampleState();
} }
class _MyStatefulWidgetState extends State<MyStatefulWidget> { class _PageScaffoldExampleState extends State<PageScaffoldExample> {
int _count = 0; int _count = 0;
@override @override
...@@ -38,19 +36,25 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> { ...@@ -38,19 +36,25 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
// Uncomment to change the background color // Uncomment to change the background color
// backgroundColor: CupertinoColors.systemPink, // backgroundColor: CupertinoColors.systemPink,
navigationBar: const CupertinoNavigationBar( navigationBar: const CupertinoNavigationBar(
middle: Text('Sample Code'), middle: Text('CupertinoPageScaffold Sample'),
), ),
child: ListView( child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
CupertinoButton( Center(
child: Text('You have pressed the button $_count times.'),
),
const SizedBox(height: 20.0),
Center(
child: CupertinoButton.filled(
onPressed: () => setState(() => _count++), onPressed: () => setState(() => _count++),
child: const Icon(CupertinoIcons.add), child: const Icon(CupertinoIcons.add),
), ),
Center(
child: Text('You have pressed the button $_count times.'),
), ),
], ],
), ),
),
); );
} }
} }
...@@ -64,6 +64,9 @@ class _CupertinoPickerExampleState extends State<CupertinoPickerExample> { ...@@ -64,6 +64,9 @@ class _CupertinoPickerExampleState extends State<CupertinoPickerExample> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoPicker Sample'),
),
child: DefaultTextStyle( child: DefaultTextStyle(
style: TextStyle( style: TextStyle(
color: CupertinoColors.label.resolveFrom(context), color: CupertinoColors.label.resolveFrom(context),
......
...@@ -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 RefreshControlApp());
class MyApp extends StatelessWidget { class RefreshControlApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const RefreshControlApp({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: RefreshControlExample(),
); );
} }
} }
class MyStatefulWidget extends StatefulWidget { class RefreshControlExample extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key); const RefreshControlExample({Key? key}) : super(key: key);
@override @override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); State<RefreshControlExample> createState() => _RefreshControlExampleState();
} }
class _MyStatefulWidgetState extends State<MyStatefulWidget> { class _RefreshControlExampleState extends State<RefreshControlExample> {
List<Color> colors = <Color>[ List<Color> colors = <Color>[
CupertinoColors.systemYellow, CupertinoColors.systemYellow,
CupertinoColors.systemOrange, CupertinoColors.systemOrange,
...@@ -44,6 +42,9 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> { ...@@ -44,6 +42,9 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoSliverRefreshControl Sample'),
),
child: CustomScrollView( child: CustomScrollView(
physics: const BouncingScrollPhysics( physics: const BouncingScrollPhysics(
parent: AlwaysScrollableScrollPhysics(), parent: AlwaysScrollableScrollPhysics(),
......
...@@ -6,25 +6,23 @@ ...@@ -6,25 +6,23 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const CupertinoDialogApp());
class MyApp extends StatelessWidget { class CupertinoDialogApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const CupertinoDialogApp({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(
theme: CupertinoThemeData(brightness: Brightness.light),
restorationScopeId: 'app', restorationScopeId: 'app',
title: _title, home: CupertinoDialogExample(),
home: MyStatelessWidget(),
); );
} }
} }
class MyStatelessWidget extends StatelessWidget { class CupertinoDialogExample extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key); const CupertinoDialogExample({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -38,7 +36,8 @@ class MyStatelessWidget extends StatelessWidget { ...@@ -38,7 +36,8 @@ class MyStatelessWidget extends StatelessWidget {
Navigator.of(context).restorablePush(_dialogBuilder); Navigator.of(context).restorablePush(_dialogBuilder);
}, },
child: const Text('Open Dialog'), child: const Text('Open Dialog'),
)), ),
),
); );
} }
...@@ -47,12 +46,22 @@ class MyStatelessWidget extends StatelessWidget { ...@@ -47,12 +46,22 @@ class MyStatelessWidget extends StatelessWidget {
return CupertinoDialogRoute<void>( return CupertinoDialogRoute<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return const CupertinoAlertDialog( return CupertinoAlertDialog(
title: Text('Title'), title: const Text('Title'),
content: Text('Content'), content: const Text('Content'),
actions: <Widget>[ actions: <Widget>[
CupertinoDialogAction(child: Text('Yes')), CupertinoDialogAction(
CupertinoDialogAction(child: Text('No')), onPressed: () {
Navigator.pop(context);
},
child: const Text('Yes'),
),
CupertinoDialogAction(
onPressed: () {
Navigator.pop(context);
},
child: const Text('No'),
),
], ],
); );
}, },
......
...@@ -6,25 +6,23 @@ ...@@ -6,25 +6,23 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp()); void main() => runApp(const ModalPopupApp());
class MyApp extends StatelessWidget { class ModalPopupApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const ModalPopupApp({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(
theme: CupertinoThemeData(brightness: Brightness.light),
restorationScopeId: 'app', restorationScopeId: 'app',
title: _title, home: ModalPopupExample(),
home: MyStatelessWidget(),
); );
} }
} }
class MyStatelessWidget extends StatelessWidget { class ModalPopupExample extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key); const ModalPopupExample({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -38,7 +36,8 @@ class MyStatelessWidget extends StatelessWidget { ...@@ -38,7 +36,8 @@ class MyStatelessWidget extends StatelessWidget {
Navigator.of(context).restorablePush(_modalBuilder); Navigator.of(context).restorablePush(_modalBuilder);
}, },
child: const Text('Open Modal'), child: const Text('Open Modal'),
)), ),
),
); );
} }
......
...@@ -6,34 +6,30 @@ ...@@ -6,34 +6,30 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; void main() => runApp(const ScrollbarApp());
void main() => runApp(const MyApp()); class ScrollbarApp extends StatelessWidget {
const ScrollbarApp({Key? key}) : super(key: key);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: Scaffold( home: ScrollbarExample(),
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
),
); );
} }
} }
class MyStatelessWidget extends StatelessWidget { class ScrollbarExample extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key); const ScrollbarExample({Key? key}) : super(key: key);
@override
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoScrollbar( return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoScrollbar Sample'),
),
child: CupertinoScrollbar(
thickness: 6.0, thickness: 6.0,
thicknessWhileDragging: 10.0, thicknessWhileDragging: 10.0,
radius: const Radius.circular(34.0), radius: const Radius.circular(34.0),
...@@ -42,10 +38,14 @@ class MyStatelessWidget extends StatelessWidget { ...@@ -42,10 +38,14 @@ class MyStatelessWidget extends StatelessWidget {
itemCount: 120, itemCount: 120,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return Center( return Center(
child: Text('item $index'), child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Item $index'),
),
); );
}, },
), ),
),
); );
} }
} }
...@@ -6,40 +6,37 @@ ...@@ -6,40 +6,37 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; void main() => runApp(const ScrollbarApp());
void main() => runApp(const MyApp()); class ScrollbarApp extends StatelessWidget {
const ScrollbarApp({Key? key}) : super(key: key);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: Scaffold( home: ScrollbarExample(),
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
),
); );
} }
} }
class MyStatefulWidget extends StatefulWidget { class ScrollbarExample extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key); const ScrollbarExample({Key? key}) : super(key: key);
@override @override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); State<ScrollbarExample> createState() => _ScrollbarExampleState();
} }
class _MyStatefulWidgetState extends State<MyStatefulWidget> { class _ScrollbarExampleState extends State<ScrollbarExample> {
final ScrollController _controllerOne = ScrollController(); final ScrollController _controllerOne = ScrollController();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoScrollbar( return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoScrollbar Sample'),
),
child: CupertinoScrollbar(
thickness: 6.0, thickness: 6.0,
thicknessWhileDragging: 10.0, thicknessWhileDragging: 10.0,
radius: const Radius.circular(34.0), radius: const Radius.circular(34.0),
...@@ -51,10 +48,14 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> { ...@@ -51,10 +48,14 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
itemCount: 120, itemCount: 120,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return Center( return Center(
child: Text('item $index'), child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Item $index'),
),
); );
}, },
), ),
),
); );
} }
} }
...@@ -14,10 +14,10 @@ Map<Sky, Color> skyColors = <Sky, Color> { ...@@ -14,10 +14,10 @@ Map<Sky, Color> skyColors = <Sky, Color> {
Sky.cerulean: const Color(0xff007ba7), Sky.cerulean: const Color(0xff007ba7),
}; };
void main() => runApp(const SegmentControlApp()); void main() => runApp(const SegmentedControlApp());
class SegmentControlApp extends StatelessWidget { class SegmentedControlApp extends StatelessWidget {
const SegmentControlApp({Key? key}) : super(key: key); const SegmentedControlApp({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -14,10 +14,10 @@ Map<Sky, Color> skyColors = <Sky, Color> { ...@@ -14,10 +14,10 @@ Map<Sky, Color> skyColors = <Sky, Color> {
Sky.cerulean: const Color(0xff007ba7), Sky.cerulean: const Color(0xff007ba7),
}; };
void main() => runApp(const SegmentControlApp()); void main() => runApp(const SegmentedControlApp());
class SegmentControlApp extends StatelessWidget { class SegmentedControlApp extends StatelessWidget {
const SegmentControlApp({Key? key}) : super(key: key); const SegmentedControlApp({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -34,6 +34,9 @@ class _CupertinoSliderExampleState extends State<CupertinoSliderExample> { ...@@ -34,6 +34,9 @@ class _CupertinoSliderExampleState extends State<CupertinoSliderExample> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoSlider Sample'),
),
child: Center( child: Center(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
......
...@@ -45,6 +45,9 @@ class _CupertinoTextFieldExampleState extends State<CupertinoTextFieldExample> { ...@@ -45,6 +45,9 @@ class _CupertinoTextFieldExampleState extends State<CupertinoTextFieldExample> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoTextField Sample'),
),
child: Center( child: Center(
child: CupertinoTextField( child: CupertinoTextField(
controller: _textController, controller: _textController,
......
...@@ -6,36 +6,31 @@ ...@@ -6,36 +6,31 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; void main() => runApp(const FormSectionApp());
void main() => runApp(const MyApp()); class FormSectionApp extends StatelessWidget {
const FormSectionApp({Key? key}) : super(key: key);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const MaterialApp( return const CupertinoApp(
title: _title, theme: CupertinoThemeData(brightness: Brightness.light),
home: MyStatefulWidget(), home: FromSectionExample(),
); );
} }
} }
class MyStatefulWidget extends StatefulWidget { class FromSectionExample extends StatelessWidget {
const MyStatefulWidget({Key? key}) : super(key: key); const FromSectionExample({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 CupertinoPageScaffold( return CupertinoPageScaffold(
child: Center( navigationBar: const CupertinoNavigationBar(
middle: Text('CupertinoFormSection Sample'),
),
// Add safe area widget to place the CupertinoFormSection below the navigation bar.
child: SafeArea(
child: Form( child: Form(
autovalidateMode: AutovalidateMode.always, autovalidateMode: AutovalidateMode.always,
onChanged: () { onChanged: () {
......
// 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/material.dart';
import 'package:flutter_api_samples/cupertino/context_menu/cupertino_context_menu.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can open cupertino context menu', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ContextMenuApp(),
);
final Offset logo = tester.getCenter(find.byType(FlutterLogo));
expect(find.text('Favorite'), findsNothing);
await tester.startGesture(logo);
await tester.pumpAndSettle();
expect(find.text('Favorite'), findsOneWidget);
await tester.tap(find.text('Favorite'));
await tester.pumpAndSettle();
expect(find.text('Favorite'), findsNothing);
});
}
// 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/page_scaffold/cupertino_page_scaffold.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can increment counter', (WidgetTester tester) async {
await tester.pumpWidget(
const example.PageScaffoldApp(),
);
expect(find.byType(CupertinoPageScaffold), findsOneWidget);
expect(find.text('You have pressed the button 0 times.'), findsOneWidget);
await tester.tap(find.byType(CupertinoButton));
await tester.pumpAndSettle();
expect(find.text('You have pressed the button 1 times.'), findsOneWidget);
});
}
// 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/refresh/cupertino_sliver_refresh_control.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can pull down to reveal CupertinoSliverRefreshControl', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RefreshControlApp(),
);
expect(find.byType(CupertinoSliverRefreshControl), findsNothing);
expect(find.byType(Container), findsNWidgets(3));
final Finder firstItem = find.byType(Container).first;
await tester.drag(firstItem, const Offset(0.0, 150.0), touchSlopY: 0);
await tester.pump();
expect(find.byType(CupertinoSliverRefreshControl), findsOneWidget);
await tester.pumpAndSettle();
expect(find.byType(CupertinoSliverRefreshControl), findsNothing);
expect(find.byType(Container), findsNWidgets(4));
});
}
// 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/route/show_cupertino_dialog.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Tap on button displays cupertino dialog', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoDialogApp(),
);
final Finder dialogTitle = find.text('Title');
expect(dialogTitle, findsNothing);
await tester.tap(find.byType(CupertinoButton));
await tester.pumpAndSettle();
expect(dialogTitle, findsOneWidget);
await tester.tap(find.text('Yes'));
await tester.pumpAndSettle();
expect(dialogTitle, findsNothing);
});
}
// 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/route/show_cupertino_modal_popup.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Tap on button displays cupertino modal dialog', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ModalPopupApp(),
);
final Finder actionOne = find.text('Action One');
expect(actionOne, findsNothing);
await tester.tap(find.byType(CupertinoButton));
await tester.pumpAndSettle();
expect(actionOne, findsOneWidget);
await tester.tap(find.text('Action One'));
await tester.pumpAndSettle();
expect(actionOne, findsNothing);
});
}
// 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/scrollbar/cupertino_scrollbar.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('List view displays CupertinoScrollbar', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ScrollbarApp(),
);
expect(find.text('Item 0'), findsOneWidget);
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(ListView)));
await gesture.moveBy(const Offset(0.0, -100.0));
await tester.pumpAndSettle();
expect(find.text('Item 0'), findsNothing);
final Finder scrollbar = find.byType(CupertinoScrollbar);
expect(scrollbar, findsOneWidget);
expect(tester.getTopLeft(scrollbar).dy, 0.0);
expect(tester.getBottomLeft(scrollbar).dy, 600.0);
});
}
// 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/scrollbar/cupertino_scrollbar.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('List view displays CupertinoScrollbar', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ScrollbarApp(),
);
expect(find.text('Item 0'), findsOneWidget);
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(ListView)));
await gesture.moveBy(const Offset(0.0, -100.0));
await tester.pumpAndSettle();
expect(find.text('Item 0'), findsNothing);
final Finder scrollbar = find.byType(CupertinoScrollbar);
expect(scrollbar, findsOneWidget);
expect(tester.getTopLeft(scrollbar).dy, 0.0);
expect(tester.getBottomLeft(scrollbar).dy, 600.0);
});
}
...@@ -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.SegmentControlApp(), const example.SegmentedControlApp(),
); );
expect(find.text('Selected Segment: midnight'), findsOneWidget); expect(find.text('Selected Segment: midnight'), 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.SegmentControlApp(), const example.SegmentedControlApp(),
); );
expect(find.text('Selected Segment: midnight'), findsOneWidget); expect(find.text('Selected Segment: midnight'), findsOneWidget);
......
// 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/text_form_field_row/cupertino_text_form_field_row.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can enter text in CupertinoTextFormFieldRow', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FormSectionApp(),
);
expect(find.byType(CupertinoFormSection), findsOneWidget);
expect(find.byType(CupertinoTextFormFieldRow), findsNWidgets(5));
expect(find.widgetWithText(CupertinoTextFormFieldRow, 'abcd'), findsNothing);
await tester.enterText(find.byType(CupertinoTextFormFieldRow).first, 'abcd');
await tester.pump();
expect(find.widgetWithText(CupertinoTextFormFieldRow, 'abcd'), findsOneWidget);
});
}
...@@ -1143,7 +1143,7 @@ class CupertinoModalPopupRoute<T> extends PopupRoute<T> { ...@@ -1143,7 +1143,7 @@ class CupertinoModalPopupRoute<T> extends PopupRoute<T> {
/// ///
/// For more information about state restoration, see [RestorationManager]. /// For more information about state restoration, see [RestorationManager].
/// ///
/// {@tool sample} /// {@tool dartpad}
/// This sample demonstrates how to create a restorable Cupertino modal route. /// This sample demonstrates how to create a restorable Cupertino modal route.
/// This is accomplished by enabling state restoration by specifying /// This is accomplished by enabling state restoration by specifying
/// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to /// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to
...@@ -1249,7 +1249,7 @@ Widget _buildCupertinoDialogTransitions(BuildContext context, Animation<double> ...@@ -1249,7 +1249,7 @@ Widget _buildCupertinoDialogTransitions(BuildContext context, Animation<double>
/// ///
/// For more information about state restoration, see [RestorationManager]. /// For more information about state restoration, see [RestorationManager].
/// ///
/// {@tool sample} /// {@tool dartpad}
/// This sample demonstrates how to create a restorable Cupertino dialog. This is /// This sample demonstrates how to create a restorable Cupertino dialog. This is
/// accomplished by enabling state restoration by specifying /// accomplished by enabling state restoration by specifying
/// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to /// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to
......
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