Skip to content

Latest commit

 

History

History
134 lines (121 loc) · 4.96 KB

README_ZH.md

File metadata and controls

134 lines (121 loc) · 4.96 KB

flutter_drop_menu

Pub Version   License: MIT  

Language: English | 简体中文

介绍

这是一个自定义的Flutter下拉菜单,可以显示标题选中状态和多种下拉动画效果。

特征

  • 支持自定义header
  • 支持自定义menus
  • 支持多种动画效果
  • 内置选中效果header

效果预览

Preview

开始使用

安装

将 flutter_drop_menu 包添加到你的 pubspec 依赖项中

DropDownMenu 参数

选项 类型 描述 是否必传
header List 显示在标题中的自定义小部件
menus List 菜单中显示的自定义小部件
controller DropdownController 用于控制菜单的控制器
divider Widget? 将标题与菜单分隔开的小部件
tag String 菜单的标签
animType AnimationType 菜单动画类型,默认使用AnimationType.topToBottom
animTypes List? 菜单动画类型集合,可以指定每个菜单进行不同的动画
outsideOnTap GestureTapCallback? 外部点击区域回调
headerHeight double 标题小部件的高度
headerDecoration Decoration? 标题的装饰
headerBackgroundColor Color 标题小部件的背景颜色
headerMainAxisAlignment MainAxisAlignment 标题小部件在主轴上的排列方式
slideDx double 使用[AnimationType.rightToLeft]动画类型时滑动菜单占用的空间量
padding EdgeInsetsGeometry 菜单上下左右的填充量
curve Curve 菜单的动画曲线
duration Duration 菜单动画的持续时间
outsideColor Color 菜单外部区域的背景颜色

使用示例

  /// The controller to use to control the menu.
  final DropdownController _controller = DropdownController();

  /// Show the menu.
  void _showMenu(int index) {
    if (_controller.index == index && _controller.isShow) {
      _hideMenu(-1);
    } else {
      _controller.show(index);
    }
  }

  /// Hide the menu.
  void _hideMenu(int index) {
    _controller.hide(index);
  }
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          DropDownMenu(
            // The controller to use to control the menu.
            controller: _controller,
            // The header of the drop-down menu.
            header: List.generate(4, (index) {
                return DropDownHeader(
                  index: index,
                  title: 'Header $index',
                  onTap: (index) {
                    _showMenu(index);
                  },
                );
              },
            ),
            // The menu of the drop-down menu.
            menus: List.generate(4, (index) {
                return Container(
                  width: double.infinity,
                  height: 200,
                  color: Colors.white,
                  alignment: Alignment.center,
                  child: InkWell(
                    onTap: () {
                      _hideMenu(index);
                    },
                    child: Text('Menu $index'),
                  ),
                );
              },
            ),
          ),
        ],
      ),
    );
  }

License

The MIT License (MIT) Copyright (c) 2024 WangYongQi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.