搜索插件、代码仓与 APP 分类

material_segmented_control 封面
插件详情v5.0.1

material_segmented_control

一个类似于 iOS 的分段控件,但采用 Material 设计。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1.1万
喜欢数
103
Pub 分数
150

安装插件

flutter pub add material_segmented_control

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个实现 Material Design 风格分段控件的 Flutter 小部件,提供与 iOS 风格分段控件视觉上一致的替代方案。它允许用户从一组互斥选项中选择一个,常用于设置或筛选功能。该控件支持自定义颜色、标签和选择行为,同时在 Android、iOS、Web、macOS、Windows 和 Linux 上保持平台适当的样式。

适合场景

  • 表单输入选择
  • 按类别筛选数据
  • 用户偏好设置
  • 标签页之间的导航
  • 可定制的UI组件

主要特点

  • 材料设计外观
  • 跨平台兼容性
  • 可自定义的颜色和标签
  • 支持单选
  • 与现有小部件的轻松集成

适合对象

  • 开发跨平台应用的开发者
  • 寻求符合 Material 规范的 UI 元素的设计人员
  • 需要直观的类似标签页导航的应用程序
  • 优先考虑跨平台的一致性
  • 具有过滤或配置界面的项目

使用建议

  • 仅限单选
  • 需要手动处理选择回调
  • 可能需要额外的样式来处理复杂布局
  • 未针对大量分段进行优化
  • 依赖外部包的维护

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Material Segmented Control

A material segmented control like the one for iOS, in Material style.

image

Why?

We all know well the Cupertino segmented widget in Flutter. But there is no similar in Material, so I thought, why not to create one.

You can check it out on pub.dev: (see package on pub.dev)

How to use

Import the package

In your pubspec.yaml, add

dependencies: 
    material_segmented_control: ^5.0.1
Import code

Wherever you want to use this widget, import

import 'package:material_segmented_control/material_segmented_control.dart';
Basic usage
int _currentSelection = 0;

MaterialSegmentedControl(
    children: _children,
    selectionIndex: _currentSelection,
    borderColor: Colors.grey,
    selectedColor: Colors.redAccent,
    unselectedColor: Colors.white,
    selectedTextStyle: TextStyle(color: Colors.white),
    unselectedTextStyle: TextStyle(color: Colors.redAccent),
    borderWidth: 0.7,
    borderRadius: 32.0,
    disabledChildren: [3],
    onSegmentTapped: (index) {
      setState(() {
        _currentSelection = index;
      });
    },
);

Map<int, Widget> _children = {
  0: Text('Hummingbird'),
  1: Text('Kiwi'),
  2: Text('Rio'),
  3: Text('Telluraves')
};
Features
  • Disable the selection for all children by setting selectionIndex to null. It un-selects all options.
  • Disable children to being not "clickable" (like setting onPressed to null on a button) by setting disabledChildren. Give it a list with all indices that should be disabled. Give it either null or an empty list to not use the disabled feature.

You might want to check out the example project.

所属分类

源码仓库

使用此插件的项目