Ad
If Statement On OnPressed Flutter
permission_handler: ^8.3.0
I inserted permission handler in pubspec.yaml
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.MANAGE_ONGOING_CALLS"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
and here are permissions that users need to run the App.
I have one raisedbutton and I wish to ask permission on a first click and on second click, show alert diaglog saying "thank you".
here is what I got so far
getPermission() async {
var status = await Permission.contacts.status;
if (status.isGranted) {
print('Approved');
} else if (status.isDenied) {
print('Denied');
Permission.contacts.request();
}
}
ElevatedButton(onPressed: () {
if(condition == true){
getPermission();
}else{
showDialog(context: context,
builder: BuildContext()
title: column(
content: Text('Thank You'),
);
);
}
It seems like if statement after elevatedbutton is the problem but I can't exactly pin point the problem to fix. Thanks in advance
Ad
Answer
RaisedButton(onPressed: () async {
if(await Permission.contacts.status == status.isDenied){
getPermission();
}else{
showDialog(context: context,
builder: BuildContext()
title: column(
content: Text('Thank You'),
);
);}
so?
Ad
source: stackoverflow.com
Related Questions
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?
Ad