【问题标题】:Setting a Window Drag Point in Flutter在 Flutter 中设置窗口拖动点
【发布时间】:2022-11-25 05:44:30
【问题描述】:

我的 Flutter 应用程序使用了相对较新的 Windows 构建工具和社区 fluent_ui 包。

为了让我的应用程序看起来更原生,我选择使用 window_manager 包删除默认的 Windows 标题栏并实现我自己的。但是,这引入了无法通过拖动窗口顶部来移动窗口的问题。

有没有办法让小部件成为窗口拖动点以允许这样做?

【问题讨论】:

  • 你能包括你到目前为止尝试过的代码-sn-p吗?
  • @YeasinSheikh 很抱歉让您失望,但没有。我找不到关于此的任何好的文档,而且我不确定如何实施它。我能找到的最接近的是 Draggable 小部件,这不是我要找的。

标签: flutter dart fluent-ui


【解决方案1】:

我最近通过制作 DraggableAppBar 找到了解决方案。我还使用 window_manager 包将窗口控制按钮添加到应用栏。

解决方案:在脚手架中使用 DraggableAppBar 而不是 AppBar。

import 'package:flutter/material.dart';
import 'package:universal_platform/universal_platform.dart';
import 'package:window_manager/window_manager.dart';

class DraggebleAppBar extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final Brightness brightness;
  final Color backgroundColor;

  const DraggebleAppBar({
    super.key,
    required this.title,
    required this.brightness,
    required this.backgroundColor,
  });

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        getAppBarTitle(title),
        Align(
          alignment: AlignmentDirectional.centerEnd,
          child: SizedBox(
            height: kToolbarHeight,
            width: 200,
            child: WindowCaption(
              backgroundColor: backgroundColor,
              brightness: brightness,
            ),
          ),
        )
      ],
    );
  }

  Widget getAppBarTitle(String title) {
    if (UniversalPlatform.isWeb) {
      return Align(
        alignment: AlignmentDirectional.center,
        child: Text(title),
      );
    } else {
      return DragToMoveArea(
        child: SizedBox(
          height: kToolbarHeight,
          child: Align(
            alignment: AlignmentDirectional.center,
            child: Text(title),
          ),
        ),
      );
    }
  }

  @override
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多