Update Cupertino examples and add missing tests (#103128)
This commit is contained in:
@@ -25,8 +25,10 @@ class CupertinoIndicatorExample extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoActivityIndicator Sample'),
|
||||
),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
|
||||
@@ -26,6 +26,9 @@ class CupertinoButtonExample extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoButton Sample'),
|
||||
),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
||||
@@ -5,52 +5,74 @@
|
||||
// Flutter code sample for CupertinoContextMenu
|
||||
|
||||
import 'package:flutter/cupertino.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
|
||||
Widget build(BuildContext context) {
|
||||
return const MaterialApp(
|
||||
title: _title,
|
||||
home: MyStatelessWidget(),
|
||||
return const CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: Brightness.light),
|
||||
home: ContextMenuExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({Key? key}) : super(key: key);
|
||||
class ContextMenuExample extends StatelessWidget {
|
||||
const ContextMenuExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoContextMenu Sample'),
|
||||
),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 100,
|
||||
height: 100,
|
||||
child: CupertinoContextMenu(
|
||||
actions: <Widget>[
|
||||
CupertinoContextMenuAction(
|
||||
child: const Text('Action one'),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
isDefaultAction: true,
|
||||
trailingIcon: CupertinoIcons.doc_on_clipboard_fill,
|
||||
child: const Text('Copy'),
|
||||
),
|
||||
CupertinoContextMenuAction(
|
||||
child: const Text('Action two'),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
trailingIcon: CupertinoIcons.share,
|
||||
child: const Text('Share '),
|
||||
),
|
||||
CupertinoContextMenuAction(
|
||||
onPressed: () {
|
||||
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(
|
||||
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> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoDatePicker Sample'),
|
||||
),
|
||||
child: DefaultTextStyle(
|
||||
style: TextStyle(
|
||||
color: CupertinoColors.label.resolveFrom(context),
|
||||
|
||||
@@ -55,6 +55,9 @@ class _TimerPickerExampleState extends State<TimerPickerExample> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoTimerPicker Sample'),
|
||||
),
|
||||
child: DefaultTextStyle(
|
||||
style: TextStyle(
|
||||
color: CupertinoColors.label.resolveFrom(context),
|
||||
|
||||
@@ -33,74 +33,80 @@ class _CupertinoFormRowExampleState extends State<CupertinoFormRowExample> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
child: CupertinoFormSection(
|
||||
header: const Text('Connectivity'),
|
||||
children: <Widget>[
|
||||
CupertinoFormRow(
|
||||
prefix: const PrefixWidget(
|
||||
icon: CupertinoIcons.airplane,
|
||||
title: 'Airplane Mode',
|
||||
color: CupertinoColors.systemOrange,
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoFormSection Sample'),
|
||||
),
|
||||
// Add safe area widget to place the CupertinoFormSection below the navigation bar.
|
||||
child: SafeArea(
|
||||
child: CupertinoFormSection(
|
||||
header: const Text('Connectivity'),
|
||||
children: <Widget>[
|
||||
CupertinoFormRow(
|
||||
prefix: const PrefixWidget(
|
||||
icon: CupertinoIcons.airplane,
|
||||
title: 'Airplane Mode',
|
||||
color: CupertinoColors.systemOrange,
|
||||
),
|
||||
child: CupertinoSwitch(
|
||||
value: airplaneMode,
|
||||
onChanged: (bool value) {
|
||||
setState(() {
|
||||
airplaneMode = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
child: CupertinoSwitch(
|
||||
value: airplaneMode,
|
||||
onChanged: (bool value) {
|
||||
setState(() {
|
||||
airplaneMode = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
CupertinoFormRow(
|
||||
prefix: const PrefixWidget(
|
||||
icon: CupertinoIcons.wifi,
|
||||
title: 'Wi-Fi',
|
||||
color: CupertinoColors.systemBlue,
|
||||
),
|
||||
error: const Text('Home network unavailable'),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: const <Widget>[
|
||||
Text('Not connected'),
|
||||
SizedBox(width: 5),
|
||||
Icon(CupertinoIcons.forward)
|
||||
],
|
||||
),
|
||||
),
|
||||
CupertinoFormRow(
|
||||
prefix: const PrefixWidget(
|
||||
icon: CupertinoIcons.bluetooth,
|
||||
title: 'Bluetooth',
|
||||
color: CupertinoColors.activeBlue,
|
||||
),
|
||||
helper: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
CupertinoFormRow(
|
||||
prefix: const PrefixWidget(
|
||||
icon: CupertinoIcons.wifi,
|
||||
title: 'Wi-Fi',
|
||||
color: CupertinoColors.systemBlue,
|
||||
),
|
||||
error: const Text('Home network unavailable'),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: const <Widget>[
|
||||
Text('Headphone'),
|
||||
Text('Connected'),
|
||||
Text('Not connected'),
|
||||
SizedBox(width: 5),
|
||||
Icon(CupertinoIcons.forward)
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: const <Widget>[
|
||||
Text('On'),
|
||||
SizedBox(width: 5),
|
||||
Icon(CupertinoIcons.forward)
|
||||
],
|
||||
CupertinoFormRow(
|
||||
prefix: const PrefixWidget(
|
||||
icon: CupertinoIcons.bluetooth,
|
||||
title: 'Bluetooth',
|
||||
color: CupertinoColors.activeBlue,
|
||||
),
|
||||
helper: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: const <Widget>[
|
||||
Text('Headphone'),
|
||||
Text('Connected'),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: const <Widget>[
|
||||
Text('On'),
|
||||
SizedBox(width: 5),
|
||||
Icon(CupertinoIcons.forward)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const CupertinoFormRow(
|
||||
prefix: PrefixWidget(
|
||||
icon: CupertinoIcons.bluetooth,
|
||||
title: 'Mobile Data',
|
||||
color: CupertinoColors.systemGreen,
|
||||
const CupertinoFormRow(
|
||||
prefix: PrefixWidget(
|
||||
icon: CupertinoIcons.bluetooth,
|
||||
title: 'Mobile Data',
|
||||
color: CupertinoColors.systemGreen,
|
||||
),
|
||||
child: Icon(CupertinoIcons.forward),
|
||||
),
|
||||
child: Icon(CupertinoIcons.forward),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,30 +6,28 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
void main() => runApp(const PageScaffoldApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
class PageScaffoldApp extends StatelessWidget {
|
||||
const PageScaffoldApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const CupertinoApp(
|
||||
title: _title,
|
||||
home: MyStatefulWidget(),
|
||||
theme: CupertinoThemeData(brightness: Brightness.light),
|
||||
home: PageScaffoldExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatefulWidget extends StatefulWidget {
|
||||
const MyStatefulWidget({Key? key}) : super(key: key);
|
||||
class PageScaffoldExample extends StatefulWidget {
|
||||
const PageScaffoldExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
|
||||
State<PageScaffoldExample> createState() => _PageScaffoldExampleState();
|
||||
}
|
||||
|
||||
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
|
||||
class _PageScaffoldExampleState extends State<PageScaffoldExample> {
|
||||
int _count = 0;
|
||||
|
||||
@override
|
||||
@@ -38,18 +36,24 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
|
||||
// Uncomment to change the background color
|
||||
// backgroundColor: CupertinoColors.systemPink,
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('Sample Code'),
|
||||
middle: Text('CupertinoPageScaffold Sample'),
|
||||
),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
CupertinoButton(
|
||||
onPressed: () => setState(() => _count++),
|
||||
child: const Icon(CupertinoIcons.add),
|
||||
),
|
||||
Center(
|
||||
child: Text('You have pressed the button $_count times.'),
|
||||
),
|
||||
],
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Center(
|
||||
child: Text('You have pressed the button $_count times.'),
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
Center(
|
||||
child: CupertinoButton.filled(
|
||||
onPressed: () => setState(() => _count++),
|
||||
child: const Icon(CupertinoIcons.add),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,6 +64,9 @@ class _CupertinoPickerExampleState extends State<CupertinoPickerExample> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoPicker Sample'),
|
||||
),
|
||||
child: DefaultTextStyle(
|
||||
style: TextStyle(
|
||||
color: CupertinoColors.label.resolveFrom(context),
|
||||
|
||||
@@ -6,30 +6,28 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
void main() => runApp(const RefreshControlApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
class RefreshControlApp extends StatelessWidget {
|
||||
const RefreshControlApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const CupertinoApp(
|
||||
title: _title,
|
||||
home: MyStatefulWidget(),
|
||||
theme: CupertinoThemeData(brightness: Brightness.light),
|
||||
home: RefreshControlExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatefulWidget extends StatefulWidget {
|
||||
const MyStatefulWidget({Key? key}) : super(key: key);
|
||||
class RefreshControlExample extends StatefulWidget {
|
||||
const RefreshControlExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
|
||||
State<RefreshControlExample> createState() => _RefreshControlExampleState();
|
||||
}
|
||||
|
||||
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
|
||||
class _RefreshControlExampleState extends State<RefreshControlExample> {
|
||||
List<Color> colors = <Color>[
|
||||
CupertinoColors.systemYellow,
|
||||
CupertinoColors.systemOrange,
|
||||
@@ -44,6 +42,9 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoSliverRefreshControl Sample'),
|
||||
),
|
||||
child: CustomScrollView(
|
||||
physics: const BouncingScrollPhysics(
|
||||
parent: AlwaysScrollableScrollPhysics(),
|
||||
|
||||
@@ -6,25 +6,23 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
void main() => runApp(const CupertinoDialogApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
class CupertinoDialogApp extends StatelessWidget {
|
||||
const CupertinoDialogApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: Brightness.light),
|
||||
restorationScopeId: 'app',
|
||||
title: _title,
|
||||
home: MyStatelessWidget(),
|
||||
home: CupertinoDialogExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({Key? key}) : super(key: key);
|
||||
class CupertinoDialogExample extends StatelessWidget {
|
||||
const CupertinoDialogExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -33,12 +31,13 @@ class MyStatelessWidget extends StatelessWidget {
|
||||
middle: Text('Home'),
|
||||
),
|
||||
child: Center(
|
||||
child: CupertinoButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).restorablePush(_dialogBuilder);
|
||||
},
|
||||
child: const Text('Open Dialog'),
|
||||
)),
|
||||
child: CupertinoButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).restorablePush(_dialogBuilder);
|
||||
},
|
||||
child: const Text('Open Dialog'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,12 +46,22 @@ class MyStatelessWidget extends StatelessWidget {
|
||||
return CupertinoDialogRoute<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return const CupertinoAlertDialog(
|
||||
title: Text('Title'),
|
||||
content: Text('Content'),
|
||||
return CupertinoAlertDialog(
|
||||
title: const Text('Title'),
|
||||
content: const Text('Content'),
|
||||
actions: <Widget>[
|
||||
CupertinoDialogAction(child: Text('Yes')),
|
||||
CupertinoDialogAction(child: Text('No')),
|
||||
CupertinoDialogAction(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Yes'),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('No'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
@@ -6,25 +6,23 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
void main() => runApp(const ModalPopupApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
class ModalPopupApp extends StatelessWidget {
|
||||
const ModalPopupApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: Brightness.light),
|
||||
restorationScopeId: 'app',
|
||||
title: _title,
|
||||
home: MyStatelessWidget(),
|
||||
home: ModalPopupExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({Key? key}) : super(key: key);
|
||||
class ModalPopupExample extends StatelessWidget {
|
||||
const ModalPopupExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -33,12 +31,13 @@ class MyStatelessWidget extends StatelessWidget {
|
||||
middle: Text('Home'),
|
||||
),
|
||||
child: Center(
|
||||
child: CupertinoButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).restorablePush(_modalBuilder);
|
||||
},
|
||||
child: const Text('Open Modal'),
|
||||
)),
|
||||
child: CupertinoButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).restorablePush(_modalBuilder);
|
||||
},
|
||||
child: const Text('Open Modal'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,45 +6,45 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
void main() => runApp(const ScrollbarApp());
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
class ScrollbarApp extends StatelessWidget {
|
||||
const ScrollbarApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: _title,
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text(_title)),
|
||||
body: const MyStatelessWidget(),
|
||||
),
|
||||
return const CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: Brightness.light),
|
||||
home: ScrollbarExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({Key? key}) : super(key: key);
|
||||
class ScrollbarExample extends StatelessWidget {
|
||||
const ScrollbarExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoScrollbar(
|
||||
thickness: 6.0,
|
||||
thicknessWhileDragging: 10.0,
|
||||
radius: const Radius.circular(34.0),
|
||||
radiusWhileDragging: Radius.zero,
|
||||
child: ListView.builder(
|
||||
itemCount: 120,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Center(
|
||||
child: Text('item $index'),
|
||||
);
|
||||
},
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoScrollbar Sample'),
|
||||
),
|
||||
child: CupertinoScrollbar(
|
||||
thickness: 6.0,
|
||||
thicknessWhileDragging: 10.0,
|
||||
radius: const Radius.circular(34.0),
|
||||
radiusWhileDragging: Radius.zero,
|
||||
child: ListView.builder(
|
||||
itemCount: 120,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Item $index'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,54 +6,55 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
void main() => runApp(const ScrollbarApp());
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
class ScrollbarApp extends StatelessWidget {
|
||||
const ScrollbarApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: _title,
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text(_title)),
|
||||
body: const MyStatefulWidget(),
|
||||
),
|
||||
return const CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: Brightness.light),
|
||||
home: ScrollbarExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatefulWidget extends StatefulWidget {
|
||||
const MyStatefulWidget({Key? key}) : super(key: key);
|
||||
class ScrollbarExample extends StatefulWidget {
|
||||
const ScrollbarExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
|
||||
State<ScrollbarExample> createState() => _ScrollbarExampleState();
|
||||
}
|
||||
|
||||
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
|
||||
class _ScrollbarExampleState extends State<ScrollbarExample> {
|
||||
final ScrollController _controllerOne = ScrollController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoScrollbar(
|
||||
thickness: 6.0,
|
||||
thicknessWhileDragging: 10.0,
|
||||
radius: const Radius.circular(34.0),
|
||||
radiusWhileDragging: Radius.zero,
|
||||
controller: _controllerOne,
|
||||
thumbVisibility: true,
|
||||
child: ListView.builder(
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoScrollbar Sample'),
|
||||
),
|
||||
child: CupertinoScrollbar(
|
||||
thickness: 6.0,
|
||||
thicknessWhileDragging: 10.0,
|
||||
radius: const Radius.circular(34.0),
|
||||
radiusWhileDragging: Radius.zero,
|
||||
controller: _controllerOne,
|
||||
itemCount: 120,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Center(
|
||||
child: Text('item $index'),
|
||||
);
|
||||
},
|
||||
thumbVisibility: true,
|
||||
child: ListView.builder(
|
||||
controller: _controllerOne,
|
||||
itemCount: 120,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Item $index'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ Map<Sky, Color> skyColors = <Sky, Color> {
|
||||
Sky.cerulean: const Color(0xff007ba7),
|
||||
};
|
||||
|
||||
void main() => runApp(const SegmentControlApp());
|
||||
void main() => runApp(const SegmentedControlApp());
|
||||
|
||||
class SegmentControlApp extends StatelessWidget {
|
||||
const SegmentControlApp({Key? key}) : super(key: key);
|
||||
class SegmentedControlApp extends StatelessWidget {
|
||||
const SegmentedControlApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -14,10 +14,10 @@ Map<Sky, Color> skyColors = <Sky, Color> {
|
||||
Sky.cerulean: const Color(0xff007ba7),
|
||||
};
|
||||
|
||||
void main() => runApp(const SegmentControlApp());
|
||||
void main() => runApp(const SegmentedControlApp());
|
||||
|
||||
class SegmentControlApp extends StatelessWidget {
|
||||
const SegmentControlApp({Key? key}) : super(key: key);
|
||||
class SegmentedControlApp extends StatelessWidget {
|
||||
const SegmentedControlApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -34,6 +34,9 @@ class _CupertinoSliderExampleState extends State<CupertinoSliderExample> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoSlider Sample'),
|
||||
),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
||||
@@ -45,6 +45,9 @@ class _CupertinoTextFieldExampleState extends State<CupertinoTextFieldExample> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('CupertinoTextField Sample'),
|
||||
),
|
||||
child: Center(
|
||||
child: CupertinoTextField(
|
||||
controller: _textController,
|
||||
|
||||
@@ -6,36 +6,31 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
void main() => runApp(const FormSectionApp());
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
class FormSectionApp extends StatelessWidget {
|
||||
const FormSectionApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const MaterialApp(
|
||||
title: _title,
|
||||
home: MyStatefulWidget(),
|
||||
return const CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: Brightness.light),
|
||||
home: FromSectionExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatefulWidget extends StatefulWidget {
|
||||
const MyStatefulWidget({Key? key}) : super(key: key);
|
||||
class FromSectionExample extends StatelessWidget {
|
||||
const FromSectionExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
|
||||
}
|
||||
|
||||
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
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(
|
||||
autovalidateMode: AutovalidateMode.always,
|
||||
onChanged: () {
|
||||
|
||||
@@ -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/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);
|
||||
});
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
const Offset dragUp = Offset(0.0, -150.0);
|
||||
|
||||
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(
|
||||
const example.SliverNavBarApp(),
|
||||
);
|
||||
@@ -23,7 +23,7 @@ void main() {
|
||||
expect(tester.getBottomLeft(find.text('Contacts').first).dy, 36.0);
|
||||
});
|
||||
|
||||
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(
|
||||
const example.SliverNavBarApp(),
|
||||
);
|
||||
@@ -46,7 +46,7 @@ void main() {
|
||||
expect(tester.getBottomLeft(find.text('Family').first).dy, 36.0);
|
||||
});
|
||||
|
||||
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(
|
||||
const example.SliverNavBarApp(),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
@@ -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/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));
|
||||
});
|
||||
}
|
||||
@@ -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/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);
|
||||
});
|
||||
}
|
||||
@@ -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/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);
|
||||
});
|
||||
}
|
||||
@@ -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/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);
|
||||
});
|
||||
}
|
||||
@@ -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/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';
|
||||
void main() {
|
||||
testWidgets('Can change a selected segmented control', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.SegmentControlApp(),
|
||||
const example.SegmentedControlApp(),
|
||||
);
|
||||
|
||||
expect(find.text('Selected Segment: midnight'), findsOneWidget);
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
void main() {
|
||||
testWidgets('Can change a selected segmented control', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.SegmentControlApp(),
|
||||
const example.SegmentedControlApp(),
|
||||
);
|
||||
|
||||
expect(find.text('Selected Segment: midnight'), findsOneWidget);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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> {
|
||||
///
|
||||
/// For more information about state restoration, see [RestorationManager].
|
||||
///
|
||||
/// {@tool sample}
|
||||
/// {@tool dartpad}
|
||||
/// This sample demonstrates how to create a restorable Cupertino modal route.
|
||||
/// This is accomplished by enabling state restoration by specifying
|
||||
/// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to
|
||||
@@ -1249,7 +1249,7 @@ Widget _buildCupertinoDialogTransitions(BuildContext context, Animation<double>
|
||||
///
|
||||
/// For more information about state restoration, see [RestorationManager].
|
||||
///
|
||||
/// {@tool sample}
|
||||
/// {@tool dartpad}
|
||||
/// This sample demonstrates how to create a restorable Cupertino dialog. This is
|
||||
/// accomplished by enabling state restoration by specifying
|
||||
/// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to
|
||||
|
||||
Reference in New Issue
Block a user