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

GitHub 저장소MelbourneDeveloper/arborio

아르보리오

애니메이션을 갖춘 우아하고 유연한 트리뷰입니다. Flutter에서 계층 데이터를 표시합니다.

아르보리오 프로젝트 이미지
스타
14
포크
4
최근 푸시(UTC)
2024. 12. 15.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

Arborio

CI Coverage

An elegant, flexible Treeview with Animation. Display hierarchical data in Flutter.

Logo

Sample

Check out the live sample app here

Features

  • 🌳 Hierarchical data display with unlimited nesting
  • ✨ Smooth animations for expand/collapse operations
  • 🎨 Fully customizable node and expander appearance
  • 🔑 Global key support for programmatic control
  • 🎯 Type-safe with generics support
  • 📱 Responsive and mobile-friendly

Basic Usage

Here's a simple example of how to create a tree view:

import 'package:arborio/tree_view.dart';
import 'package:flutter/material.dart';

enum ElementType { file, folder }

// Define your data type
class FileSystemElement {
  FileSystemElement(this.name, this.type);
  final String name;
  final ElementType type;
}

// Create tree nodes
final nodes = [
  TreeNode<FileSystemElement>(
    const Key('root'),
    FileSystemElement('Documents', ElementType.folder),
    [
      TreeNode<FileSystemElement>(
        const Key('child1'),
        FileSystemElement('report.pdf', ElementType.file),
      ),
    ],
  ),
];

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
          body: TreeView<FileSystemElement>(
            nodes: nodes,
            builder: (context, node, isSelected, animation, select) => Row(
              children: [
                Icon(
                  node.data.type == ElementType.folder
                      ? Icons.folder
                      : Icons.file_copy,
                ),
                Text(node.data.name),
              ],
            ),
            expanderBuilder: (context, isExpanded, animation) =>
                RotationTransition(
              turns: animation,
              child: const Icon(Icons.chevron_right),
            ),
          ),
        ),
        debugShowCheckedModeBanner: false,
      );
}

Using TreeViewKey

The TreeViewKey allows programmatic control of the tree view:

// Create a key
const treeViewKey = TreeViewKey<FileSystemElement>();

// Use it in your TreeView
TreeView<FileSystemElement>(
  key: treeViewKey,
  nodes: nodes,
  builder: (context, node, isSelected, animation, select) {
    // ... node builder implementation
  },
  expanderBuilder: (context, isExpanded, animation) {
    return RotationTransition(
      turns: animation,
      child: const Icon(Icons.chevron_right),
    );
  },
)

Node Management

You can dynamically add or remove nodes using the tree's state. This example uses mutable state for simplicitly, but you can achieve the same result with immutable data classes.

// Add a new node
FloatingActionButton(
  onPressed: () => setState(() {
    nodes.add(
      TreeNode(
        const Key('newnode'),
        FileSystemElement('New Folder', ElementType.folder),
      ),
    );
  }),
  child: const Icon(Icons.add),
),

// Expand/collapse all nodes
FloatingActionButton(
  onPressed: () => setState(() {
    treeViewKey.currentState?.expandAll();
  }),
  child: const Icon(Icons.expand),
),

FloatingActionButton(
  onPressed: () => setState(() {
    treeViewKey.currentState?.collapseAll();
  }),
  child: const Icon(Icons.compress),
),

Handling Node Events

TreeView<FileSystemElement>(
  onExpansionChanged: (node, expanded) {
    print('Node ${node.data.name} is now ${expanded ? 'expanded' : 'collapsed'}');
  },
  onSelectionChanged: (node) {
    print('Selected node: ${node.data.name}');
  },
  expanderBuilder: (context, isExpanded, animation) {
    return RotationTransition(
      turns: animation,
      child: const Icon(Icons.chevron_right),
    );
  },
)

Customizing Node Appearance

The builder parameter gives you full control over node appearance, along with an animation variable so you can respond to changes over time:

builder: (context, node, isSelected, animation, select) {
  return InkWell(
    onTap: () => select(node),
    child: Container(
      color: isSelected ? Colors.blue.withOpacity(0.1) : null,
      padding: const EdgeInsets.all(8),
      child: Row(
        children: [
          if (node.data.type == ElementType.folder)
            RotationTransition(
              turns: animation,
              child: const Icon(Icons.folder),
            )
          else
            const Icon(Icons.file_copy),
          const SizedBox(width: 8),
          Text(node.data.name),
        ],
      ),
    ),
  );
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the BSD 3-Clause - see the LICENSE file for details.

Christian Findlay GitHub avatar
GitHub 작성자

Christian Findlay ↗

Building frameworks, tools and apps with AI in Melbourne, Australia

Melbourne, Australia공식 웹사이트 ↗
언어DartC++CMakeHTMLSwiftCShellKotlinObjective-C

분류

사용 중인 의존성

의존성 목록 6 개

  • cupertino_icons^1.0.2
  • flutter{"sdk":"flutter"}
  • arborio_sample개발 의존성{"path":"example"}
  • austerity개발 의존성^1.1.0
  • flutter_lints개발 의존성^2.0.0
  • flutter_test개발 의존성{"sdk":"flutter"}

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗