Why does my CupertinoActionSheet appear from the top? - flutter

Everything works fine, it's just that the sheet appears at the top instead of the bottom. I would like the cupertinoactionsheet to appear from the bottom as default.
I'm currently using an Android emulator but I doubt it's the reason why the sheet is appearing from the top.
Attached is my code
Future<bool> showReportDialog({
#required BuildContext context,
}) async {
return showCupertinoDialog(
context: context,
builder: (context) => CupertinoActionSheet(
title: const Text('Make Your Space Safe',
style: TextStyle(
fontSize: 18, color: Colors.black, fontWeight: FontWeight.w600)),
message: const Text('What to report this user for?',
style: TextStyle(
fontSize: 16.5,
color: Colors.black38,
fontWeight: FontWeight.w500)),
actions: <CupertinoActionSheetAction>[
CupertinoActionSheetAction(
child: const Text(
'Scam',
),
onPressed: () {
afterReport();
print("Reported user for SCAM");
},
),
CupertinoActionSheetAction(
child: const Text('Bots/Spam'),
onPressed: () {
afterReport();
print("Reported user for BOTS/SPAM");
},
),
CupertinoActionSheetAction(
child: const Text('Sexually harassing'),
onPressed: () {
afterReport();
print("Reported user for SEXUALLY HARASSSING");
},
),
CupertinoActionSheetAction(
child: const Text('Offensive/abusive behaviour'),
onPressed: () {
afterReport();
print('Reported user for OFFENSIVE/ABUSIVE BEHAVIOUR');
},
),
CupertinoActionSheetAction(
child: const Text('I want to write more',
style: TextStyle(fontWeight: FontWeight.bold)),
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (BuildContext context) => ReportUser()));
},
),
CupertinoActionSheetAction(
child: const Text('Cancel'),
onPressed: () {
Navigator.pop(context);
},
)
],
),
);
}

You need to use showCupertinoModalPopup instead of showCupertinoDialog:
showCupertinoModalPopup(
context: context,
builder: (context) => CupertinoActionSheet(
title: const Text('Make Your Space Safe',
style: TextStyle(
fontSize: 18,
color: Colors.black,
fontWeight: FontWeight.w600)),
...

Related

Flutter showing error while using InkeWell (dirty State)

My Flutter project ain't working, as I used a inkwell for a text, so that when the user clicks on the text it Navigates to another page,and it gets error saying dirty state whenever I try to run it,
const SizedBox(width: 167.5),
InkWell(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: ((context) => const PopAnime()))),
child: const Text(
"See all >",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 15),
),
),
]),
[][1
InkWell(
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: ((context) => const PopAnime()),
),
),
child: const Text(
"See all >",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 15,
),
),
)
you can use navigator like this

show dialog is unstable when my keyboard is up in my flutter web app

I'm building an flutter web app and came across this issue.
I have a text field in an alert dialog.
It works perfectly in my laptop, but the alert dialog is unstable in my mobile.
Here's my code. How can I fix this?
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Add Tag'),
content: TextField(
controller: tagController,
decoration: InputDecoration(
hintText: 'Type here',
suffix: IconButton(
icon: const Icon(
Icons.clear,
size: 16,
),
onPressed: () {
tagController.clear();
},
),
),
),
actions: [
TextButton(
onPressed: () {
setState(() {
Navigator.pop(
context);
});
},
child: const Text(
'Cancel',
style: TextStyle(
color:
Colors.red),
)),
TextButton(
onPressed: () async {
},
child: const Text(
'OK',
style: TextStyle(
color:
Colors.green),
))
],
);
});

Firebase Auth systems stopped working after signOut

I was making a profile page. I also added a "Logout" button to the profile page.
The codes are as follows:
InkWell(
child: ListView(
shrinkWrap: true,
children: [
ListTile(
leading: Icon(Icons.person, color: Colors.black,),
title: Text("Profile", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black),),
onTap: () {
//Navigator.push(context, MaterialPageRoute(builder: (context) => profileScreen()));
},
),
ListTile(
leading: Icon(Icons.settings, color: Colors.black,),
title: Text("Settings", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black),),
onTap: () {
//Navigator.push(context, MaterialPageRoute(builder: (context) => settingsScreen()));
},
),
ListTile(
leading: Icon(Icons.exit_to_app, color: Colors.black,),
title: Text("Logout", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black),),
onTap: () {
FirebaseAuth.instance.signOut(); // !!!!!!!!!!!!<<<<<<<
},
),
],
),
onTap: () {
print("clicked");
},
),
Console:
W/System (31904): Ignoring header X-Firebase-Locale because its value was null.
When I press the ListTile with "Logout" written FirebaseAuth.instance.signOut(); the code would work. I pressed it and my access to the account was cut off. It also gave a few errors but those errors were normal errors anyway.
Then I tried to login to the account again, I couldn't. It gave an error other than password and email errors.
Apart from these, functions such as registration and forgot password do not work.
What could have caused this problem? How can I solve it? Thanks in advance for your help.

Flutter CupertinoAlertDialog widget error

I'm trying to use CupertinoAlertDialog on my profile page. It works just fine on my other page, but not the profile page.
Here is my code:
showCupertinoModalPopup(
context: context,
builder: (context) => CupertinoActionSheet(
actions: [
image != null ? CupertinoActionSheetAction(
child: Text('Remove photo',
style: TextStyle(
color: Colors.red
),),
onPressed: () {
Navigator.pop(context);
_openDialog(context);
},
)
void _openDialog(ctx) {
showCupertinoDialog(
context: ctx,
builder: (_) => CupertinoAlertDialog(
title: Text("Delete Chat"),
content: Text("Messages will be removed from this device only."),
actions: [
// Close the dialog
// You can use the CupertinoDialogAction widget instead
CupertinoButton(
child: Text('Cancel',
style: TextStyle(
color: Color(0xFF2481CF)
),
),
onPressed: () {
Navigator.of(ctx).pop();
}),
CupertinoButton(
child: Text('Delete',
style: TextStyle(
color: Colors.red
),
),
onPressed: () {
Navigator.of(ctx).pop();
},
)
],
));
}
And this is the error:
Is there any solutions?
Try this
Navigator.of(context).pop(false);
instead of
Navigator.of(ctx).pop();
In your code.its working for me.
Your Alert:
openDialog(BuildContext context) {
showCupertinoDialog(
context: context,
barrierDismissible: false,
builder: (context) => CupertinoAlertDialog(
title: Text('Delete Chat'),
content: Text('Messages will be removed from this device only.'),
actions: <Widget>[
CupertinoButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text(
'Cancel',
style: TextStyle(
color: Color(0xFF2481CF),
),
),
),
CupertinoButton(
onPressed: () => Navigator.of(context).pop(true),
child: Text(
'Delete',
style: TextStyle(color: Colors.red),
),
),
],
),
);
}
Your Widget:
ElevatedButton(
onPressed: () {
showCupertinoModalPopup(
context: context,
builder: (context) => CupertinoActionSheet(
actions: [
CupertinoActionSheetAction(
child: Text(
'Remove photo',
style: TextStyle(color: Colors.red),
),
onPressed: () {
Navigator.pop(context);
openDialog(context);
},
),
],
),
);
},
child: Text('Click me'),
style: ElevatedButton.styleFrom(
primary: Colors.red,
),
),

Flutter:Couldn't Show the AlertDialog

When I click the button, I want to show a dialog when the process is finished, but although I add the dialog part I cant see alertdialog in my screen.
Where am I doing wrong? here's my code;
child: InkWell(
onTap: () async {
final selectedLanguage =
await SharedPreferences.getInstance();
final setLanguage =
selectedLanguage.getString('selectedLanguage');
String language =
allTranslations.getLocaleKey(setLanguage);
_forgotPassword =
await createPasswordCode(_controller.text, language);
_dialog('Try');
},
child: Center(
child: Text(
'Send',
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
And here's my dialog part
Widget _dialog(String title) {
return AlertDialog(
title: Text(
title,
style: TextStyle(fontWeight: FontWeight.bold),
),
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(20)),
),
actions: [
FlatButton(
child: Text('Approve'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
}
You need to call the alertDialog inside showDialog.
InkWell(
onTap: () async {
final selectedLanguage =
await SharedPreferences.getInstance();
final setLanguage =
selectedLanguage.getString('selectedLanguage');
String language =
allTranslations.getLocaleKey(setLanguage);
_forgotPassword =
await createPasswordCode(_controller.text, language);
showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return _dialog("try");
},
);
},
child: Center(
child: Text(
'Send',
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
))
Widget _dialog(String title) {
return showDialog(
barrierDismissible: false,
context: context,
child: AlertDialog(
title: Text(
title,
style: TextStyle(fontWeight: FontWeight.bold),
),
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(20)),
),
actions: [
FlatButton(
child: Text('Approve'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
)
),
);
}
you need the showDialog method to show the dialog box