how to run code dart on click app icon without launching the app

189 Views Asked by At

i am trying to develop an flutter app that when i click on the app icon a task will start without launching the app , i find the package quick action but when i click on the quick action always app is launched this is my code

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

 void main() {
     WidgetsFlutterBinding.ensureInitialized();
     final QuickActions quickActions = QuickActions();

     quickActions.initialize((shortcutType) {
       if (shortcutType == 'action_one') {
          print('The user tapped on the "Main view" action.');
       }
     });

     quickActions.setShortcutItems(<ShortcutItem>[
       const ShortcutItem(
         type: 'action_one',
         localizedTitle: 'Action one',
         icon: 'AppIcon',
         ),
       const ShortcutItem(
         type: 'action_two', localizedTitle: 'Action two', icon: 'ic_launcher'),
       ]);
   //runApp(MyApp());<-- comment
   }

thank you for helping me

1

There are 1 best solutions below

1
Vishwesh Soni On

I think you are doing only one click,
you have to tap long on the app ,
Also check const is missing there.

final QuickActions quickActions = const QuickActions();