getx
getx copied to clipboard
Get.back() not working in Get.Dialog using GetMaterialApp builder property
Describe the bug I have used the Default layout using material App for all pages, so i have a Get.Dialog() in which I have used a container to show a dialog box, but on the click of the button Get.back() is not working due to which i am not able to close dialog box on the button click.
Please refer to the below examples for the details with Screenshots and error description
Example:
main.dart
import 'package:flutter/material.dart';
import 'package:flutter_application_1/defaultview.dart';
import 'package:get/get.dart';
void main() {
runApp(GetMaterialApp(
initialRoute: '/task',
builder: (context, child) => DefaultView(child: child),
getPages: [
GetPage(
name: '/task',
page: () => Container(
child: Center(
child: RaisedButton(
child: Text('Open Dialog'),
onPressed: () => Get.defaultDialog(
title: 'Login Failure',
radius: 5.0,
middleText: "result",
actions: [
RaisedButton(
onPressed: () {
print("test");
Get.back();
},
child: Text(
"OK",
style: TextStyle(color: Colors.white),
),
color: Colors.black,
)
],
),
),
),
),
)
],
));
}
defaultview.dart
class DefaultView extends StatelessWidget {
final Widget child;
DefaultView({@required this.child});
final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
Color _colors;
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text('Task'),
),
body: Row(
children: [
SizedBox(
width: 60.0,
child: NavigationRail(
selectedIndex: 0,
onDestinationSelected: (index) {
_colors = Colors.amber;
},
destinations: [
NavigationRailDestination(
icon: Container(
child: Icon(
Icons.home,
color: Colors.red,
),
color: Colors.red.withOpacity(0.50),
),
label: Text("Home"),
),
NavigationRailDestination(
icon: Icon(Icons.supervised_user_circle),
label: Text("Persons"),
),
],
),
),
Expanded(
child: Container(
child: child,
),
),
],
),
),
);
}
}
Error Description in logs:
[GETX] "GetMaterialController" has been initialized
[GETX] GOING TO ROUTE /task
test
To Reproduce Steps to reproduce the behavior:
Use the above example with builder property issue is easily reproducible
Expected behavior Get.back() should close the dialog on click of OK button.
Actual behavior Dialog box does should get closed on OK button using Get.back()
Screenshots
Dialogbox with OK button

Flutter Version:
Flutter 1.23.0-18.1.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 198df796aa (4 months ago) • 2020-10-15 12:04:33 -0700
Engine • revision 1d12d82d9c
Tools • Dart 2.11.0 (build 2.11.0-213.1.beta)
Getx Version: Using the latest get package as specific version is not specified in the yaml file
dependencies: get: 3.24.0
Describe on which device you found the bug: Flutter web and Mi A1
Minimal reproduce code Use the Above provided example issue is easily reproducible
Why you use MaterialApp inside GetMaterialApp?
I had referred the issue raised by one of my colleague for Use of Popupbutton which requires a material App in which he suggested we can use Material App inside a material app which does not create the Material App twice. https://github.com/jonataslaw/getx/issues/729
@ghprod Any updates..?
Try this:
Get.back(closeOverlays: true);
Tested on get: 4.2.0
Do not use Material App in GetMaterial App, and try to create a scaffold before creating dialog
try this : Navigator.of(Get.overlayContext!, rootNavigator: true).pop();
Try this:
Get.back(closeOverlays: true);Tested on
get: 4.2.0
Its working in windows