I'm creating a Flutter mobile application. I have a Scaffold with a Drawer that is Centered in the App Like This:
Centered Drawer: https://ibb.co/s5BMdNM
When The User Taps on the 2nd ListTile which is "Filter Character / Choose Categories", an AlertDialog popups. The Problem is the Alert Dialog isn't Centered neither vertically nor horizontally in the Landscape Orientation, and It's not centered vertically in the Portrait one.
Landscape AlertDialog: https://ibb.co/GtdJ2jZ
Portrait AlertDialog: https://ibb.co/HH6vQbx
I've tried calculating the percentage of the misplacement and adding it as a padding to the right, it worked when the Device Orientation was LandscapeRight, but was misplaced again when the orientation became LandscapeLeft.
Right Adjusted: https://ibb.co/h9K0YB3
Left Misplaced: https://ibb.co/JykZ67x
I've Searched but currently there's a problem getting the Device's true orientation.
So can anyone help me centering the AlertDialog, or tell me why it isn't centered? Thanks in Advance.
Summarized Drawer's Code:
Scaffold(
key: scaffoldKey,
backgroundColor: Colors.grey[100],
body: _getScaffoldBody(homePageState, context),
drawer: Center(
child: Container(
alignment: Alignment.center,
width: MediaQuery.of(context).size.width * 0.9 > 375
? 375
: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.9 > 58.0 * 6
? 58.0 * 6 // 58 * Number of List Tiles
: MediaQuery.of(context).size.height * 0.9,
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.all(Radius.circular(5)),
),
child: ListView(
shrinkWrap: true,
padding: EdgeInsets.zero,
physics: BouncingScrollPhysics(),
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
ListTile(
title: Text('Filter Characters / Choose Categories'),
trailing: Icon(
Icons.search,
color: Colors.blue,
),
onTap: () {
showCategoriesDialg(homePageState, context);
},
),
],
),
),
),
),
Showing AlertDialog's Code:
Future showCategoriesDialg(State<HomePage> homePageState, BuildContext context) async {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap a button!
builder: (BuildContext context) {
return AlertDialog(
scrollable: true,
content: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height - 200,
child: ListView.builder(
itemCount: categories.length,
itemBuilder: (context, index) {
return CheckboxListTile(
title: Text(categories.values.elementAt(index).titleEn),
value: categories.values.elementAt(index).checked,
onChanged: (newValue) {
homePageState.setState(() {
categories.values.elementAt(index).checked = newValue;
});
},
controlAffinity: ListTileControlAffinity.trailing,
);
},
),
),
);
},
);
}