A custom is strong dropdown menu for Flutter

Overview

gzx_dropdown_menu

Pub Package GitHub Stars GitHub Forks GitHub Issues GitHub License

这是一个Flutter自定义功能强大的轻量级下拉筛选菜单Package,它支持iOS和Android。


  • 🙀 开源不易,麻烦给个Star ⭐️ 吧!我会根据大家的关注度和个人时间持续更新代码!
  • 🙀 如你想接收更新消息,你可以Watch下,有问题请提到Issues。

导航

功能介绍

A custom is strong dropdown menu for Flutter. Easy to use and powerful for customization, it's up to you what you want to display in the dropdown menu!

  • Custom dropdown header
  • Custom dropdown header item
  • Custom dropdown menu
  • Custom dropdown menu animation
  • Control dropdown menu show or hide

查看版本更新记录

待办事项

  • 由于GZXDropDownMenu只能在Stack内使用,扩展性还不够强
  • 支持CustomScrollView和NestedScrollView
  • ..........

Gif效果图

效果图展示了仿美团和淘宝的下拉筛选菜单。

  • 美团的代码就在这个仓库的example目录下
  • 淘宝的代码在Flutter 淘宝

如何使用

目前已发布到Pub,你可以在Pub官网查看最新的版本和更新说明!去Pub官网查看

1、添加gzx_dropdown_menu package

打开pubspec.yaml文件 添加如下代码

  gzx_dropdown_menu: ^3.1.0

添加后打开Terminal,执行flutter packages get

2、使用

  • 强烈建议你先clone下本仓库
  • 然后运行下看下效果
  • 打开本仓库example项目下的gzx_dropdown_menu_test_page.dart文件自己看。

没空编辑文字了,而且说这么多还不如你直接运行下看下效果,然后看下代码,就知道如何使用了。

算了 🤪 🤪 🤪 🙄 还是简单说下吧!!!
你只需要将GZXDropDownHeader和GZXDropDownMenu嵌套到你的代码中即可

GZXDropDownHeader

这里要注意了,这些参数不是必须要要写的,我写出来只是让你知道强大的自定义功能,实际上就前面三个参数是必填的

// 下拉菜单头部
GZXDropDownHeader(
  // 下拉的头部项,目前每一项,只能自定义显示的文字、图标、图标大小修改
  items: [
    GZXDropDownHeaderItem(_dropDownHeaderItemStrings[0]),
    GZXDropDownHeaderItem(
      _dropDownHeaderItemStrings[1],
      iconData: Icons.keyboard_arrow_down,
      iconDropDownData: Icons.keyboard_arrow_up,
    ),
    GZXDropDownHeaderItem(
      _dropDownHeaderItemStrings[2],
      style: TextStyle(color: Colors.green),
      iconData: Icons.arrow_upward,
      iconDropDownData: Icons.arrow_downward,
    ),
    GZXDropDownHeaderItem(
      _dropDownHeaderItemStrings[3],
      iconData: Icons.filter_frames,
      iconSize: 18,
    ),
  ],
  // GZXDropDownHeader对应第一父级Stack的key
  stackKey: _stackKey,
  // controller用于控制menu的显示或隐藏
  controller: _dropdownMenuController,
  // 当点击头部项的事件,在这里可以进行页面跳转或openEndDrawer
  onItemTap: (index) {
    if (index == 3) {
      _dropdownMenuController.hide();
      _scaffoldKey.currentState!.openEndDrawer();
    }
  },
  // 头部的高度
  height: 40,
  // 头部背景颜色
  color: Colors.red,
  // 头部边框宽度
  borderWidth: 1,
  // 头部边框颜色
  borderColor: Color(0xFFeeede6),
  // 分割线高度
  dividerHeight: 20,
  // 分割线颜色
  dividerColor: Color(0xFFeeede6),
  // 文字样式
  style: TextStyle(color: Color(0xFF666666), fontSize: 14),
  // 下拉时文字样式
  dropDownStyle: TextStyle(
    fontSize: 14,
    color: Theme.of(context).primaryColor,
  ),
  // 图标大小
  iconSize: 20,
  // 图标颜色
  iconColor: Color(0xFFafada7),
  // 下拉时图标颜色
  iconDropDownColor: Theme.of(context).primaryColor,
),

GZXDropDownMenu

// 下拉菜单,注意GZXDropDownMenu目前只能在Stack内,后续有时间会改进,以及支持CustomScrollView和NestedScrollView
GZXDropDownMenu(
  // controller用于控制menu的显示或隐藏
  controller: _dropdownMenuController,
  // 下拉菜单显示或隐藏动画时长
  animationMilliseconds: 300,
  // 下拉后遮罩颜色
  //maskColor: Theme.of(context).primaryColor.withOpacity(0.5),
  //maskColor: Colors.red.withOpacity(0.5),
  dropdownMenuChanging: (isShow, index) {
    setState(() {
      _dropdownMenuChange = '(正在${isShow ? '显示' : '隐藏'}$index)';
      print(_dropdownMenuChange);
    });
  },
  dropdownMenuChanged: (isShow, index) {
    setState(() {
      _dropdownMenuChange = '(已经${isShow ? '显示' : '隐藏'}$index)';
      print(_dropdownMenuChange);
    });
  },
  // 下拉菜单,高度自定义,你想显示什么就显示什么,完全由你决定,你只需要在选择后调用_dropdownMenuController.hide();即可
  menus: [
    GZXDropdownMenuBuilder(
        dropDownHeight: 40 * 8.0,
        dropDownWidget: _buildAddressWidget((selectValue) {
          _dropDownHeaderItemStrings[0] = selectValue;
          _dropdownMenuController.hide();
          setState(() {});
        })),
    GZXDropdownMenuBuilder(
        dropDownHeight: 40 * 8.0,
        dropDownWidget: _buildConditionListWidget(_brandSortConditions, (value) {
          _selectBrandSortCondition = value;
          _dropDownHeaderItemStrings[1] =
          _selectBrandSortCondition.name == '全部' ? '品牌' : _selectBrandSortCondition.name;
          _dropdownMenuController.hide();
          setState(() {});
        })),
    GZXDropdownMenuBuilder(
        dropDownHeight: 40.0 * _distanceSortConditions.length,
        dropDownWidget: _buildConditionListWidget(_distanceSortConditions, (value) {
          _selectDistanceSortCondition = value;
          _dropDownHeaderItemStrings[2] = _selectDistanceSortCondition.name;
          _dropdownMenuController.hide();
          setState(() {});
        })),
  ],
),

相关Repository

相关文章

捐助开发者

Comments
  • 没有appbar的情况下显示异常

    没有appbar的情况下显示异常

    显示异常的情况是需要很高的高度才会显示gridview的内容

    // var gridView = GridView.count( // physics: NeverScrollableScrollPhysics(), // crossAxisCount: _menuCount, // childAspectRatio: (_screenWidth / _menuCount) / widget.height, // children: widget.items.map((item) { // return _menu(item); // }).toList(), // ); var gridView = ListView( scrollDirection: Axis.horizontal, physics: NeverScrollableScrollPhysics(), children: widget.items.map((item) { return _menu(item); }).toList(), );

    然后改成这样才会显示正常

    opened by MugWorld 3
  • 多个实例加载时报错

    多个实例加载时报错

    主页用IndexedStack同时加载多个页面,当有两个或以上页面使用此插件时报错: ======== Exception caught by widgets library ======================================================= The following LateError was thrown building GZXDropDownMenu(dirty, dependencies: [_EffectiveTickerMode, MediaQuery], state: _GZXDropDownMenuState#f2693(ticker inactive)): LateInitializationError: Field '_maskColorOpacity@969011985' has not been initialized.

    The relevant error-causing widget was: GZXDropDownMenu file:///D:/Sky-Eye/code/skyeye-app-flutter/trunk/lib/page/home/tab_alert.dart:393:15 When the exception was thrown, this was the stack: #0 _GZXDropDownMenuState._maskColorOpacity (package:gzx_dropdown_menu/src/gzx_dropdown_menu.dart) #1 _GZXDropDownMenuState._mask (package:gzx_dropdown_menu/src/gzx_dropdown_menu.dart:176:47) #2 _GZXDropDownMenuState._buildDropDownWidget (package:gzx_dropdown_menu/src/gzx_dropdown_menu.dart:206:13) #3 _GZXDropDownMenuState.build (package:gzx_dropdown_menu/src/gzx_dropdown_menu.dart:86:12) #4 StatefulElement.build (package:flutter/src/widgets/framework.dart:4612:27)

    每个页面的key和GZXDropdownMenuController都是独立的,不知道为什么报这个错误。

    opened by wishinlife 1
  • 大佬 GZXDropDownHeader不支持放到AppBar的bottom中吗?

    大佬 GZXDropDownHeader不支持放到AppBar的bottom中吗?

    类似下面这样的结构

    Scaffold(
          key: _scaffoldKey,
          appBar: AppBar(
             title: "DropDown Menu Demo"
             bottom: PreferredSize(
                 child: GZXDropDownHeader,
                 preferredSize: Size.fromHeight(50),
              ),
          ),
          body: Stack(
            key: _stackKey,
            children: <Widget>[
              Container(
                  child: ListView(),
              ),
              GZXDropDownMenu(),
           ],
         ),
    );
    
    opened by hbshun 1
  • clone下来显示Your app isn't using AndroidX.

    clone下来显示Your app isn't using AndroidX.

    FAILURE: Build failed with an exception.

    • What went wrong: Could not resolve all files for configuration ':app:debugCompileClasspath'.

    Could not resolve io.flutter:arm64_v8a_debug:1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954. Required by: project :app Could not resolve io.flutter:arm64_v8a_debug:1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954. > Could not get resource 'https://jcenter.bintray.com/io/flutter/arm64_v8a_debug/1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954/arm64_v8a_debug-1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954.pom'. > Could not HEAD 'https://jcenter.bintray.com/io/flutter/arm64_v8a_debug/1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954/arm64_v8a_debug-1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954.pom'. > Read timed out Could not resolve io.flutter:x86_64_debug:1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954. Required by: project :app Could not resolve io.flutter:x86_64_debug:1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954. > Could not get resource 'https://jcenter.bintray.com/io/flutter/x86_64_debug/1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954/x86_64_debug-1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954.pom'. > Could not HEAD 'https://jcenter.bintray.com/io/flutter/x86_64_debug/1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954/x86_64_debug-1.0.0-9a28c3bcf40ce64fee61e807ee3e1395fd6bd954.pom'. > Read timed out

    • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

    • Get more help at https://help.gradle.org

    BUILD FAILED in 2m 1s Exception: Gradle task assembleDebug failed with exit code 1 Exited (sigterm)

    opened by liumingsongning 1
  • GZXDropdownMenuBuilder中 dropDownWidget问题

    GZXDropdownMenuBuilder中 dropDownWidget问题

    GZXDropdownMenuBuilder( dropDownHeight: 40 * 8.0, dropDownWidget: Column( children: [ Expanded(child: Container()), Container(height:40), ] )) 当dropDownWidget里边是 Column,子数组为Expanded + 固定高度组件,动画展开的过程中必然会报错。 A RenderFlex overflowed by xx pixels on the bottom

    opened by Zhuzhua 0
  • Field '_maskColorOpacity@1172011985' has not been initialized

    Field '_maskColorOpacity@1172011985' has not been initialized

    The following LateError was thrown building GZXDropDownMenu(dirty, dependencies: [_EffectiveTickerMode, MediaQuery], state: _GZXDropDownMenuState#610c4(ticker inactive)): LateInitializationError: Field '_maskColorOpacity@1172011985' has not been initialized.

    opened by maomao1020 1
Releases(V3.1.0)
  • V3.1.0(Apr 7, 2021)

    ✨ New Features

    • Add iconDropDownData to customize icon when menu is show

    🐛 Bug Fixes

    • Fixed the drop down menu not showing fully when the width of the drop down menu is smaller than the width of the screen
    Source code(tar.gz)
    Source code(zip)
  • V3.0.0+1(Apr 6, 2021)

  • V3.0.0(Apr 2, 2021)

  • V2.1.0(Jun 3, 2020)

    ✨ New Features

    • GZXDropDownMenu add dropdownMenuChanging and dropdownMenuChanged callback
    • GZXDropDownHeaderItem add style (see https://github.com/GanZhiXiong/gzx_dropdown_menu/issues/27)

    ⚡️ Improvements

    • Add removeListener and removeStatusListener when the animation is recreated
    • Reduced calls to setstate

    🐛 Bug Fixes

    • Fixed Dropdown menu hide mask no animation
    Source code(tar.gz)
    Source code(zip)
  • V2.0.0(May 11, 2020)

    ✨ New Features

    • Mask color animation display
    • Support for changing mask colors

    ⚡️ Improvements

    • Modify the drop-down header to not scroll
    • Hide dropdown menu add animation

    🐛 Bug Fixes

    • Fix-issues-16
    • Fix repeatedly click current header,can't hide
    Source code(tar.gz)
    Source code(zip)
  • V1.0.3(Aug 6, 2019)

Owner
干志雄
Talk is cheap. Show me the code.
干志雄
A simple animated radial menu widget for Flutter.

flutter_radial_menu A radial menu widget for Flutter. . Installation Install the latest version from pub. Quick Start Import the package, create a Rad

Victor Choueiri 434 Jan 7, 2023
Native context menu for Flutter apps

native_context_menu Native context menu for flutter apps Installation flutter pub add native_context_menu Usage import 'package:native_context_menu/na

Andrei Lesnitsky 151 Dec 22, 2022
Custom widget for Flutter

Flushbar Use this package if you need more customization when notifying your user. For Android developers, it is made to substitute toasts and snackba

Andre Haueisen 899 Dec 30, 2022
🔁 A custom refresh indicator for flutter.

Liquid Pull To Refresh A beautiful and custom refresh indicator for flutter highly inspired from Ramotion Pull Down to Refresh. Table of contents Inst

Ayush Agarwal 1.1k Jan 8, 2023
A customizable timer builder, with controller, animation, intervals, callbacks and custom actions for Flutter.

Custom Timer ⌛ A highly customizable timer builder, with controller, animation, intervals, callbacks, custom actions, and more! ?? Simple Usage @overr

Federico De Sía 27 Nov 23, 2022
A simple widget for animating a set of images with full custom controls as an alternative to using a GIF file.

image_sequence_animator A simple widget for animating a set of images with full custom controls as an alternative to using a GIF file. If you have a G

AliYigitBireroglu 134 Dec 22, 2022
A Splash screen with curved custom bottom sheet and dots indicator within it.

Pub.dev Curved Splash Screen A Splash screen with curved custom bottom sheet and dots indicator within it. You can add your custom splash screens acco

Hosain Mohamed 16 Dec 1, 2022
this repo is testing the custom painter by changing according to slider value. It was intended to be used for volume control in audio player.

custom_paint_demo Trying a widget called custom paint Getting Started This project is a starting point for a Flutter application. A few resources to g

Edy 7 Jan 16, 2022
Movies App UI in Flutter using Simple Widgets without Using API's in Flutter.

Movies App UI in Flutter using Simple Widgets without Using API's in Flutter.

Habib ullah 3 May 15, 2022
A flutter plugin for Easily make Flutter apps responsive. Automatically adapt UI to different screen sizes. Responsiveness made simple.

A flutter plugin for Easily make Flutter apps responsive. Automatically adapt UI to different screen sizes. Responsiveness made simple.

Urmish Patel 191 Dec 29, 2022
The Coolicons icon pack for Flutter with over 400 icons available for your flutter project.

coolicons This flutter package allows you to use the Coolicons icon pack. Made from Coolicons. ?? Installation In the dependencies: section of your pu

Stephen Joel 1 May 24, 2022
Foody - Flutter project to display foods to clients and display charts and has a lot of features , two flutter apps : Android and Web

Foody Flutter project to display foods to the clients and use charts and use a lot of features to complete the process (HUGE APP) There two apps: Andr

ABDULKARIMALBAIK 1 Feb 7, 2022
Flutter-business-card-app - Flutter + Dart business card mobile app

Dart + Flutter Business Card Mobile Application

Mark Hellner 1 Nov 8, 2022
A Flutter project that gives basic flutter design to implement a login UI

Login UI Design A Flutter project that gives basic flutter design to implement a

CABREX 9 Nov 8, 2022
Flutter Complete E-Commerce app (UI by - 'The Flutter Way')

NOT COMPLETED YET! e_commerce A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to ge

null 1 Mar 8, 2022
Flutter Shop UI - an e-commerce app using Flutter

If you are planning to create an e-commerce app using Flutter then this Shop UI Kit would be the perfect choice for you to make a gorgeous app for both Android & iOS.

Trần Văn Nguyên 21 Nov 21, 2022
A Flutter staggered grid view

flutter_staggered_grid_view A Flutter staggered grid view which supports multiple columns with rows of varying sizes. Features Configurable cross-axis

Romain Rastel 2.7k Dec 30, 2022
Tinder like cards swipe effect with Flutter.

Tinder cards Hi! After showcasing Focus for Reddit, the app I am working on, people asked me how did I do the tinder like cards swipe (posts media are

Ivascu Adrian 733 Jan 7, 2023
The app to demo animation with Flutter by implement Facebook reactions

Facebook Reactions Animation Description The app to demo animation with Flutter by implement Facebook reactions. Watch the demo video for more clarity

Duy Tran 318 Jan 8, 2023