패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.0.5

customtogglebuttons

Flutter 내장 ToggleButtons보다 더 많은 유연성을 제공하는 사용자 정의 ToggleButtons 구현입니다.

30일 다운로드
66
좋아요
14
Pub 점수
40

패키지 설치

flutter pub add customtogglebuttons

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

플러터에서 내장 위젯의 제한을 넘어가는 유연하고 사용자 정의 가능한 토글 버튼 구현체입니다. 외관, 동작 및 상호작용에 대한 강화된 제어를 제공하여 개발자가 쉽게 고유한 토글 버튼 디자인을 만들 수 있도록 합니다. 맞춤형 시각 피드백이나 복잡한 선택 로직이 필요한 애플리케이션에 적합합니다. 패키지는 가볍고 기존 플러터 프로젝트에 원활하게 통합됩니다.

사용 사례

  • 고유한 토글 스타일을 가진 사용자 정의 UI 컴포넌트
  • 고급 선택 인터페이스
  • 동적 버튼 레이아웃
  • 접근성 중심의 토글 디자인
  • 인터랙티브 폼 컨트롤

주요 기능

  • 확장 가능한 디자인 옵션
  • 기본 ToggleButtons에 대한 개선된 사용자 지정
  • 동적 버튼 크기 지원
  • 유연한 선택 처리
  • 깔끔하고 최소한의 API

적합한 대상

  • 창의적인 토글 패턴을 찾는 UI 디자이너
  • 인터랙티브 폼을 개발하는 개발자
  • 표준이 아닌 전환 동작이 필요한 앱
  • 접근성과 사용자 경험을 우선시하는 프로젝트
  • Flutter 초보자가 위젯 사용자 정의 배우기

고려 사항

  • 복잡한 사용 사례의 경우 수동 상태 관리가 필요합니다
  • 제한된 플랫폼 고유 스타일 기본값
  • 내장 애니메이션이 없음(외부 패키지를 통해 추가)
  • 키보드 탐색을 위해 추가 코드가 필요할 수 있습니다
  • 매우 큰 버튼 세트에 최적화되지 않음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Custom Toggle Buttons

A custom ToggleButtons implementation that allows more flexibility than Flutter's inbuilt ToggleButtons.

Features

  • Horizontal and Vertical Alignment support
  • Elevation support
  • More customization for each state (selected, disabled, unselected
  • Similar look and feel as Flutter Material CustomButtons

Getting started

Add this dependency to your package's pubspec.yaml file:

dependencies:
  ...
  customtogglebuttons: ^0.0.5

and install it by running the following in your command line:

flutter pub get

Now you can use this in your source file by adding the following import:

import 'package:customtogglebuttons/customtogglebuttons.dart';

Usage

The simplest example is below, it creates a 2 icon set of toggle buttons that can be selected or unselected on each click.

Create a list of boolean values to store selected/unselected state:

List<bool> _isSelected = [false, false];

In your build method:

CustomToggleButtons(
	isSelected: _isSelected,
	children: <Widget>[
		Icon(Icons.add),
		Icon(Icons.remove),
	],
	onPressed: (index) {
		setState(() {
			_isSelected[index] = !_isSelected[index];
		});
	},
),

NOTE: The length of the bool List you pass in isSelected has to be the same as the length of the children list.

Examples

The source code for all examples is available in the example/lib/main.dart file.

You can run the example app on your mobile device and have a look at each of the samples in action.

Default

Shows the default behaviour without any additional styling properties. When the width of the buttons is longer than the available width, the next buttons automatically wrap to the next line.

Vertical Alignment

Shows vertically aligned toggle buttons, and a sample with Text widgets.

Border Styling

Shows an example of borderless toggle buttons, and an example where the border width and color are set for selected and unselected states.

Color Styling

Shows colors set for the selected, unselected and disabled states. Also shows an example with a specified splash color.

Spacing and Elevation

Shows examples with spacing for horizontal and vertical alignment, and an example with elevation.

Additional Parameters

Parameter Type Usage Description Required?
children List<Widget> children: <Widget>[...] The toggle button widgets. These are typically Icon or Text widgets. Length of list must be equal to the length of isSelected list. Yes
isSelected List<bool> isSelected: <bool>[...] The corresponding selection state of each toggle button. Length of list must be equal to the length of children list. Yes
onPressed void Function(index) onPressed: (){...} The callback that is called when a button is tapped. The index parameter of the callback is the index of the button that is tapped No
constraints BoxConstraints constraints: BoxConstraints(...) Defines the button's size. If this property is null, then BoxConstraints(minWidth: 48.0, minHeight: 48.0) is be used. No
color Color color: Colors.orange The color for descendant [Text] and [Icon] widgets if the button is enabled and not selected. Defaults to Theme.of(context).colorScheme.onSurface. No
selectedColor Color selectedColor: Colors.orange The color for descendant [Text] and [Icon] widgets if the button is selected. Defaults to Theme.of(context).colorScheme.primary. No
disabledColor Color disabledColor: Colors.orange The color for descendant [Text] and [Icon] widgets if the button is disabled. Defaults to Theme.of(context).colorScheme.onSurface.withOpacity(0.38). No
fillColor Color fillColor:: Colors.orange The fill color for selected toggle buttons. Defaults to Colors.transparent. No
unselectedFillColor Color unselectedFillColor: Colors.orange The fill color for unselected toggle buttons. Defaults to Colors.transparent. No
disabledFillColor Color disabledFillColor: Colors.orange The fill color for disabled toggle buttons. Defaults to Colors.transparent. No
highlightColor Color highlightColor: Colors.orange The highlight color for the button's InkWell. Defaults to Theme.of(context).highlightColor. No
splashColor Color splashColor: Colors.orange The splash color for the button's InkWell. Defaults to Theme.of(context).splashColor. No
hoverColor Color hoverColor: Colors.orange The color to use for filling the button when the button has a pointer hovering over it. Defaults to Theme.of(context).hoverColor. No
renderBorder bool renderBorder: false Whether or not to render a border around each toggle button. If false, no border will be rendered, even if other border properties are defined. Defaults to true. No
borderColor Color borderColor: Colors.orange The border color to display when the toggle button is enabled and not selected. Defaults to Colors.black12. No
selectedBorderColor Color selectedBorderColor: Colors.orange The border color to display when the toggle button is selected. Defaults to Colors.black12. No
disabledBorderColor Color disabledBorderColor: Colors.orange The border color to display when the toggle button is disabled. Defaults to Colors.black12. No
borderWidth double borderWidth: 2.5 The width of the border surrounding each toggle button. This applies to both the greater surrounding border, as well as the borders between buttons. Defaults to a width of 1.0 No
borderRadius double borderRadius: 2.5 Not implemented The radii of the border's corners. Defaults to 0.0 No
spacing double spacing: 5.0 The space between two consecutive toggle buttons. Defaults to 0.0. No
runSpacing double runSpacing: 5.0 The space between two consecutive runs of toggle buttons. Defaults to 0.0. No
direction Axis direction: Axis.vertical The direction in which the toggle buttons will be created. Can be either Axis.horizontal or Axis.vertical. Defaults to Axis.horizontal. No
elevation double elevation: 10.0 The elevation of each toggle button. Defaults to 0.0. No

Contributing

All contributions are welcome 😄

  • If you found a bug/issue with the library, consider making an Issue describing it in as much detail possible.
  • If you want to fix something, add something you feel is relevant or resolve an issue, feel free to submit a Pull Request. Try to be as descriptive as possible about what the PR is about.
  • Do consider modifying the documentation and adding documentation comments in your code so that the existing documentation is kept up-to-date.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.