Posts: 0
Threads: 0
Joined: Mar 2021
Reputation:
0
Level: inf [ ]
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
In Flutter, I write a simple dialog for the loader during async task. When I touch outside dialog dismissed, How can I stop this behaviour?
**Code**
showDialog(
context: context,
builder: (_) => new Dialog(
child: new Container(
alignment: FractionalOffset.center,
height: 80.0,
padding: const EdgeInsets.all(20.0),
child: new Row(
mainAxisSize: MainAxisSize.min,
children: [
new CircularProgressIndicator(),
new Padding(
padding: new EdgeInsets.only(left: 10.0),
child: new Text("Loading"),
),
],
),
),
));
|
Posts: 0
Threads: 0
Joined: Jan 2018
Reputation:
0
Level: inf [ ]
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
There's a property called `barrierDismissible` that you can pass to `showDialog` ; which makes dialogs dismissible or not on external click
showDialog(
barrierDismissible: false,
builder: ...
)
|
Posts: 0
Threads: 0
Joined: Jul 2021
Reputation:
0
Level: inf [ ]
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
If you want to prevent dialog close when back button pressed then refer below code. You have to wrap your AlertDialog in WillPopScope widget and make onWillPop property value with function which return Future.value(false).
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return WillPopScope(
onWillPop: () => Future.value(false),
child:AlertDialog(
title: new Text("Alert Title"),
content: new SingleChildScrollView(
child: Container(),),
actions: <Widget>[
new FlatButton(
child: new Text("Close"),
onPressed: () {
},
),
],
)
)
},
);
|
Posts: 0
Threads: 0
Joined: Apr 2020
Reputation:
0
Level: inf [ ]
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
**just Add this Line**
barrierDismissible: false,
**like as**
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(
"Classes",
style: TextStyle(
fontSize: 24, color: Colors.black, fontFamily: 'intel'),
),
content: setupAlertDialoadClassList(
context, listClasses, Icons.class__outlined, 0),
);
});
|
Posts: 0
Threads: 0
Joined: Mar 2021
Reputation:
0
Level: inf [ ]
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
Always use top flutter packages like [get][1]
[1]: [To see links please register here]
```
Get.generalDialog(pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation,) {
return SimpleDialog(
...
);
}, barrierDismissible: false /* its default value */);
```
|
Posts: 0
Threads: 0
Joined: Jan 2021
Reputation:
0
Level: inf [ ]
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
**barrierDismissible: false,**
Use this one as I described below.
showDialog(
barrierDismissible: false,
builder // code //
|
Posts: 0
Threads: 0
Joined: Nov 2017
Reputation:
0
Level: inf [ ]
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
This will disable device navigation
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return WillPopScope(
onWillPop: () async => false,
child:AlertDialog(
title: new Text("Alert Title"),
content: new SingleChildScrollView(
child: Container(),),
actions: <Widget>[
new FlatButton(
child: new Text("Close"),
onPressed: () {
},
),
],
)
)
},
);
|
Posts: 0
Threads: 0
Joined: Jan 2022
Reputation:
0
Level: inf [ ]
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
If you ar not using a showDialog, otherwise you'r using GestureDetectore, there's a easy way i just did, Just put a GestureDetector inside another one, then set the onTap action if that's your case on both GestureDetector's, with the diference that in one you are gonna put an action, an in the other one you can just leave it empty, just like this.
GestureDetector(
onTap: () { //The Gesture you dont want to afect the rest
Navigator.pop(context);
},
child: Container(
color: Colors.transparent,
child:GestureDetector(
onTap: () {}, //This way is not going to afect the inside widget
child: Container() //your widget
)
)
)
|
Posts: 0
Threads: 0
Joined: Jan 2019
Reputation:
0
Level: inf [ ]
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
**Phone navigation bar action disabled and disable outer touch in AlertDialog**
showDialog(
context: context,
barrierDismissible: false, // <-- Set this to false.
builder: (_) => WillPopScope(
onWillPop: () async => false, // <-- Prevents dialog dismiss on press of back button.
child: AlertDialog(),
),
);
|
|