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

GitHub 儲存庫SimonWang9610/flutter_slidable_panel

flutter_slidable_panel

適用於 Flutter 的高效能滑動面板。

flutter_slidable_panel 專案封面
星標
3
分支
1
最近推送(UTC)
2024年8月20日
專案狀態
未封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

A high-performant slidable Panel that can show actions in different positions, and also can expand the action item when the panel is opening

Features

this package uses some syntax sugar of Dart 3.0, please create issues if you want to use this package in Dart 2.x, I will remove those syntax sugars and migrate it to Dart 2.x

  1. When the panel is closed/dismissed, no actions would be painted and laid out.
  2. The animation of actions (e.g., expanding/collapsing a specific action) will be scoped and not result in the re-layout and re-painting of the entire SlidablePanel
  3. control the SlidablePanel and actions programmatically using SlideController, not limited to gestures.
All action widgets can be expanded when the SlidablePanel is opening.
Different Motions
  • ActionMotion.drawer
  • ActionMotion.scroll
  • ActionMotion.behind
Disable gesture sliding

By setting gestureDisabled: true, you could avoid gesture sliding and continue sliding via SlideController programmatically

SlidablePanel(
  ...
  gestureDisabled: true,
  ...
)
Initial Opened Position

By specifying the initOpenedPosition of SlideController, you could open actions at the initOpenedPosition without using WidgetsBinding.instance.addPostFrameCallback.

you should ensure there are actions at the specified initOpenedPosition

  final SlideController _slideController = SlideController(
    usePreActionController: true,
    usePostActionController: true,
    initOpenedPosition: ActionPosition.pre,
  );

Getting started

import 'package:flutter/material.dart';
import 'package:flutter_slidable_panel/flutter_slidable_panel.dart';

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

  @override
  State<SizedSlidableExample> createState() => _SizedSlidableExampleState();
}

class _SizedSlidableExampleState extends State<SizedSlidableExample> {
  final SlideController _slideController = SlideController(
    usePreActionController: true,
    usePostActionController: true,
  );

  @override
  void dispose() {
    _slideController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Sized Slidable Example'),
      ),
      body: Center(
        child: SlidablePanel(
          controller: _slideController,
          maxSlideThreshold: 0.8,
          axis: Axis.horizontal,
          preActions: [
            TextButton(
              onPressed: () {
                _slideController.toggleAction(0);
              },
              style: TextButton.styleFrom(
                backgroundColor: Colors.greenAccent,
                shape: const RoundedRectangleBorder(),
              ),
              child: const Text("PreAction"),
            ),
            TextButton(
              onPressed: () {
                _slideController.toggleAction(1);
              },
              style: TextButton.styleFrom(
                backgroundColor: Colors.redAccent,
                shape: const RoundedRectangleBorder(),
              ),
              child: const Text("PreAction"),
            ),
          ],
          postActions: [
            TextButton(
              onPressed: () {
                _slideController.toggleAction(0);
              },
              style: TextButton.styleFrom(
                backgroundColor: Colors.greenAccent,
                shape: const RoundedRectangleBorder(),
              ),
              child: const Text("PostAction"),
            ),
            TextButton(
              onPressed: () {
                _slideController.toggleAction(1);
              },
              style: TextButton.styleFrom(
                backgroundColor: Colors.redAccent,
                shape: const RoundedRectangleBorder(),
              ),
              child: const Text("PostAction"),
            ),
          ],
          child: GestureDetector(
            onTap: () {
              _slideController.dismiss();
            },
            child: const DecoratedBox(
              decoration: BoxDecoration(color: Colors.blue),
              child: SizedBox(
                width: 250,
                height: 100,
                child: Center(
                  child: Text(
                    'Slide me',
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Usage

create a SlideController
  • usePreActionController indicates if you want to enable expanding/collapsing the pre actions
  • usePostActionController indicates if you want to enable expanding/collapsing the post actions.

if [usePreActionController] or [usePostActionController] is set to true, the corresponding [ActionController] would be created and bound to [RenderSlideAction] automatically

  • invoking [SlideController.expand]/[SlideController.collapse]/[SlideController.toggleAction] only takes effects for two cases:
    1. [usePreActionController] is true and the current [openedPosition] is [ActionPosition.pre]
    2. [usePostActionController] is true and the current [openedPosition] is [ActionPosition.post]
  final SlideController _slideController = SlideController(
    usePreActionController: true,
    usePostActionController: true,
  );
use different motion and alignment at different positions

SlidablePanel.preActionLayout and SlidablePanel.postActionLayout accept ActionLayout as parameters.

  1. You could determine how to layout the actions at the different positions by specifying:

    when using ActionAlignment.flex, you could give an action a specific flex value using ActionItem. Other actions not wrapped in ActionItem would have a default flex value of 1.

    ActionAlignment.spaceEvenly would ignore ActionItem

ActionLayout(
  alignment: ActionAlignment.spaceEvenly || ActionAlignment.flex,
)
  1. You could also determine which motion to use:
ActionLayout(
  motion: ActionMotion.behind || ActionMotion.drawer || ActionMotion.scroll
)
Do something when starting sliding

You could set onSlideStart to do some work when starting sliding, e.g., you want to dismiss all other SlidablePanel when starting sliding.

SlidablePanel(
  /// other code
  onSlideStart: <your function>,
  /// other code
)

Use SlideController programmatically

open the panel
SlideController.open({
    ActionPosition position = ActionPosition.pre,
    Curve curve = Curves.easeInOut,
    Duration duration = const Duration(milliseconds: 300),
    VoidCallback? onOpened,
  });
dismiss the panel
SlideController.dismiss({
    Curve curve = Curves.easeInOut,
    Duration duration = const Duration(milliseconds: 300),
    VoidCallback? onDismissed,
  })
check the current opened position
SlideController.openedPosition
  • opened ActionPosition.pre for horizontal and vertical
  • opened ActionPosition.post for horizontal and vertical
expand the index action at the opened position

index is the index in SlidablePanel.preActions or SlidablePanel.postActions

it will try to expand the index action at the current opened position if this panel is opened;

if this panel is closed/dismissed, it has no effects

if the current opened position has no associated ActionController, it also has no effects

you could associate ActionController to a specific position by setting usePreActionController or usePostActionController as true.

SlideController.expand(
    int index, {
    Curve curve = Curves.easeInOut,
    Duration duration = const Duration(milliseconds: 150),
  })
collapse the index action at the opened position
SlideController.collapse(
    int index, {
    required ActionPosition position,
    Curve curve = Curves.easeInOut,
    Duration duration = const Duration(milliseconds: 150),
  })
toggle the index action at the opened position
SlideController.toggleAction(
    int index, {
    Curve curve = Curves.easeInOut,
    Duration duration = const Duration(milliseconds: 150),
  })
detect if the index action is expanded
bool SlideController.hasExpandedAt(int index)
Simon Wang GitHub avatar
GitHub 作者

Simon Wang ↗

Learning by sharing. Dart/Flutter/Golang/Node.js Full stack developer.

語言DartC++CMakeCSwiftHTMLShellObjective-CJavaKotlin

分類

此儲存庫發佈的套件

使用的依賴

依賴清單 3 項

  • flutter{"sdk":"flutter"}
  • flutter_test開發依賴{"sdk":"flutter"}
  • flutter_lints開發依賴^2.0.0

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

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

GitHub Docs — About repositories ↗