A Contextual action bar workaround for flutter

Overview

Flutter contextual action bar(CAB)

CAB & Flutter

CAB is a top app bar that replace the application app bar to provide contextual actions to selected items. Check the material implementation and requirement here

Flutter does not natively support CAB yet. see issue Until CAB is natively supported, this package should provide you with an elegant way to implement the contextual action bar in flutter.

How it works

  • ContextualScaffold or ContextualScrollView(for slivers)
  • ContextualAppBar
  • ContextualAction
  • ContextualActionWidget

ContextualScaffold<?>

The ContextualScaffold<?> is similar to the normal material Scaffold except that it also takes a required contextualAppBar.

ContextualScaffold<?>(
      contextualAppBar: ContextualAppBar(),
      appBar: AppBar(),
      body: Body(),
    )

You can provide multiple ContextualScaffold as needed

ContextualScrollView<?>

The ContextualScrollView<?> is similar to the normal NestedScrollview except that it also takes a required contextualAppBar.

 ContextualScrollView<?>(
     contextualAppBar: ContextualAppBar(),
     headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) => [],
     body: Body(),
  )
   

The ContextualScrollView is used to add first class support for silvers although ContextualScaffold can also be used with NestedScrollview check the WhatsApp example for complete usage.

ContextualAppBar<?>

The ContextualAppBar<?> is similar to the normal material Appbar but takes a counterBuilder instead of title and also a contextualActions instead of actions.

 ContextualAppBar(
      counterBuilder: (int itemsCount){
        return Text("$itemsCount Selected");
      },
      contextualActions: <ContextualAction>[],
    )

ContextualAction<?>

The ContextualAction<?> allows you to take actions on the selected items, with the help of itemsHandler callback.

ContextualAction(
            itemsHandler: (List<?> items) {
              items.forEach((item) {
                Scaffold.of(context).showSnackBar(SnackBar(
                  content: Text("$item saved"),
                ));
              });
            },
            child: Icon(Icons.save),
          ),

ContextualActionWidget<?>

You can use the ContextualActionWidget anywhere in the ContextualActionScaffold or ContextualScrollView<?> body to notify ContextualActionScaffold or ContextualScrollView<?> respectively, that an item have been selected in order to show the ContextualAppBar.

   ContextualActionWidget(
          data: ?,
          child: ChildWidget(),
        )

Note: It is important that the child widget does not handle onLongPress.

A closer look at ContextualActionWidget<?>

The ContextualActionWidget<?> takes other optional parameters like

  • selectedColor
  • selectedWidget
  • unselectedWidget

The selectedColor is the color of the background for the selected item, it defaults to the splash color, if not provided. The selectedColor works well with ListTile.

selectedWidget and unselectedWidget are stacked on top of the provided child widget. By default, they are positioned at the center of the provided child widget. Since They are stacked, you can use Row, Align, Positioned Widget or any other combination of widgets to position them where desired.

The selectedWidget is shown when the ActionMode is enabled and the item is selected, while the unselectedWidget is shown when ActionMode is enabled and the item is not selected. See example(status_saver) image below with both the selectedWidget and unselectedWidget aligned to the top-right corner.

ActionMode

This contextual action bar workaround does not support zero item in the ActionMode.

  • Use the ActionMode.addItem<?> to add an item to the selected items. If this is the first selection, the ActionMode is will be enabled.

  • Use the ActionMode.addItems<?> to add a list of items.

  • Use the ActionMode.disable<?> to disable and deselect all selected items.

  • Use the ActionMode.enabledStream<?> to emit true or false depending on if the Action mode is enabled or disabled respectively.

Note: In most cases, you won't need to use ActionMode.disable<?> because the package already do that for you where needed.

Study complete examples at example page. If you like the project, don't forget to star ⭐️

Other Packages authored by me

License

This package is licensed under the MIT license. See LICENSE for details.

You might also like...

A Flutter package to create a nice circular menu using a Floating Action Button.

A Flutter package to create a nice circular menu using a Floating Action Button.

FAB Circular Menu A Flutter package to create a nice circular menu using a Floating Action Button. Inspired by Mayur Kshirsagar's great FAB Microinter

Jan 5, 2023

A action bottom sheet that adapts to the platform (Android/iOS).

A action bottom sheet that adapts to the platform (Android/iOS).

Adaptive action sheet A action bottom sheet that adapts to the platform (Android/iOS). iOS Android Getting Started Add the package to your pubspec.yam

Sep 26, 2022

Master Channel cannot use Glass Floating Action Button

Master Channel cannot use Glass Floating Action Button

Problem Master Channel cannot use GlassFloatingActionButton. About This package

Oct 2, 2022

Adaptive dialog - Show alert dialog or modal action sheet adaptively according to platform.

Adaptive dialog - Show alert dialog or modal action sheet adaptively according to platform.

adaptive_dialog Show alert dialog or modal action sheet adaptively according to platform. showOkAlertDialog Convenient wrapper of showAlertDialog. iOS

Dec 17, 2022

Icarus - Local Action, Global Impact

Icarus - Local Action, Global Impact

Icarus Local Action, Global Impact Download · Report Bug · Request Feature Table of Contents About The Project About Icarus Todo Technologies Getting

Oct 26, 2022

This package will animate a floating action button at the center and icons at the bottomNavigationBar using AnimatedContainer and SlideTransition respectively.

This package will animate a floating action button at the center and icons at the bottomNavigationBar using AnimatedContainer and SlideTransition respectively.

floating_bottom_bar This package will animate a floating action button at the center and icons at the bottomNavigationBar using AnimatedContainer and

Oct 10, 2022

Flutter component concept created with Flutter using Dart programming language, inspired by Gooey Rab Bar.

Flutter component concept created with Flutter using Dart programming language, inspired by Gooey Rab Bar.

Gooey Tab Bar Flutter Flutter component concept created with Flutter using Dart programming language, inspired by Gooey Tab Bar. About This component

Dec 14, 2022

Flutter-FFNavigationBar - Configurable navigation bar for Flutter

Flutter-FFNavigationBar - Configurable navigation bar for Flutter

ff_navigation_bar A highly configurable navigation bar with emphasis for the selected item. Add dependency dependencies: ff_navigation_bar: ^0.1.5

Sep 22, 2022

best flutter / dart practices + Custom Painter + Sliver App Bar + Custom Scrollview

best flutter / dart practices + Custom Painter + Sliver App Bar + Custom Scrollview

Weekly Budget Flutter App A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get yo

Oct 21, 2021
Comments
  • ActionMode dismissed callback

    ActionMode dismissed callback

    Hi,

    First of all thank you for such a nice plugin. It does the job pretty well.

    In one of my use case, I need to hide/unhide a view based on ActionMode enabled/disabled status. I tried to figure it out but could not able to identify if the ActionMode is disabled. Though by using the CounterBuilder I identified that the ActionMode is enabled when itemCount >= 0

    Looking forward for your help.

    Thanks in advance.

    opened by imsanjaysah 4
  • Fix Scaffold.of(context) calls and update Scaffold constructors

    Fix Scaffold.of(context) calls and update Scaffold constructors

    The new version of Scaffold in flutter does not have a nullOk parameter, so I removed that.

    I also ran into an issue where ContextualActionBar was calling Scaffold.of(context) but since it was a sibling in the Stack, it could not find the correct Scaffold. I updated this so it is within the Scaffold, and the Scaffold builds either the appBar or contextualAppBar depending on if ActionMode is enabled or not.

    opened by percula 2
Owner
null
A chat application that utilizes the smart reply ML model to suggest contextual conversation replies.

smart_reply A chat application that utilizes the smart reply ML model to suggest contextual conversation replies. Sample Notes Smart Replies are conte

Ahmed Aboelyazeed 1 May 15, 2022
Flutter-nav-bottom-bar-tutorial - A flutter bottom navigation bar tutorial

Flutter Bottom Navigation Bar Tutorial A tutorial with various Flutter bottom na

Aleyna Eser 2 Oct 25, 2022
A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

r_scan A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your iss

PengHui Li 112 Nov 11, 2022
Starlight search bar - Starlight search bar with flutter

starlight_search_bar If you find the easiest way to search your item, this is fo

Ye Myo Aung 1 Apr 20, 2022
Animation nav bar - Flutter Animated Navigation Bar

Flutter Animated Navigation Bar Getting Started This project is a starting point

Sudesh Nishshanka Bandara 23 Dec 30, 2022
Custom bottom bar - A bottom tool bar that can be swiped left or right to expose more tools.

custom_bottom_bar A bottom tool bar that can be swiped left or right to expose more tools. usage Create your custom bottom bars with up to four custom

null 4 Jan 26, 2020
This is a JazzCash UI clone ( Modern Wallet App in Pakistan), implementing modern app bar animmation. One can take a concept of making app bar with animation.

jazzcash_ui This is a JazzCash UI clone ( Modern Wallet App in Pakistan), implementing modern app bar animmation. One can take a concept of making app

null 9 Nov 27, 2022
A flutter UI package provides a cell widget that has leading and trailing swipe action menu.

Language: English |中文简体 flutter_swipe_action_cell A package that can give you a cell that can be swiped ,effect is like iOS native If you like this pa

WenJingRui 261 Jan 7, 2023
GitHub Action that uses the Dart Package Analyzer to compute the Pub score of Dart/Flutter packages

Dart/Flutter package analyzer This action uses the pana (Package ANAlysis) package to compute the score that your Dart or Flutter package will have on

Axel Ogereau-Peltier 45 Dec 29, 2022
Floating Action Button Widget For Flutter

Flutter Tutorial - FloatingActionButton Widget (FAB) Embed the FloatingActionBut

Behruz Hurramov 0 Dec 27, 2021