Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FlatButton onPressed Not Working In Positioned Widget

Whenever I used FlatButton onPressed Method Is Not Working In Positioned Widget.

I am designing one screen in that buttons are always in the bottom of the screen and that button click we can move to other screens,but here it is not working, can anyone check and help me out.thaks in advance

           child: Stack(
               // height: MediaQuery.of(context).size.height,
               children: <Widget>[
                     Positioned(
                         left: 0,
                         bottom: 0,
                           // alignment: Alignment(0, 0),
                           child: Row(
                             mainAxisSize: MainAxisSize.max,
                             crossAxisAlignment: CrossAxisAlignment.end,
                             mainAxisAlignment: MainAxisAlignment.end,
                             children: <Widget>[
                               SizedBox(height: 115),
                               ButtonTheme(
                                 minWidth:
                                     MediaQuery.of(context).size.width / 2,
                                 height: 60.0,
                                 child: FlatButton.icon(
                                   icon: Icon(FontAwesomeIcons.fileInvoice),
                                   color: Colors.white,
                                   onPressed: () {
                                  MaterialPageRoute(builder: (context) => MainScreen());
                                   },
                                   label: Text(
                                     "My Orders",
                                     textAlign: TextAlign.center,
                                     style: TextStyle(
                                       // decoration: TextDecoration.underline,
                                       fontSize: 25,
                                       fontWeight: FontWeight.bold,
                                       color: Theme.of(context).accentColor,
                                     ),
                                   ),
                                 ),
                               ),
                               SizedBox(height: 115),
                               ButtonTheme(
                                 minWidth:
                                     MediaQuery.of(context).size.width / 2,
                                 height: 60.0,
                                 child: FlatButton.icon(
                                   icon: Icon(FontAwesomeIcons.dollarSign),
                                   color: Colors.white60,
                                   onPressed: () {
                                    Navigator.pushReplacementNamed(
                                       context, '/home');
                                   },
                                   label: Text(
                                     "Bean Balnace",
                                     textAlign: TextAlign.center,
                                     style: TextStyle(
                                       // decoration: TextDecoration.underline,
                                       fontWeight: FontWeight.bold,
                                       fontSize: 20,
                                       color: Theme.of(context).accentColor,
                                     ),
                                   ),
                                 ),
                               ),
                             ],
                           )),
like image 925
Zeeshan Ansari Avatar asked Feb 12 '26 14:02

Zeeshan Ansari


1 Answers

Change this line:

MaterialPageRoute(builder: (context) => MainScreen());

to this:

Navigator.push(context, MaterialPageRoute(builder: (context) => MainScreen()));
like image 187
hoangquyy Avatar answered Feb 15 '26 10:02

hoangquyy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!