搜尋套件、儲存庫與 APP 分類

material_segmented_control 封面
套件詳情v5.0.1

material_segmented_control

一個類似於 iOS 的分段控制元件,但採用 Material 設計。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.4萬
喜歡數
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.

所屬分類

原始碼儲存庫

使用此套件的專案