Quick accetions in flutter

 


Add quick_actions: ^0.3.0+2 package in your .yaml file

import the quick_actions package and create a new instance of the QuickActions in the Manager's state class.


  
import 'package:quick_actions/quick_actions.dart';

class _QuickActionsManagerState extends State {
  final QuickActions quickActions = QuickActions();

}

Setup Quick Actions.


  
void _setupQuickActions() {
    quickActions.setShortcutItems([
      ShortcutItem(
          type: 'action_main',
          localizedTitle: 'Main view',
          icon: icons.menu),
      ShortcutItem(
          type: 'action_help',
          localizedTitle: 'Help',
          icon: icons.help)
    ]);
  }

Handle Selected Action.


  
void _handleQuickActions() {
  quickActions.initialize((shortcutType) {
    if (shortcutType == 'action_main') {
      Navigator.push(
          context, MaterialPageRoute(builder: (context) => Login()));
    } else if(shortcutType == 'action_help') {
      print('Show the help dialog!');
    }
  });
}

Use it.


  
@override
void initState() {
  super.initState();
  _setupQuickActions();
  _handleQuickActions();
}

Post a Comment

Previous Post Next Post

Subscribe Us


Get tutorials, Flutter news and other exclusive content delivered to your inbox. Join 1000+ growth-oriented Flutter developers subscribed to the newsletter

100% value, 0% spam. Unsubscribe anytime