I want to use the audio players package to run audio files on my app,
NOTE:
I use local files in assets file like this
assets\audio\he_has_got_the_packa.mp3
this path file
I try to use AssetSource
// this is an object from AudioPlayer
AudioPlayer player = AudioPlayer();
...
TextButton(
onPressed: () {
player.setSource(AssetSource('assets\audio\he_has_got_the_packa.mp3'));
},
child: Text('to play click here'),
),
but isn't running because asynchronous suspension
I try searching but I don't get content to this thing
you use below code and you issue is fix.
TextButton(
onPressed: () {
player.setSource(AssetSource('sample-15s.mp3')).then((value) {
player.play(AssetSource('sample-15s.mp3'));
});
},
child: Text('to play click here'),
),
also please verify this image also.
Happy Codeing....
Try this
TextButton(
onPressed: () async {
await player.play(AssetSource('assets\audio\he_has_got_the_packa.mp3'));
},
child: Text('to play click here'),
),
Adding await keyboard and making onPressed() async is important.
Related
I am new to flutter and I am developing an app in Flutter. While I am doing this, I try to add ElevatedButton which is the latest version of RaisedButton, and its return error and I am also not sure why. I will insert the error code image and would be grateful if someone tells me what is the reason for the error and how to solve it. Thank you
You need to add a child widget (it is required in addition to onPressed function). Here is a sample code for Elevated Button. You can adjust it based on your needs:
ElevatedButton(
style: ElevatedButton.styleFrom(
onPrimary: Colors.white,
primary: Color(0xffccbbd7),
minimumSize: const Size(330,70),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
),
onPressed: () {},
child: const Text('click'),
),
You Forgot the child Widget inside ElevatedButton, in this button onPressed and child widgets are required
Refer ElevatedButton
Try below code
ElevatedButton(
onPressed: () {
// write your onPressed function here
print('Button Pressed');
},
child: const Text('Press Me'),
),
Your result screen->
Well, elevated button should have child inside. Can be text, icon or image
ElevatedButton(
onPressed: () {
print('Tombol baru saja ditekan!');
},
child: const Text('Hit me!'),
),
How to add whatsapp image in floating action button in flutter because whatsapp icon is not in flutter icon list. Tell me a simple method.
Row(
children: [
FloatingActionButton(
child: const Icon(Icons.chat),
backgroundColor: Colors.green.shade800,
onPressed: () {
String url =
"https://wa.me/+923045873730/?text=Hello";
launch(url);
},
),
],
),
Font Awesome has a flutter package that helps with most icons that are not in flutter default icon set, https://pub.dev/packages/font_awesome_flutter. It also includes all icons listed in font Awesome Offical website https://fontawesome.com/icons
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
Row(
children: [
FloatingActionButton(
child: FaIcon(FontAwesomeIcons.whatsapp),
backgroundColor: Colors.green.shade800,
onPressed: () {
String url =
"https://wa.me/+923045873730/?text=Hello";
launch(url);
},
),
],
),
The easiest way that comes to my mind is that downloading the icon image of Whatsapp (from flaticon or other website), adding it to the project's assets and adding it as a child( for example asset image).
I am using flutter for development and I want to send app to background or close it when user clicks on back icon on appbar
I have used this answer for reference but apart from exit(0) is nothing working, which is not recommended in iOS.
I have tried following recommendations from other answers but none of it working on iOS.
Navigator.of(context).pop();
Navigator.of(context).maybePop();
Navigator.of(context, rootNavigator: true).pop(context);
Navigator.pushReplacementNamed(context, '/route');
SystemNavigator.pop();
Navigator.pop(context,true);
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
for android following is working properly.
SystemNavigator.pop();
What should I use to close the app within apple guidelines.
EDIT
SystemNavigator.pop(); gives black screen in iOS.
Try this
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.of(context).pop(),
),
title: Text("Sample"),
centerTitle: true,
),
I created a new Flutter app from scratch, in Android Studio. In one of my previous apps, I intentionally used a weird font style. Now, for some reason, the new app has the same fonts. Is it possible that I had stored some "global" font style somewhere in the Android Studio, and now it's getting re-used? How can I get rid of it and revert the "normal" fonts?
Here's the code of one widget and its screenshot in the emulator:
import 'package:flutter/material.dart';
class LoginScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Container(
child: Column(
children: <Widget>[
RaisedButton(
child: Text('Login'),
onPressed: () {
Navigator.pushNamed(context, '/');
},
),
Text('Login'),
],
),
),
);
}
}
No, there shouldn't be.
In my case it also appeared in the debug app, but disappeared again when I recompiled the project. I haven't seen it in a finished app yet.
I use url_launcher package in my app for making a call like this:
IconButton(
onPressed: () {
UrlLauncher.launch('tel://${user.phoneNumber}');
},
icon: Icon(
Icons.phone,
color: Color(0XFF01d57f),
),
)
everything works fine in the simulator, but on real app when I have another call apps like Skype, android ask for default app for calling; and if user select Skype by mistake and press "Always use this" every time Skype open for him instead of default call app how can i avoid those third party apps or just reset settings each time user enter the app ?
I also try flutter_phone_direct_caller package but same thing happened :
IconButton(
onPressed: () async {
//set the number here
bool res =
await FlutterPhoneDirectCaller.callNumber(
user.phoneNumber);
},
icon: Icon(
Icons.phone,
color: Color(0XFF01d57f),
),
)