如何让MacOS应用程序完全透明,而其中的flutter widget完全可见?

问题描述 投票:0回答:1

我确实有一个基本的 Flutter 应用程序,并且希望为 macOS 容器应用程序实现以下目标:

  • 使 macOS 容器应用程序 100% 透明,不透明度为 0。
  • 使 macOS 容器应用程序中的 Flutter 小部件100%不透明具有白色背景。

我们的想法是拥有一个 macOS 绘图应用程序,它仅充当完全透明的容器,没有标题或边框,同时完全透视和点击。 flutter 应用程序的侧面将有一个小菜单,可以在桌面上的任何位置绘制。

以下代码有效,除了macOS 应用程序使 flutter 小部件也透明。

// appDelegate.swift

import Cocoa
import FlutterMacOS

@NSApplicationMain
class AppDelegate: FlutterAppDelegate {
  override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
    return true
  }
}
// MainFlutterWindow.swift
import Cocoa
import FlutterMacOS

class MainFlutterWindow: NSWindow {

  override func awakeFromNib() {
    let flutterViewController = FlutterViewController.init()
    let windowFrame = self.frame
    self.contentViewController = flutterViewController
    self.setFrame(windowFrame, display: true)

    RegisterGeneratedPlugins(registry: flutterViewController)

    super.awakeFromNib()
    // make the window transparent
    isOpaque = false
    backgroundColor = NSColor.clear
    
  }
}

```dart
// main.dart

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.transparent,
        body: Center(
          child: Text(
            'Hello, World!',
            style: TextStyle(fontSize: 24, color: Colors.white),
          ),
        ),
      ),
    );
  }
}
swift flutter macos dart transparency
1个回答
0
投票

如果您使用https://pub.dev/packages/flutter_amic

,它就可以工作

并设置:

@override
  void initState() {
    Window.setEffect(effect: WindowEffect.transparent);
    Window.makeWindowFullyTransparent();
    Window.enableFullSizeContentView();
    Window.exitFullscreen();
    // Window.hideWindowControls();


    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: CustomPaint(
        painter: DrawPainter(),
        child: Container(
        ),
      ),
    );
  }
© www.soinside.com 2019 - 2024. All rights reserved.