【问题标题】:gestureEvent or PointerEvent on longPressed DialogBox长按对话框上的手势事件或指针事件
【发布时间】:2022-01-05 11:37:38
【问题描述】:

如何在长按对话框上添加点击或长按(任何gestureDector事件)

显示后点击popop上的图标,我们可以在图标上滑动并获得像点击一样的动作吗?

听到我,使用“OverlyEntery”显示对话框,我使用overlyEntry,因为它会保持手势长按事件,长按显示对话框时工作正常,发生长按结束事件时消失,但问题是打开后对话框, 在对话框中我无法添加任何事件,听到我想要像 instagram 图像预览。

谢谢。

import 'package:flutter/material.dart';
class Explore extends StatelessWidget {
  Explore({Key? key}) : super(key: key);
  OverlayEntry _popUp({required String url}) {
    return OverlayEntry(
        builder: (context) => Dialog(
                child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  width: double.infinity,
                  padding: EdgeInsets.all(10.0),
                  color: Colors.black,
                  child: Center(
                      child: Text(
                    "Trip Body name",
                    style: TextStyle(color: Colors.white),
                  )),
                ),
                Image.asset(url),
                Container(
                  color: Colors.black,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      GestureDetector(
                        onLongPress: () {
                          print("press1");
                        },
                        onLongPressCancel: () {
                          print("press2");
                        },
                        onLongPressDown: (e) {
                          print("press3");
                        },
                        onLongPressMoveUpdate: (d) {
                          print("press4");
                        },
                        child: Container(
                            child: const Icon(
                          Icons.favorite,
                          color: Colors.white,
                        )),
                      ),
                      Icon(Icons.save)
                    ],
                  ),
                )
              ],
            )));
  }

  OverlayEntry? _popUpDialog;
  @override
  Widget build(BuildContext context) {
    
    return Scaffold(

        body: Stack(children: [
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: StaggeredGridView.countBuilder(
          //    controller: _scrollController,
              crossAxisCount: 2,
              itemCount: 50,
              itemBuilder: (BuildContext context, int index) => InkWell(
                onTap: () {
                 
                },
                child: GestureDetector(
                    //  behavior: HitTestBehavior.deferToChild,
                    onLongPress: () {
                   
                      _popUpDialog = _popUp(
                          url: 'assets/images/a' +
                              ((index < 15)
                                  ? index.toString()
                                  : index > 20
                                      ? '3'
                                      : (index - 10).toString()) +
                              '.jpeg');
                      Overlay.of(context)!.insert(_popUpDialog!);
                    },
                    onLongPressEnd: (d) {
                   
                      _popUpDialog!.remove();
                    },
                    child: Image.asset((
                    'assets/images/a' +
                          ((index < 15)
                              ? index.toString()
                              : index > 20
                                  ? '3'
                                  : (index - 10).toString()) +
                          '.jpeg'
                    )),
              ),
              staggeredTileBuilder: (int index) => StaggeredTile.count(
                  1, isForReel(index: index) ? 1.5 : 1), // 2,11,23,30,44
              mainAxisSpacing: 4.0,
              crossAxisSpacing: 4.0,
            ),
          ),
        
        )
        ]
        )
    );
        
  }


}

【问题讨论】:

    标签: flutter dart flutter-layout flutter-animation dart-null-safety


    【解决方案1】:

    尝试在DialogBox的body而不是SubViews上添加Gesture Detecter。

    【讨论】:

    • 不,它不起作用
    • 谁能有解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多