custom-dropdown icon indicating copy to clipboard operation
custom-dropdown copied to clipboard

How to remove dropdown if I click outside?

Open Donaboyev opened this issue 2 years ago • 13 comments

Donaboyev avatar Sep 24 '22 08:09 Donaboyev

yes please add this too in next update

AyushTripathi28 avatar Dec 29 '23 13:12 AyushTripathi28

Hey @Donaboyev @AyushTripathi28 Currently, this behaviour is already added. Dropdown overlay should close if you tap outside. Can you guys explain your issue more?

AbdullahChauhan avatar Dec 29 '23 13:12 AbdullahChauhan

I just noticed that after 3.0 upgrade, but only does that in certain scenarios

Screenshot 2023-12-30 at 17 27 44

karniv00l avatar Dec 30 '23 16:12 karniv00l

@karniv00l This not looks good. Can you please share the video so I can properly analyse whats happening...

AbdullahChauhan avatar Dec 30 '23 16:12 AbdullahChauhan

Also on which platform you are using dropdown?

AbdullahChauhan avatar Dec 30 '23 16:12 AbdullahChauhan

I'll try to write some example code when i have more time. Looks like it's platform independent (tested on macOS and Android). But as I mentioned, this is not present everywhere in my app, only in some parts

karniv00l avatar Dec 30 '23 19:12 karniv00l

Ok, I found the issue

I'm currently using MediaQuery trick/hack to remove unnecessary left padding from ListTile and AppBar on mobile, and appears that this was causing the issue with the drop-down. I just needed to move the MediaQuery down the tree to make it work properly. Sorry for the confusion, this library is fantastic!

karniv00l avatar Dec 31 '23 12:12 karniv00l

@karniv00l Ah, I see. No worries. Thanks for the appreciation :thumbsup:

AbdullahChauhan avatar Jan 01 '24 09:01 AbdullahChauhan

Hey @Donaboyev @AyushTripathi28 Currently, this behaviour is already added. Dropdown overlay should close if you tap outside. Can you guys explain your issue more?

const Expanded(child: DataEnvDropdown()), this is how i call this class

import 'dart:developer';

import 'package:animated_custom_dropdown/custom_dropdown.dart';
import 'package:flutter/material.dart';

const List<DataEnv> _list = [
  DataEnv('ICICI', Icons.developer_mode),
  DataEnv('MOSL', Icons.design_services),
  DataEnv('Oister', Icons.account_balance),
];

class DataEnvDropdown extends StatelessWidget {
  const DataEnvDropdown({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CustomDropdown<DataEnv>(
      expandedFillColor: Colors.black,
      closedFillColor: Colors.black,
      initialItem: _list[0],
      hintText: 'Select Warehouse',
      items: _list,
      canCloseOutsideBounds: false,
      excludeSelected: true,
      onChanged: (value) {
        log('changing value to: $value');
      },
      closedBorderRadius: const BorderRadius.all(Radius.circular(5)),
      closedSuffixIcon: const Icon(Icons.arrow_drop_down),
      expandedSuffixIcon: const Icon(Icons.arrow_drop_up),
    );
  }
}

class DataEnv with CustomDropdownListFilter {
  final String name;
  final IconData icon;
  const DataEnv(this.name, this.icon);

  @override
  String toString() {
    return name;
  }

  @override
  bool filter(String query) {
    return name.toLowerCase().contains(query.toLowerCase());
  }
}

Issue is i call it in appbar and its working corectly but i cannot able to close it by tapping outside

AyushTripathi28 avatar Jan 05 '24 14:01 AyushTripathi28

@AyushTripathi28 You are calling this widget inside AppBar widget?

AbdullahChauhan avatar Jan 05 '24 17:01 AbdullahChauhan

No not in app bar I am calling it inside body

const Expanded(child: DataEnvDropdown()),

sorry for late reply .

AyushTripathi28 avatar Jan 09 '24 10:01 AyushTripathi28

I got it actually i put canCloseOutsideBounds: false, but it should be true for this functionality.

AyushTripathi28 avatar Jan 09 '24 11:01 AyushTripathi28

Hi, what if the dropdown is inside a modal which have a scaffold, and if i press anywhere outside the scaffold, the dropdown didnt close untitled.webm

andikatp avatar Jun 24 '24 09:06 andikatp