Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clickMaskDismiss设置失效的问题 #159

Closed
LiJiyaoisrunning opened this issue Nov 2, 2023 · 2 comments
Closed

clickMaskDismiss设置失效的问题 #159

LiJiyaoisrunning opened this issue Nov 2, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@LiJiyaoisrunning
Copy link

LiJiyaoisrunning commented Nov 2, 2023

版本信息

  • Flutter版本: 3.10.6
  • flutter_smart_dialog版本:4.9.5

描述bug/需求

同时弹出多个弹窗时,先弹出的弹窗没有将clickMaskDismiss设为false,后弹出的弹窗将clickMaskDismiss设为false,这时点击mask区域还是会关闭将clickMaskDismiss设为false的弹窗

问题demo

import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
      navigatorObservers: [FlutterSmartDialog.observer],
      builder: FlutterSmartDialog.init(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  void _incrementCounter() async {
    showA();
    await Future.delayed(Duration(milliseconds: 500));
    showB();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  void showA() {
    SmartDialog.show(
      builder: (context) {
        return Container(
          height: 100,
          width: 100,
          margin: EdgeInsets.all(16),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(16),
            color: Colors.white,
          ),
        );
      },
    );
  }

  void showB() {
    SmartDialog.show(
      maskColor: Colors.transparent,
      backDismiss: false,
      clickMaskDismiss: false,
      usePenetrate: true,
      alignment: Alignment.topCenter,
      builder: (context) {
        return Container(
          height: 50,
          width: 300,
          margin: EdgeInsets.all(16),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(16),
            color: Colors.white,
          ),
        );
      },
    );
  }

}
@LiJiyaoisrunning
Copy link
Author

我翻了下源码,发现在mask回掉的dismiss流程中,执行_getDialog方法时只过滤了backDismiss为false的情况,没有过滤clickMaskDismiss的情况

static DialogInfo? _getDialog({
    DialogType type = DialogType.dialog,
    String? tag,
    bool force = false,
    CloseType closeType = CloseType.normal,
  }) {
    var proxy = DialogProxy.instance;
    if (proxy.dialogQueue.isEmpty) return null;

    DialogInfo? info;
    var dialogQueue = proxy.dialogQueue;
    var list = dialogQueue.toList();

    //handle dialog with tag
    if (tag != null) {
      for (var i = dialogQueue.length - 1; i >= 0; i--) {
        if (dialogQueue.isEmpty) break;
        if (list[i].tag == tag) info = list[i];
      }
      return info;
    }

    //handle permanent dialog
    if (force) {
      for (var i = dialogQueue.length - 1; i >= 0; i--) {
        if (dialogQueue.isEmpty) break;
        if (list[i].permanent) return list[i];
      }
    }

    //handle normal dialog
    for (var i = dialogQueue.length - 1; i >= 0; i--) {
      if (dialogQueue.isEmpty) break;
      var item = list[i];
      if (!item.dialog.mainDialog.visible && !item.useSystem) {
        continue;
      }
      if (type == DialogType.dialog || item.type == type) {
        info = item;
        break;
      }
    }

    //handle prohibiting back event
    if (info != null && (!info.backDismiss && closeType == CloseType.back)) {
      return null;
    }

    return info;
  }

@xdd666t xdd666t self-assigned this Nov 2, 2023
@xdd666t xdd666t added the bug Something isn't working label Nov 2, 2023
xdd666t added a commit that referenced this issue Nov 3, 2023
@xdd666t
Copy link
Member

xdd666t commented Nov 3, 2023

  • 解决了,试下新版本吧
dependencies:
  flutter_smart_dialog: ^4.9.5+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants