How can I play this function in background services in flutter?
Kindly elaborate or also attach documentation or video link if possible.
I'm trying to play some music from a dependency named assets_audio_player.
I tried to use the didAppLifeCycleChange but in this way, I was facing a new
issuer it plays 2 songs. now I want to play songs directly in the background does not matter
app is in background or in foreground
void setupPlaylist() async {
await audioplayer.open(
showNotification: true,
Playlist(audios: [
Audio(
'assets/1.mp4',
metas: Metas(
title: "Bazz aa by YS",
artist: 'Talha',
image: const MetasImage.network(
'https://www.musicgrotto.com/wp-content/uploads/2021/09/best-songs-of-all-time-graphic-art.jpg'),
),
),
// Audio(SongsList[2].,
// metas: Metas(
// title: "Bazz01",
// artist: 'Talha',
// )),
Audio.network(
'https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview125/v4/09/17/bb/0917bbe1-58c3-6252-d00e-9b70d42ef5dc/mzaf_2269500085377778268.plus.aac.p.m4a',
metas: Metas(
id: 'Online',
title: 'Online',
artist: 'Florent Champigny',
album: 'OnlineAlbum',
// image: MetasImage.network('https://www.google.com')
image: const MetasImage.network(
'https://i.dawn.com/large/2021/09/61399fb500900.png'),
),
),
Audio(
'assets/2.mp4',
metas: Metas(
title: "Bazz aa by YS",
artist: 'Talha',
image: const MetasImage.network(
'https://www.musicgrotto.com/wp-content/uploads/2021/09/best-songs-of-all-time-graphic-art.jpg'),
),
),
Audio('assets/3.mp4',
metas: Metas(
title: "Bazz aa song",
artist: 'Talha',
image: const MetasImage.network(
'https://www.thenews.com.pk/assets/uploads/updates/2021-12-27/920292_6757937_hgjhj_updates.jpg'),
)),
Audio('assets/1.mp4',
metas: Metas(
title: "Bazz03",
artist: 'Talha',
image: const MetasImage.network(
'https://www.thenews.com.pk/assets/uploads/updates/2021-12-27/920292_6757937_hgjhj_updates.jpg'),
)),
]),
autoStart: true,
loopMode: LoopMode.playlist,
);
}
Related
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",
),
],
);
I'm trying to call a final variable name "manSoMi" in AssetImage Widget but it always gets an error. I've tried many solutions to solve an error but it always says "Undefined name 'manSoMi'
import 'package:flutter/material.dart';
import 'package:zeus_app/models/Somiproduct.dart';
class DetailProductCart extends StatefulWidget {
final SoMiNam manSoMi;
const DetailProductCart({super.key, required this.manSoMi});
#override
State<DetailProductCart> createState() => _DetailProductCartState();
}
class _DetailProductCartState extends State<DetailProductCart> {
#override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.white,
body: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
Container(
width: size.width,
height: 500,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(manSoMi.image),
fit: BoxFit.cover)),
),
],
)
);
}
}
This is a Product class that i want to call it in AssetImage Widget by using the index name "manSoMi.image"
class SoMiNam {
final String image, title, addColors, price;
final int id;
SoMiNam(
{required this.image,
required this.title,
required this.addColors,
required this.price,
required this.id});
}
List<SoMiNam> aoSoMi = [
SoMiNam(
title: 'Sunflower Polo Tee',
price: '399.000 đ',
image: 'assets/images/v1.jpeg',
addColors: '+3 màu',
id: 1),
SoMiNam(
title: 'Bei Linen Shirt',
price: '429.000 đ',
image: 'assets/images/v6.jpeg',
addColors: '+3 màu',
id: 2),
SoMiNam(
title: 'GodFather Shirt',
price: '449.000 đ',
image: 'assets/images/v8.jpeg',
addColors: '+4 màu',
id: 3),
SoMiNam(
title: 'Felix Shirt',
price: '449.000 đ',
image: 'assets/images/FelixShirt.JPG',
addColors: '+2 màu',
id: 4),
SoMiNam(
title: 'Hemi Shirt',
price: '419.000 đ',
image: 'assets/images/HemiShirt.JPG',
addColors: '+1 màu',
id: 5),
SoMiNam(
title: 'Lala Cuban Shirt',
price: '449.000 đ',
image: 'assets/images/LalacubanShirt.JPG',
addColors: '+2 màu',
id: 6),
];
This is an error
You should call widget.manSoMi in order to access your variable in state full widget.
You need to use widget:
widget.manSoMi.image;
To access varieble manSoMi of DetailProductCart in _DetailProductCartState class.
final List <Category> _categories = [
Category(
id: '1',
title: 'Poultry',
food: [
Food(
id: '1',
title: 'Chicken 1',
description: "qdwwqd",
price: 500.00,
image: "https://jb-ph-cdn.tillster.com/menu-images/prod/45df1872-c7f7-4b3d-baa9-1b0c4f56a5cc.png",
choice: [],
),
],
),
Category(
id: '2',
title: 'Vegetables',
food: [
Food(
id: '1',
title: 'Cabbage',
description: "qdwwqd",
price: 500.00,
image: "https://jb-ph-cdn.tillster.com/menu-images/prod/45df1872-c7f7-4b3d-baa9-1b0c4f56a5cc.png",
choice: [],
),
],
),
]
'''
In order to insert new data into the food array, first you need to find the correct category:
String myID = '1';
int index = _categories.indexWhere((cat) => cat.id == myID);
Once you did that, it is quite simple:
_categories[index].food.add(Food());
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"),
],
);
in the case here I want to change the boolean value false to true by clicking Inkwel 1x in the flutter programming language. Where the key that I will change is in the array list for the menu. So when the menu is clicked, the key starts with false, then it will change to true. following my code. what I will change is the favorite key
This array data :
List<menuData> _menuServiceList = [];
#override
void initState() {
_menuServiceList.add(new menuData(
id: 1, name: 'menu 1', image: 'assets/icon/balancesheet.png', favorit: false
));
_menuServiceList.add(new menuData(
id: 2, name: 'menu 2', image: 'assets/icon/card.png', favorit: false
));
_menuServiceList.add(new menuData(
id: 3, name: 'menu 3', image: 'assets/icon/decrease.png', favorit: false
));
_menuServiceList.add(new menuData(
id: 5, name: 'menu 4', image: 'assets/icon/growth.png', favorit: false
));
_menuServiceList.add(new menuData(
id: 5, name: 'menu 5', image: 'assets/icon/growth.png', favorit: false
));
_menuServiceList.add(new menuData(
id: 6, name: 'menu 6', image: 'assets/icon/officesupplies.png', favorit: false
));
_menuServiceList.add(new menuData(
id: 7, name: 'menu 7', image: 'assets/icon/piechart.png', favorit: false
));
_menuServiceList.add(new menuData(
id: 8, name: 'menu 8', image: 'assets/icon/sharemoney.png', favorit: false
));
_menuServiceList.add(new menuData(
id: 9, name: 'menu 9', image: 'assets/icon/speechbubble.png', favorit: false
));
_menuServiceList.add(new menuData(
id: 10, name: 'menu 10', image: 'assets/icon/grid.png', favorit: true
));
super.initState();
}
this code clicked button :
child: InkWell(
onTap: (){
setState(() {
if (menuData.favorit == false){
print("klik false");
}else{
print("klik true");
}
});
},
child: HeaderItem(
images: menuData.image,
title: menuData.name,
textcolor: Colors.grey[600],
) ,
)
First of all, please make sure menuData.favorit is mutable. then just update the flag accordingly
child: InkWell(
onTap: (){
setState(() {
menuData.favorit = !menuData.favorit;
});
},
child: HeaderItem(
images: menuData.image,
title: menuData.name,
textcolor: Colors.grey[600],
),
)