编辑:我尝试将 包装Container在Material小部件中并将颜色属性移动到Material小部件,但我将一堆ResourceCards水平放置ListView,,因此小部件中的颜色Material似乎只填充ResourceCard.
我ResourceCard在 Flutter 中创建了自己的小部件。我用 a 包裹它来GestureDetector检测点击,但我想显示某种反馈或效果来通知用户它被点击了。GestureDetector我决定用小部件替换InkWell,但我没有通过容器的线性渐变和颜色看到飞溅效果,所以我只是将其恢复为GestureDetector. 我看过其他具有潜在解决方法的帖子,但它们都不能使用线性渐变和颜色。其中一个ResourceCard小部件如下所示: https: //i.stack.imgur.com/N2txv.jpg。这是小部件的代码:
class ResourceCard extends StatelessWidget {
ResourceCard({
@required this.colour,
@required this.margin,
@required this.cardText,
this.onPress,
@required this.cardCaption,
@required this.paddingText,
});
final Color colour;
final String cardText;
final Function onPress;
final EdgeInsets margin;
final String cardCaption;
final EdgeInsets paddingText;
@override
Widget build(BuildContext context) {
return GestureDetector( …Run Code Online (Sandbox Code Playgroud) 我正在尝试按照本教程创建仅出现在 MacOS Big Sur 菜单栏(右上角)中的应用程序:https : //medium.com/@acwrightdesign/creating-a-macos-menu-bar-application -using-swiftui-54572a5d5f87/。它在 Xcode 11 和 MacOS Catalina 上工作,因为有一个 AppDelegate.swift 文件,但我听说这被这个方法取代:
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,本教程的前几步要求我对(现在不存在的) AppDelegate.swift 文件进行一些更改。我已经尝试在 MyApp.swift 中进行这些更改,但我似乎无法让它工作。有没有人愿意帮我改编 MacOS Big Sur/Xcode 12 的教程?
注意:以下是 AppDelegate.swift 文件根据教程的外观(如果它存在)(如果您出于任何原因不想打开教程):
import Cocoa
import SwiftUI
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var popover: NSPopover!
var statusBarItem: NSStatusItem!
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Create the SwiftUI view that provides the window contents.
let contentView …Run Code Online (Sandbox Code Playgroud) 我正在 SwiftUI 中为 macOS 菜单/状态栏制作一个应用程序,单击该应用程序时,会打开一个NSPopover. 该应用程序以(Big Sur 中的新功能)为中心TextEditor,但这TextEditor似乎并没有响应用于复制、粘贴和剪切的典型 Cmd + C/V/X 键盘快捷键。我知道TextEditors确实支持这些快捷方式,因为如果我在 XCode 中启动一个新项目并且不将其放入NSPopover(例如,我只是将其放入常规 Mac 应用程序中),它就可以工作。复制/粘贴/剪切选项仍然出现在右键菜单中,但我不确定为什么我不能使用键盘快捷键在NSPopover.
我相信这与以下事实有关:当您单击打开弹出窗口时,macOS 不会“聚焦”该应用程序。通常,当您打开应用程序时,您会在 Mac 菜单栏的左上角(Apple 徽标旁边)看到应用程序名称和相关菜单选项。我的应用程序不这样做(大概是因为它是一个弹出窗口)。
这是相关代码:
ContentView.swift 中的文本编辑器:
TextEditor(text: $userData.note)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(10)
.font(.body)
.background(Color(red: 30 / 255, green: 30 / 255, blue: 30 / 255))
Run Code Online (Sandbox Code Playgroud)
NotedApp.swift 中的 NSPopover 逻辑:
@main
struct MenuBarPopoverApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
Settings{
EmptyView()
}
}
}
class AppDelegate: …Run Code Online (Sandbox Code Playgroud)