系统相关
锁定固定方向
dart
// 在main.dart中
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([
// 这里只添加允许的方向
DeviceOrientation.portraitUp, // 顶部朝上
DeviceOrientation.portraitDown, // 顶部朝下
DeviceOrientation.landscapeLeft, // 左侧朝上
DeviceOrientation.landscapeRight // 右侧朝上
]);安卓设备UI模式
dart
// 在主函数指向的Widget中:
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
// 这里设置UI模式为没有空隙,即可以在导航条或者“刘海”后面添加内容
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
// 其它内容
}
}WARNING
不要让UI的内容位于安全区之外,详细见长度参数
macOS系统菜单
菜单模板
WARNING
系统按钮如果要适配语言,需要在Xcode中设置语言,简体中文语言见页尾
dart
return Platform.isMacOS ? PlatformMenuBar(
menus: [
PlatformMenu(
label: "App 名称",
menus: [
PlatformMenuItemGroup(
members: [
PlatformMenuItem(
label: "关于 App",
onSelected: (){
// 显示关于
}
)
]
),
PlatformMenuItemGroup(
members: [
PlatformMenuItem(
label: "设置",
shortcut: const SingleActivator(
LogicalKeyboardKey.comma,
meta: true,
),
onSelected: (){
// 前往设置
}
),
]
),
const PlatformMenuItemGroup(
members: [
PlatformProvidedMenuItem(
enabled: true,
type: PlatformProvidedMenuItemType.hide,
),
PlatformProvidedMenuItem(
enabled: true,
type: PlatformProvidedMenuItemType.quit,
),
]
),
]
),
PlatformMenu(
label: "编辑",
menus: [
PlatformMenuItem(
label: "拷贝",
onSelected: (){
final focusedContext = FocusManager.instance.primaryFocus?.context;
if (focusedContext != null) {
Actions.invoke(focusedContext, CopySelectionTextIntent.copy);
}
}
),
PlatformMenuItem(
label: "粘贴",
onSelected: (){
final focusedContext = FocusManager.instance.primaryFocus?.context;
if (focusedContext != null) {
Actions.invoke(focusedContext, const PasteTextIntent(SelectionChangedCause.keyboard));
}
},
),
PlatformMenuItem(
label: "全选",
onSelected: (){
final focusedContext = FocusManager.instance.primaryFocus?.context;
if (focusedContext != null) {
Actions.invoke(focusedContext, const SelectAllTextIntent(SelectionChangedCause.keyboard));
}
}
)
]
),
const PlatformMenu(
label: "窗口",
menus: [
PlatformMenuItemGroup(
members: [
PlatformProvidedMenuItem(
enabled: true,
type: PlatformProvidedMenuItemType.minimizeWindow,
),
PlatformProvidedMenuItem(
enabled: true,
type: PlatformProvidedMenuItemType.toggleFullScreen,
)
]
)
]
)
]
) : Container()语言文件,这个文件位于zh-Hans.lproj/MainMenu.strings
Details
strings
/* Class = "NSMenuItem"; title = "APP_NAME"; ObjectID = "1Xt-HY-uBw"; */
"1Xt-HY-uBw.title" = "APP_NAME";
/* Class = "NSMenu"; title = "Find"; ObjectID = "1b7-l0-nxx"; */
"1b7-l0-nxx.title" = "查找";
/* Class = "NSMenuItem"; title = "Transformations"; ObjectID = "2oI-Rn-ZJC"; */
"2oI-Rn-ZJC.title" = "转换";
/* Class = "NSMenu"; title = "Spelling"; ObjectID = "3IN-sU-3Bg"; */
"3IN-sU-3Bg.title" = "拼写";
/* Class = "NSMenu"; title = "Speech"; ObjectID = "3rS-ZA-NoH"; */
"3rS-ZA-NoH.title" = "听写";
/* Class = "NSMenuItem"; title = "Find"; ObjectID = "4EN-yA-p0u"; */
"4EN-yA-p0u.title" = "查找";
/* Class = "NSMenuItem"; title = "Enter Full Screen"; ObjectID = "4J7-dP-txa"; */
"4J7-dP-txa.title" = "进入全屏幕";
/* Class = "NSMenuItem"; title = "Quit APP_NAME"; ObjectID = "4sb-4s-VLi"; */
"4sb-4s-VLi.title" = "退出 APP_NAME";
/* Class = "NSMenuItem"; title = "Edit"; ObjectID = "5QF-Oa-p0T"; */
"5QF-Oa-p0T.title" = "编辑";
/* Class = "NSMenuItem"; title = "About APP_NAME"; ObjectID = "5kV-Vb-QxS"; */
"5kV-Vb-QxS.title" = "关于 APP_NAME";
/* Class = "NSMenuItem"; title = "Redo"; ObjectID = "6dh-zS-Vam"; */
"6dh-zS-Vam.title" = "恢复";
/* Class = "NSMenuItem"; title = "Correct Spelling Automatically"; ObjectID = "78Y-hA-62v"; */
"78Y-hA-62v.title" = "自动纠正拼写";
/* Class = "NSMenuItem"; title = "Substitutions"; ObjectID = "9ic-FL-obx"; */
"9ic-FL-obx.title" = "替换";
/* Class = "NSMenuItem"; title = "Smart Copy/Paste"; ObjectID = "9yt-4B-nSM"; */
"9yt-4B-nSM.title" = "智能复制/粘贴";
/* Class = "NSMenu"; title = "Main Menu"; ObjectID = "AYu-sK-qS6"; */
"AYu-sK-qS6.title" = "Main Menu";
/* Class = "NSMenuItem"; title = "Preferences…"; ObjectID = "BOF-NM-1cW"; */
"BOF-NM-1cW.title" = "偏好设置…";
/* Class = "NSMenuItem"; title = "Spelling and Grammar"; ObjectID = "Dv1-io-Yv7"; */
"Dv1-io-Yv7.title" = "拼写和语法";
/* Class = "NSMenuItem"; title = "Help"; ObjectID = "EPT-qC-fAb"; */
"EPT-qC-fAb.title" = "帮助";
/* Class = "NSMenu"; title = "Substitutions"; ObjectID = "FeM-D8-WVr"; */
"FeM-D8-WVr.title" = "替换";
/* Class = "NSMenuItem"; title = "View"; ObjectID = "H8h-7b-M4v"; */
"H8h-7b-M4v.title" = "视图";
/* Class = "NSMenuItem"; title = "Text Replacement"; ObjectID = "HFQ-gK-NFA"; */
"HFQ-gK-NFA.title" = "文本替换";
/* Class = "NSMenuItem"; title = "Show Spelling and Grammar"; ObjectID = "HFo-cy-zxI"; */
"HFo-cy-zxI.title" = "显示拼写和语法";
/* Class = "NSMenu"; title = "View"; ObjectID = "HyV-fh-RgO"; */
"HyV-fh-RgO.title" = "视图";
/* Class = "NSMenuItem"; title = "Show All"; ObjectID = "Kd2-mp-pUS"; */
"Kd2-mp-pUS.title" = "显示全部";
/* Class = "NSMenuItem"; title = "Bring All to Front"; ObjectID = "LE2-aR-0XJ"; */
"LE2-aR-0XJ.title" = "全部置于顶层";
/* Class = "NSMenuItem"; title = "Services"; ObjectID = "NMo-om-nkz"; */
"NMo-om-nkz.title" = "服务";
/* Class = "NSMenuItem"; title = "Minimize"; ObjectID = "OY7-WF-poV"; */
"OY7-WF-poV.title" = "最小化";
/* Class = "NSMenuItem"; title = "Hide APP_NAME"; ObjectID = "Olw-nP-bQN"; */
"Olw-nP-bQN.title" = "隐藏 APP_NAME";
/* Class = "NSMenuItem"; title = "Find Previous"; ObjectID = "OwM-mh-QMV"; */
"OwM-mh-QMV.title" = "查找上一个";
/* Class = "NSMenuItem"; title = "Stop Speaking"; ObjectID = "Oyz-dy-DGm"; */
"Oyz-dy-DGm.title" = "停止朗读";
/* Class = "NSWindow"; title = "APP_NAME"; ObjectID = "QvC-M9-y7g"; */
"QvC-M9-y7g.title" = "APP_NAME";
/* Class = "NSMenuItem"; title = "Zoom"; ObjectID = "R4o-n2-Eq4"; */
"R4o-n2-Eq4.title" = "缩放";
/* Class = "NSMenuItem"; title = "Select All"; ObjectID = "Ruw-6m-B2m"; */
"Ruw-6m-B2m.title" = "选择全部";
/* Class = "NSMenuItem"; title = "Jump to Selection"; ObjectID = "S0p-oC-mLd"; */
"S0p-oC-mLd.title" = "跳转到选择内容";
/* Class = "NSMenu"; title = "Window"; ObjectID = "Td7-aD-5lo"; */
"Td7-aD-5lo.title" = "窗口";
/* Class = "NSMenuItem"; title = "Capitalize"; ObjectID = "UEZ-Bs-lqG"; */
"UEZ-Bs-lqG.title" = "大写";
/* Class = "NSMenuItem"; title = "Hide Others"; ObjectID = "Vdr-fp-XzO"; */
"Vdr-fp-XzO.title" = "隐藏其它窗口";
/* Class = "NSMenu"; title = "Edit"; ObjectID = "W48-6f-4Dl"; */
"W48-6f-4Dl.title" = "编辑";
/* Class = "NSMenuItem"; title = "Paste and Match Style"; ObjectID = "WeT-3V-zwk"; */
"WeT-3V-zwk.title" = "粘贴并匹配样式";
/* Class = "NSMenuItem"; title = "Find…"; ObjectID = "Xz5-n4-O0W"; */
"Xz5-n4-O0W.title" = "查找…";
/* Class = "NSMenuItem"; title = "Find and Replace…"; ObjectID = "YEy-JH-Tfz"; */
"YEy-JH-Tfz.title" = "查找并替换…";
/* Class = "NSMenuItem"; title = "Start Speaking"; ObjectID = "Ynk-f8-cLZ"; */
"Ynk-f8-cLZ.title" = "开始朗读";
/* Class = "NSMenuItem"; title = "Window"; ObjectID = "aUF-d1-5bR"; */
"aUF-d1-5bR.title" = "窗口";
/* Class = "NSMenuItem"; title = "Use Selection for Find"; ObjectID = "buJ-ug-pKt"; */
"buJ-ug-pKt.title" = "使用选择内容来查找";
/* Class = "NSMenu"; title = "Transformations"; ObjectID = "c8a-y6-VQd"; */
"c8a-y6-VQd.title" = "转换";
/* Class = "NSMenuItem"; title = "Smart Links"; ObjectID = "cwL-P1-jid"; */
"cwL-P1-jid.title" = "智能链接";
/* Class = "NSMenuItem"; title = "Make Lower Case"; ObjectID = "d9M-CD-aMd"; */
"d9M-CD-aMd.title" = "转换为小写";
/* Class = "NSMenuItem"; title = "Undo"; ObjectID = "dRJ-4n-Yzg"; */
"dRJ-4n-Yzg.title" = "撤销";
/* Class = "NSMenuItem"; title = "Paste"; ObjectID = "gVA-U4-sdL"; */
"gVA-U4-sdL.title" = "粘贴";
/* Class = "NSMenuItem"; title = "Smart Quotes"; ObjectID = "hQb-2v-fYv"; */
"hQb-2v-fYv.title" = "智能引用";
/* Class = "NSMenuItem"; title = "Check Document Now"; ObjectID = "hz2-CU-CR7"; */
"hz2-CU-CR7.title" = "立即检查文件";
/* Class = "NSMenu"; title = "Services"; ObjectID = "hz9-B4-Xy5"; */
"hz9-B4-Xy5.title" = "服务";
/* Class = "NSMenuItem"; title = "Check Grammar With Spelling"; ObjectID = "mK6-2p-4JG"; */
"mK6-2p-4JG.title" = "检查语法和拼写";
/* Class = "NSMenuItem"; title = "Delete"; ObjectID = "pa3-QI-u2k"; */
"pa3-QI-u2k.title" = "删除";
/* Class = "NSMenuItem"; title = "Find Next"; ObjectID = "q09-fT-Sye"; */
"q09-fT-Sye.title" = "查找下一个";
/* Class = "NSMenu"; title = "Help"; ObjectID = "rJ0-wn-3NY"; */
"rJ0-wn-3NY.title" = "帮助";
/* Class = "NSMenuItem"; title = "Check Spelling While Typing"; ObjectID = "rbD-Rh-wIN"; */
"rbD-Rh-wIN.title" = "在输入的时候检查拼写";
/* Class = "NSMenuItem"; title = "Smart Dashes"; ObjectID = "rgM-f4-ycn"; */
"rgM-f4-ycn.title" = "智能破折号";
/* Class = "NSMenuItem"; title = "Data Detectors"; ObjectID = "tRr-pd-1PS"; */
"tRr-pd-1PS.title" = "数据检查";
/* Class = "NSMenu"; title = "APP_NAME"; ObjectID = "uQy-DD-JDr"; */
"uQy-DD-JDr.title" = "APP_NAME";
/* Class = "NSMenuItem"; title = "Cut"; ObjectID = "uRl-iY-unG"; */
"uRl-iY-unG.title" = "剪切";
/* Class = "NSMenuItem"; title = "Make Upper Case"; ObjectID = "vmV-6d-7jI"; */
"vmV-6d-7jI.title" = "转换为大写";
/* Class = "NSMenuItem"; title = "Copy"; ObjectID = "x3v-GG-iWU"; */
"x3v-GG-iWU.title" = "复制";
/* Class = "NSMenuItem"; title = "Speech"; ObjectID = "xrE-MZ-jX0"; */
"xrE-MZ-jX0.title" = "朗读";
/* Class = "NSMenuItem"; title = "Show Substitutions"; ObjectID = "z6F-FW-3nz"; */
"z6F-FW-3nz.title" = "显示替换";