Flutter中的Cupertino庫提供了一些widget,可以幫助開發者構建外觀和感覺原生的iOS應用。下面是一些使用Cupertino庫的方法:
import 'package:flutter/cupertino.dart';
void main() {
runApp(CupertinoApp(
home: MyApp(),
));
}
import 'package:flutter/cupertino.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('My App'),
),
child: Center(
child: Text('Hello, World!'),
),
);
}
}
import 'package:flutter/cupertino.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('My App'),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CupertinoButton(
child: Text('Button'),
onPressed: () {},
),
CupertinoTextField(
placeholder: 'Enter text',
),
CupertinoActivityIndicator(),
],
),
),
);
}
}
import 'package:flutter/cupertino.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('My App'),
),
child: Center(
child: CupertinoButton(
child: Text('Show Alert'),
onPressed: () {
showCupertinoDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text('Alert'),
content: Text('This is an alert dialog.'),
actions: [
CupertinoDialogAction(
child: Text('OK'),
onPressed: () {
Navigator.pop(context);
},
),
],
);
},
);
},
),
),
);
}
}
這些是使用Cupertino庫構建外觀和感覺原生的iOS應用的一些常見方法。開發者可以根據自己的需求選擇合適的widget和樣式來創建iOS風格的界面。