Add Action to AndroidNotificationDetails - flutter

I would like to add a button to my notification, I was able to get it displayed but I can't find the documentation on how to add an action to the button press
const androidNotification = AndroidNotificationDetails(
'Bla', 'Bla',
icon: 'ic_bg_service_small',
ongoing: true,
actions: [AndroidNotificationAction("stop", "Stop")]);
flutterLocalNotificationsPlugin.show(
888,
'MyService',
'bla',
const NotificationDetails(android: androidNotification),
);

You need to use this plugin to make action in notifications https://pub.dev/packages/awesome_notifications
void _showNotificationWithButton() {
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 10,
channelKey: 'basic_channel',
title: 'Simple Notification',
body: 'Simple body'),
actionButtons: <NotificationActionButton>[
NotificationActionButton(key: 'yes', label: 'Yes'),
NotificationActionButton(key: 'no', label: 'No'),
],
);
}

Related

flutter awesome notification give function to button

i want to give some action to my notification button but i cannot get it to work, i want to give cancel download from my dio service
here is my code
notification.createNotification(
content: NotificationContent(
//simgple notification
id: id,
channelKey: 'basic', //set configuration wuth key "basic"
title: title,
body: body,
payload: {
"name": "layar",
},
icon: 'resource://drawable/ic_downloading',
autoDismissible: false,
notificationLayout: NotificationLayout.ProgressBar,
progress: progress,
fullScreenIntent: true,
backgroundColor: MyThemes.colorBlue,
),
actionButtons: [
NotificationActionButton(
key: "cancel",
label: "Cancel",
actionType: ActionType.DismissAction,
),
NotificationActionButton(
key: "pause",
label: "Pause",
),
],
);

How to add json list items to dropdown search items in Flutter | Dart

I'm creating a dropdown button with search. So I using this package . Here with this package I have problem. The response from the API is like this.
List countries = [
{
'id': '1',
'name': 'Brazil',
},
{
'id': '2',
'name': 'India',
},
{
'id': '3',
'name': 'Japan',
},
{
'id': '4',
'name': 'Tokyo',
},
{
'id': '5',
'name': 'Australia',
},
{
'id': '6',
'name': 'Srilanka',
},
{
'id': '7',
'name': 'Canada',
},
];
My Dropdown code is this,
body: Column(
children: [
DropdownSearch<String>(
mode: Mode.MENU,
items: countries['name'],
showSearchBox: true,
label: "Menu mode",
hint: "country in menu mode",
onChanged: (value){
print(countries['name']);
},
selectedItem: "Canada",
),
],
),
Here items: countries['name'] line i getting error as The argument type 'String' can't be assigned to the parameter type 'int'. Also when i select a country i want to print the country id. eg: if i select country as japan then it should print 4 in console. My Code is not working.
First of all, a List of Map doesn't work like this -> (countries['name]), try replace your items to:
DropdownSearch<String>(
mode: Mode.MENU,
items: countries.map((e)=>e['name']).toList(),
showSearchBox: true,
label: "Menu mode",
hint: "country in menu mode",
onChanged: (value){
print(value);
},
selectedItem: "Canada",
),
Try below code hope its help to you.
Refer my answer here for put json data to dropdown
Padding(
padding: const EdgeInsets.all(8.0),
child: DropdownSearch<dynamic>(
mode: Mode.MENU,
items: countries.map((e) => e['name']).toList(),
showSearchBox: true,
label: "Menu mode",
hint: "country in menu mode",
onChanged: (value) {},
selectedItem: "Canada",
),
),
Your result screen->
you have to create a data class Country and override the toString function to return the country name.
and update your dropdownSearch like this:
//don't forget to generate the list of countries frop the map
DropdownSearch<Country>(
mode: Mode.MENU,
items: yourCountries,
showSearchBox: true,
label: "Menu mode",
hint: "country in menu mode",
onChanged: (Country value){
print(value.id);
},
selectedItem: Country("Canada",7),
),
use your own country Model like this
DropdownSearch<Country>(
mode: Mode.MENU,
items: yourCountries,
popupProps: PopupProps.dialog(
showSelectedItems: false,
showSearchBox: true,
),
showSearchBox: true,
label: "Menu mode",
hint: "country in menu mode",
itemAsString: (Country u) => u.name,
onChanged: (Country country){
print(country.name);
print(country.id);
},
selectedItem: Country("Canada",7),
),
don't forget to use -> itemAsString field
//OR
you can Visit the - https://pub.dev/packages/dropdown_search#customize-showed-field-itemasstring. section from the package it self

How to land the user on a different page while using AutoTabsScaffold and BottomNavigationBar?

I'm using Auto_Route for routing in my application and AutoTabsScaffold makes it easier. But by default, the user is navigated to the first page in the bottom navigation bar but I want it to be navigated to third page by default. How can I do that?
Here's a snippet of the code:
AutoTabsScaffold(
routes: [
A(),
B(),
C(),
D(),
E(),
],
bottomNavigationBuilder: (_, tabsRouter) {
return BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Colors.black,
selectedItemColor: const Color(0XFFEAF8FF),
unselectedItemColor: Colors.grey,
currentIndex: tabsRouter.activeIndex,
onTap: tabsRouter.setActiveIndex,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.groups_outlined), label: ""),
BottomNavigationBarItem(icon: Icon(Icons.search), label: ""),
BottomNavigationBarItem(
icon: Icon(Icons.catching_pokemon), label: ""),
BottomNavigationBarItem(
icon: Icon(Icons.library_add_check_outlined), label: ""),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline), label: ""),
],
);
I want the user to land on C() and not A(). How can I do that? Thanks in advance.
Had the same issue.
I use auto_route package in my project.
We can see that current index depend on tabsRouter.activeIndex property.
So, I just added to the preferred route initial: true, property.
Like this:
CustomRoute(
path: '/',
page: MainScreen,
name: 'MainScreenRoute',
guards: [AuthGuard],
transitionsBuilder: TransitionsBuilders.fadeIn,
children: [
AutoRoute(
path: 'wallet',
page: WalletScreen,
),
AutoRoute(
path: 'trades',
page: TradesScreen,
),
AutoRoute(
path: 'market',
initial: true,
page: MarketScreen,
),

[Flutter]: Searching not working in SelectFormField package

Using this flutter package: https://pub.dev/packages/select_form_field
Hello I am having an issue regarding searching in "SelectFormFieldType.dialog", I don't know if I have missed something but it seems like the search doesn't seem to work.
Here is my code:
List of items:
List<Map<String, dynamic>> _items = [
{
'value': '',
'label': 'Select Account',
'icon': Icon(Icons.account_balance)
},
{'value': '1', 'label': 'Account 1', 'icon': Icon(Icons.account_balance)},
{'value': '2', 'label': 'Account 2', 'icon': Icon(Icons.account_balance)},
{'value': '3', 'label': 'Account 3', 'icon': Icon(Icons.account_balance)}
];
Here is selectformfield:
SelectFormField(
dialogCancelBtn: 'Cancel',
enableSearch: true,
dialogSearchHint: 'Search account',
type: SelectFormFieldType.dialog,
icon: Icon(Icons.account_balance),
labelText: 'Select Account',
hintText: 'Select Account',
items: _items,
onChanged: (val) {
print(val);
},
)
Here is the screenshot of the list
list of items
Here is the screenshot of output when searching item
output

awesome push notification with fcm

i am lost at some point,
i am try to figure out how to use this plugin plugin here
what should use to reply this:
this is working on fcm fine but i am trying to switch from fcm because of the reply like whatsApp
FirebaseMessaging.onMessage.listen
FirebaseMessaging.onMessageOpenedApp.listen
FirebaseMessaging.instance
.getInitialMessage()
.then((RemoteMessage message) {
});
you can use action button:
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 10,
channelKey: 'basic_channel',
title: 'Action button title',
body: 'Simple body',
),
actionButtons: [
NotificationActionButton(
key: "REPLY",
label: "Reply",
autoCancel: true,
enabled: true,
buttonType: ActionButtonType.InputField,
icon: "resource://drawable/logo"),
],
);