影片中使用Hello World 進行改編
導入Cupertino包
import 'package: flutter/cupertino.dart';
將Hello World 改為 按鈕Tap Me,並使用注目顏色
class Homepage extends StatelessWidget (
const Homepage();
@override
Widget build(BuildContext context) (
return CupertinoPageScaffold(
child: Center(
child: CupertinoButton(
child: Text('Tap Me!'),
color: CupertinoColors.activeOrange,
onPressed: (){},
), // CupertinoButton
), // Center
); // CupertinopageScaffold
編寫onPressed處理程序,並彈出Cupertino警告對話框
onPressed: () {
showDesertAlertDialog(context);
void showDesertAlertoialog(BuildContextcontext){
showCupertinoDialog(
context: context,
builder: (BuildContext context) = CupertinoAlertialog
title: const Text ('Like Desserts?'),
actions: [
CupertinoDialogAction(
child: const Text ('Nope"),
isDestructiveAction: true,
onPressed: () {
Navigator.pop(context):
},
),
CupertinoDialogAction(
child: const Text ('Absolutely!'),
isDefauttAction: true,
onPressed: () {
Navigator. pop(context);
},
),
],
),
);
}
}
三個文字框(Midnight , Viridian , Cerulean)
class HomePage extends Statelesswidget {
const HomePage ();
final Map<int, Widget> children = const <int, Widget>{
0: Text('Midnight'),
1: Text('viridian'),
2: Text ('Cerulean'),
};
@override
Widget build(Buildcontext context) {
return CupertinoPageScaffold(
child: Center(
child: SizedBox(
width: 375,
child: CupertinoSegmentedControl<int>(
children: children,
groupValue: 0,
onValueChanged: (int newvalue) {},
).// CupertinoSwitch
).// Center
).
);// CupertinoPageScaffold
}
}