Closed slic-rick closed 3 years ago
I traced the issue and finally found the root of the problem. It is kind of an unexpected behavior to me.
Problem: Dialogue wont close if your app's main() is like this
void main() { runApp(new MaterialApp( home: new MyApp(), )); }
Consider changing main() to following, and the dialogues will dismiss normally then
void main() => runApp( new MyApp());
For somebody who wants to reproduce the error or want specific error example, here is the main.dart file.
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
));
}
// Changing main() to following solves the dismissing problem
/*
void main() => runApp( new MyApp());
*/
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Fancy Dialog Example',
theme: ThemeData.dark(),
home: new HomePage(),
);
}
}
class HomePage extends StatefulWidget {
HomePage({
Key key,
}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Awesome Dialog Example'),
),
body: Center(
child: Container(
padding: EdgeInsets.all(16),
child: SingleChildScrollView(
child: Column(
children: <Widget>[
SizedBox(
height: 100,
),
AnimatedButton(
text: 'Succes Dialog',
color: Colors.green,
pressEvent: () {
AwesomeDialog(
context: context,
animType: AnimType.LEFTSLIDE,
headerAnimationLoop: false,
dialogType: DialogType.SUCCES,
title: 'Succes',
desc:
'Dialog description here..................................................',
btnOkOnPress: () {
debugPrint('OnClcik');
},
btnOkIcon: Icons.check_circle,
onDissmissCallback: () {
debugPrint('Dialog Dissmiss from callback');
})
..show();
},
),
SizedBox(
height: 16,
),
],
),
),
)));
}
}
Everytime i press the buttons to naviagate to another page the dialog is not dismissed
showDialog: () { AwesomeDialog( context: context, dialogType: DialogType.NO_HEADER, animType: AnimType.TOPSLIDE, title: 'Release Music', desc: 'Release a new single or a new album', btnCancelOnPress: () { Navigator.push( context, MaterialPageRoute( builder: (context) => NewSingleView(), ), ); }, body: Column( children: [ Text( 'Release Music', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 25, color: Colors.black), ), SizedBox( height: 10, ), Text( 'Release a new single or a new album', style: TextStyle( fontSize: 15, fontWeight: FontWeight.w500), ) ], ), btnOkText: 'New Single', // btnOk: FlatButton( // shape: RoundedRectangleBorder( // borderRadius: // BorderRadius.circular(10.0)), // color: Colors.blue, // onPressed: () { // Navigator.pop(context); // Navigator.push( // context, // MaterialPageRoute( // builder: (context) => NewSingleView(), // ), // ); // }, // child: Text('New Single'), // ), // btnCancel: FlatButton( // shape: RoundedRectangleBorder( // borderRadius: // BorderRadius.circular(10.0)), // color: Colors.blue, // onPressed: () { // // Navigator.of(context)?.pop(); // // Navigator.push( // context, // MaterialPageRoute( // builder: (context) => AddAlbumView( // currentArtist: model.currentArtist, // ), // ), // ); // }, // child: Text('New Album'), // ), btnCancelColor: Colors.blue, btnOkColor: Colors.blue, btnCancelText: 'New Album', btnOkOnPress: () { debug( title: 'New album pressed', className: className); Navigator.push( context, MaterialPageRoute( builder: (context) => AddAlbumView( currentArtist: model.currentArtist, ), ), ); }, )..show(); },