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

dropdown_model_list 표지
패키지 상세v3.0.2

dropdown_model_list

유연한 드롭다운 모델 리스트는 간단한 모델 리스트와 함께 작동하며 사용하기 쉽고 맞춤 설정이 가능합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
249
좋아요
54
Pub 점수
160

패키지 설치

flutter pub add dropdown_model_list

패키지 개요

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

DropdownModelList는 모델 리스트를 사용하여 드롭다운 메뉴를 만드는 것을 단순화하는 유연하고 사용하기 쉬운 Flutter 패키지입니다. 개발자들이 드롭다운 옵션을 직접 사용자 정의 데이터 모델에 바인딩할 수 있게 해주며, 깔끔하고 타입 안전한 구현을 가능하게 합니다. 이 패키지는 외관과 동작을 커스터마이징할 수 있어 다양한 플랫폼에서의 UI 요구 사항에 적합합니다. 최소한의 설정과 직관적인 API를 통해 Flutter 앱에서 폼 입력 및 선택 워크플로우를 간편하게 만들어 줍니다.

사용 사례

  • 동적 옵션을 가진 폼 입력
  • 대시보드에서 사용자 정의 가능한 드롭다운
  • 사용자 선호도 선택기
  • 다국어 드롭다운
  • 데이터 필터링 인터페이스

주요 기능

  • 사용자 정의 모델 목록을 지원합니다
  • 기존 데이터 모델과의 간편한 통합
  • 높은 사용자 정의 가능한 UI
  • 크로스 플랫폼 호환성
  • 데이터 바인딩을 위한 간단한 API
  • 내장 상태 관리

적합한 대상

  • 동적 선택지를 사용하여 폼을 구축하는 개발자
  • 재사용 가능한 드롭다운 컴포넌트가 필요한 팀
  • 모델 기반 UI 요소를 필요로 하는 프로젝트
  • Flutter 초보자가 드롭다운 패턴 배우기
  • 다중 플랫폼을 대상으로 하는 앱

고려 사항

  • Dart 모델에 대한 이해가 필요합니다
  • 제한된 내장 검증
  • 기본적으로 네이티브 검색/필터링 없음
  • 복잡한 디자인의 경우 추가 스타일링이 필요할 수 있습니다
  • 고급 기능을 위해 외부 패키지에 의존합니다

원본 README

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

Flutter DropDown Model List

DropDown_Model_list

Features

Flexible DropDown Model List works with a simple model list and Easy to use & customized. In DropDown Model List Feature:-

  • Single Selection
  • Single Selection With Search
  • Multiple Selection
  • Radio Button Selection

# Installation
  1. Add the latest version of package to your pubspec.yaml (and dart pub get):
dart
  dependencies:
    flutter:
      sdk: flutter
    dropdown_model_list: latest
  1. Import the package and use it in your App.

Usage Example

import 'package:dropdown_model_list/dropdown_model_list.dart';

Example of Single Selection DropDown

import 'package:dropdown_model_list/drop_down/select_drop_list.dart';
import 'package:example/model/userModel.dart';
import 'package:flutter/material.dart';

class SingleSelection extends StatefulWidget {
  const SingleSelection({super.key});

  @override
  State<SingleSelection> createState() => _SingleSelectionPageState();
}

class _SingleSelectionPageState extends State<SingleSelection> {
  final users = [
    UserModel(id: '1', title: 'Alice'),
    UserModel(id: '2', title: 'Bob'),
    UserModel(id: '3', title: 'Charlie'),
  ];

  OptionItems<UserModel>? selectedUser;
  late DropdownListModel<UserModel> userDropdown;

  // Define one reusable placeholder
  final OptionItems<UserModel> placeholderOption = OptionItems(model: null, displayTitle: "Choose user");

  @override
  void initState() {
    super.initState();
    // Start with placeholder shown
    selectedUser = placeholderOption;

    // Only actual users in dropdown
    userDropdown = DropdownListModel<UserModel>(
      users.map((u) => OptionItems<UserModel>(
        model: u,
        displayTitle: u.title!,
      )).toList(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Single Selection DropDown'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          children: [
            /// Dropdown
            SelectDropList<UserModel>(
              itemSelected: selectedUser,
              dropListModel: userDropdown,
              onOptionSelected: (optionItem) {
                setState(() {
                  selectedUser = optionItem;
                });
              },
              hintText: "Choose user",
              showArrowIcon: true,
              height: 50,
              arrowColor: Colors.black,
              textColorTitle: Colors.black,
              textColorItem: Colors.black,
              dropboxColor: Colors.white,
              dropBoxBorderColor: Colors.grey,
              scrollThumbColor: Colors.blue,
            ),

            const SizedBox(height: 20),

            /// Clear button
            ElevatedButton(
              onPressed: () {
                setState(() {
                  selectedUser = placeholderOption; // 👈 not in list, but shown
                });
              },
              child: const Text("Clear Selected User"),
            )
          ],
        ),
      ),
    );
  }
}
            

Image of Single Selection DropDown

single_selection

Example of Search DropDown

import 'package:dropdown_model_list/drop_down/search_drop_list.dart';
import 'package:example/model/userModel.dart';
import 'package:flutter/material.dart';

class SearchSingleSelection extends StatefulWidget {
  const SearchSingleSelection({super.key});

  @override
  State<SearchSingleSelection> createState() => _SearchSingleSelectionPageState();
}

class _SearchSingleSelectionPageState extends State<SearchSingleSelection> {
  final users = [
    UserModel(id: '1', title: 'Alice'),
    UserModel(id: '2', title: 'Bob'),
    UserModel(id: '3', title: 'Charlie'),
  ];

  OptionItemsSearch<UserModel>? selectedUser;
  late DropdownSearchListModel<UserModel> userDropdown;

  // Placeholder used to reset the dropdown
  final OptionItemsSearch<UserModel> placeholderOption =
  OptionItemsSearch(model: null, displayTitle: "Choose user");

  @override
  void initState() {
    super.initState();
    selectedUser = placeholderOption;

    userDropdown = DropdownSearchListModel<UserModel>(
      users
          .map((u) =>
          OptionItemsSearch<UserModel>(model: u, displayTitle: u.title ?? ''))
          .toList(),
    );
  }

  void _onClearSelection() {
    setState(() {
      selectedUser = placeholderOption;
    });
  }

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Search DropDown'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          children: [
            /// Custom Search Dropdown
            SearchDropList<UserModel>(
              itemSelected: selectedUser,
              dropListModel: userDropdown,
              onOptionSelected: (optionItem) {
                setState(() {
                  selectedUser = optionItem;
                });
              },
              hintText: "Choose user",
              showArrowIcon: true,
              textColorTitle: Colors.black,
              textColorItem: Colors.black,
              dropboxColor: Colors.white,
              dropBoxBorderColor: Colors.grey,
              scrollThumbColor: Colors.blue,
              showClearButton: true,
              onClear: _onClearSelection,
              showBorder: false,
              enable: true,
              borderSize: 1,
            ),

            const SizedBox(height: 20),

            /// Clear Button (optional if showClearButton is used)
            ElevatedButton(
              onPressed: _onClearSelection,
              child: const Text("Clear Selected User"),
            )
          ],
        ),
      ),
    );
  }
}

Image of Search DropDown

search_dropdown

Example of Search DropDown with Multiple selection

import 'package:dropdown_model_list/drop_down/multiple_selection_search.dart';
import 'package:example/model/userModel.dart';
import 'package:flutter/material.dart';

class SearchMultipleSelection extends StatefulWidget {
  const SearchMultipleSelection({super.key});

  @override
  State<SearchMultipleSelection> createState() =>
      _SearchMultipleSelectionPageState();
}

class _SearchMultipleSelectionPageState extends State<SearchMultipleSelection> {
  final users = [
    UserModel(id: '1', title: 'Alice'),
    UserModel(id: '2', title: 'Bob'),
    UserModel(id: '3', title: 'Charlie'),
  ];

  late MultiDropdownSearchListModel<UserModel> userDropdown;

  // State for selected users
  List<OptionItemsMultiSearch<UserModel>> selectedUsers = [];

  @override
  void initState() {
    super.initState();

    userDropdown = MultiDropdownSearchListModel<UserModel>(
      users
          .map((u) => OptionItemsMultiSearch<UserModel>(
        model: u,
        displayTitle: u.title ?? '',
      ))
          .toList(),
    );
  }

  void _onClearSelection() {
    setState(() {
      selectedUsers.clear();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Search DropDown With Multiple selection'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            /// Custom Search Dropdown
            MultipleSelectionSearchDropList<UserModel>(
              dropListModel: userDropdown,
              hintText: "Choose user",
              showArrowIcon: true,
              height: 60,
              enableSearch: true, //If you hide search field set false but default its true
              textColorTitle: Colors.black,
              textColorItem: Colors.black,
              dropboxColor: Colors.white,
              dropBoxBorderColor: Colors.grey,
              scrollThumbColor: Colors.blue,
              showClearButton: true,
              onClear: _onClearSelection,
              showBorder: false,
              enable: true,
              borderSize: 1,
              // 👇 Track selected items
              selectedItems: selectedUsers,
              // 👇 Handle new selections
              onOptionsSelected: (List<OptionItemsMultiSearch<UserModel>> value) {
                setState(() {
                  selectedUsers = value;
                });
              },
            ),

            const SizedBox(height: 20),

            ElevatedButton(
              onPressed: _onClearSelection,
              child: const Text("Clear Selected User"),
            ),

            const SizedBox(height: 20),

            /// Display selected values
            const Text(
              "Selected Users:",
              style: TextStyle(fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 10),
            ...selectedUsers.map((user) => Text(user.displayTitle)),
          ],
        ),
      ),
    );
  }
}

Image of Search DropDown with Multiple selection

search_with_multiselection

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

카테고리

소스 저장소

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

아직 데이터가 없습니다.