【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

相关推荐
程序员陆业聪1 小时前
AI编码提效实战:Skill、Rule与上下文工程
android
liulian09161 小时前
【Flutter for OpenHarmony第三方库】Flutter for OpenHarmony 音频播放功能适配与实现指南
flutter·华为·音视频·学习方法·harmonyos
程序员陆业聪2 小时前
AI驱动需求梳理与Spec编写:让PRD自动变成技术方案
android
Lanren的编程日记2 小时前
Flutter 鸿蒙应用机器学习功能集成实战:TFLite兼容框架+模拟推理引擎,打造端侧智能体验
flutter·华为·harmonyos·推荐算法
Hello__77773 小时前
开源鸿蒙 Flutter 实战|应用启动页(Splash Screen)全流程实现
flutter·开源·harmonyos
拉拉尼亚3 小时前
flutter轮播组件教程
flutter
深念Y3 小时前
大模型API缓存的底层原理:从显存到网关
缓存·ai·llm·api·硬件·显存·kvcache
李艺为3 小时前
Android Studio使用switch匹配资源id时报需要常量表达式解决办法
android
杨浦老苏4 小时前
AI使用追踪和代理网关GoModel
人工智能·docker·ai·api·群晖
Hello__77774 小时前
开源鸿蒙 Flutter 实战|用户头像编辑功能全流程实现
flutter·开源·harmonyos