【Flutter&Dart】 拖动改变 widget 的窗口尺寸大小GestureDetector~简单实现(10 /100)

上效果

预期的是通过拖动一条边界线改变窗口大小,类似vscode里拖动效果。这个是简单的拖动实现

上代码:

dart 复制代码
import 'package:flutter/material.dart';

class MyDraggableViewDemo extends StatelessWidget {
  const MyDraggableViewDemo({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('MyDraggableViewDemo'),
        ),
        body: DraggableDemo(),
      ),
    );
  }
}

class DraggableDemo extends StatefulWidget {
  const DraggableDemo({super.key});

  @override
  State<StatefulWidget> createState() {
    return _DraggableDemoState();
  }
}

class _DraggableDemoState extends State<DraggableDemo> {
  double width = 200.0;
  double height = 200.0;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: GestureDetector(
        onPanUpdate: (details) {
          setState(() {
            width = width + details.delta.dx;
            height = height + details.delta.dy;
          });
        },
        child: Container(
          width: width,
          height: height,
          
          color: Colors.blue,
          child: Center(
            child: Text(
              '点击 拖动后改变窗口大小',
              style: TextStyle(color: Colors.white),
            ),
          ),
        ),
      ),
    );
  }
}

所以预期的边界线效果,应该是对边界线进行处理,然后和关联的 widget 进行联动,

下一篇见

======End

相关推荐
黄昏晓x6 分钟前
C++----异常
android·java·c++
aningxiaoxixi14 分钟前
Android Audio 广播之 ACTION_AUDIO_BECOMING_NOISY
android·java·python
2501_9219308315 分钟前
进阶实战 Flutter for OpenHarmony:Transform 变换矩阵系统 - 高级视觉效果实现
flutter
2501_9219308330 分钟前
进阶实战 Flutter for OpenHarmony:自定义仪表盘系统 - 高级数据可视化实现
flutter·信息可视化
2601_9495936531 分钟前
进阶实战 Flutter for OpenHarmony:InheritedWidget 组件实战 - 跨组件数据
flutter
阿林来了32 分钟前
Flutter三方库适配OpenHarmony【flutter_speech】— 持续语音识别与长录音
flutter·语音识别·harmonyos
lili-felicity1 小时前
进阶实战 Flutter for OpenHarmony:mobile_device_identifier 第三方库实战 - 设备标识
flutter
松叶似针2 小时前
Flutter三方库适配OpenHarmony【secure_application】— 与 HarmonyOS 安全能力的深度集成
安全·flutter·harmonyos
Chengbei112 小时前
内网渗透过程中搜寻指定文件内容Everything小工具
android·安全·网络安全·系统安全·密码学·网络攻击模型·安全架构
coding者在努力2 小时前
LangChain之Prompt核心组件.2026年新版讲解,超详细
android·langchain·prompt