Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Navigator.pop(context) showing blank

I was trying to navigate back to the first Screen using Navigator.pop(context), but instead it shows a blank screen instead of going back to the first screen.
How do i fix this

MAIN SCREEN
enter image description here

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'GenderButton.dart';
import 'constants.dart';
import 'buttons.dart';
import 'resultpage.dart';

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Center(child: Text('')),
          elevation: 0,
          actions: [
            IconButton(
                onPressed: () {},
                icon: Icon(
                  Icons.add_alert_sharp,
                  size: 35,
                ))
          ],
          leading: IconButton(
            onPressed: () {},
            icon: Icon(
              Icons.add,
              size: 35,
            ),
          ),
        ),
        body: HomeScreen());
  }
}

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  Gender SelectedGender = Gender.empty;
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        //BMI Calculator Header
        Row(
          children: [
            SizedBox(
              width: 30,
            ),
            Text(
              'BMI Calculator',
              style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
            ),
          ],
        ),
        SizedBox(
          height: 20,
        ),
        //Gender Text
        Row(
          children: [
            SizedBox(
              width: 25,
            ),
            Text(
              'Gender',
              style: TextStyle(fontSize: 17),
            ),
          ],
        ),
        SizedBox(
          height: 10,
        ),
        //Button Widget
        Row(
          children: [
            SizedBox(
              width: 25,
            ),
            BoxButton(
              Type: 'MALE',
              BorderColor: SelectedGender == Gender.male
                  ? activeCardColor
                  : inactiveCardColor,
              IconColor:
                  SelectedGender == Gender.male ? activeCardColor : inactiv,
              OnPress: () {
                setState(() {
                  SelectedGender = Gender.male;
                });
              },
            ),
            SizedBox(
              width: 15,
            ),
            BoxButton(
              Type: 'FEMALE',
              BorderColor: SelectedGender == Gender.female
                  ? activeCardColor
                  : inactiveCardColor,
              IconColor:
                  SelectedGender == Gender.female ? activeCardColor : inactiv,
              OnPress: () {
                setState(() {
                  SelectedGender = Gender.female;
                });
              },
            ),
          ],
        ),
        SizedBox(
          height: 20,
        ),
        //Weight Text
        Row(
          children: [
            SizedBox(
              width: 25,
            ),
            //Weight Text
            Text(
              'Weight',
              style: TextStyle(fontSize: 15),
            )
          ],
        ),
        SizedBox(
          height: 5,
        ),
        Row(
          children: [
            SizedBox(
              width: 25,
            ),
            Container(
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(8)),
              // margin: EdgeInsets.all(15),
              height: 50,
              width: 250,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  RoundedIconButton(
                    icon: FontAwesomeIcons.minus,
                    onPressed: () {
                      setState(() {
                        Weight--;
                      });
                    },
                  ),
                  SizedBox(
                    width: 55,
                  ),
                  Text(
                    Weight.toString(),
                    style: TextStyle(
                        color: Colors.black,
                        fontSize: 20,
                        fontWeight: FontWeight.bold),
                  ),
                  SizedBox(
                    width: 50,
                  ),
                  RoundedIconButton(
                    icon: FontAwesomeIcons.plus,
                    onPressed: () {
                      setState(() {
                        Weight++;
                      });
                    },
                  )
                ],
              ),
            ),
            SizedBox(
              width: 10,
            ),
            Container(
              height: 50,
              width: 100,
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(9)),
            )
          ],
        ),
        SizedBox(
          height: 20,
        ),
        //Height Text
        Row(
          children: [
            SizedBox(
              width: 25,
            ),
            Text(
              'Height',
              style: TextStyle(fontSize: 15),
            )
          ],
        ),
        Row(
          children: [
            SizedBox(
              width: 25,
            ),
            Container(
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(8)),
              // margin: EdgeInsets.all(15),
              height: 50,
              width: 250,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  RoundedIconButton(
                    icon: FontAwesomeIcons.minus,
                    onPressed: () {
                      setState(() {
                        Height--;
                      });
                    },
                  ),
                  SizedBox(
                    width: 55,
                  ),
                  Text(
                    Height.toString(),
                    style: TextStyle(
                        color: Colors.black,
                        fontSize: 20,
                        fontWeight: FontWeight.bold),
                  ),
                  SizedBox(
                    width: 50,
                  ),
                  RoundedIconButton(
                    icon: FontAwesomeIcons.plus,
                    onPressed: () {
                      setState(() {
                        Height++;
                      });
                    },
                  )
                ],
              ),
            ),
            SizedBox(
              width: 10,
            ),
            Container(
              height: 50,
              width: 100,
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(9)),
            )
          ],
        ),
        SizedBox(
          height: 20,
        ),
        Row(
          children: [
            SizedBox(
              width: 25,
            ),
            Text(
              'Age',
              style: TextStyle(fontSize: 18),
            )
          ],
        ),
        SizedBox(
          height: 5,
        ),
        Container(
          decoration: BoxDecoration(
              color: Colors.white, borderRadius: BorderRadius.circular(8)),
          height: 50,
          width: 369,
          child: Container(
            // margin: EdgeInsets.all(15),
            height: 50,
            width: 250,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                RoundedIconButton(
                  icon: FontAwesomeIcons.minus,
                  onPressed: () {
                    setState(() {
                      Age--;
                    });
                  },
                ),
                SizedBox(
                  width: 100,
                ),
                Text(
                  Age.toString(),
                  style: TextStyle(
                      color: Colors.black,
                      fontSize: 20,
                      fontWeight: FontWeight.bold),
                ),
                SizedBox(
                  width: 110,
                ),
                RoundedIconButton(
                  icon: FontAwesomeIcons.plus,
                  onPressed: () {
                    setState(() {
                      Age++;
                    });
                  },
                )
              ],
            ),
          ),
        ),
        SizedBox(
          height: 20,
        ),
        GestureDetector(
          onTap: () {
            Navigator.push(context, MaterialPageRoute(builder: (context) {
              return ResultPage();
            }));
          },
          child: Container(
            decoration: BoxDecoration(
                color: Color(0xFF06C46C),
                borderRadius: BorderRadius.circular(8)),
            height: 50,
            width: 369,
            child: Center(
                child: Text(
              'Calculate',
              style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
            )),
          ),
        ),
      ],
    );
  }
}

enter image description here
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SCREEN 2

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ResultPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
          scaffoldBackgroundColor: Colors.black,
          textTheme: TextTheme(
            bodyText2: TextStyle(color: Colors.white),
          ),
          colorScheme: ColorScheme.light(
              primary: Colors.black, secondary: Colors.black)),
      home: Scaffold(
          appBar: AppBar(
            title: Center(child: Text('')),
            elevation: 0,
            actions: [
              IconButton(
                  onPressed: () {},
                  icon: Icon(
                    Icons.add_alert_sharp,
                    size: 35,
                  ))
            ],
            leading: IconButton(
              onPressed: () {},
              icon: Icon(
                Icons.add,
                size: 35,
              ),
            ),
          ),
          body: Results()),
    );
  }
}

class Results extends StatefulWidget {
  @override
  _ResultsState createState() => _ResultsState();
}

class _ResultsState extends State<Results> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(
            'Result',
            style: TextStyle(fontSize: 30),
          ),
          Center(
            child: Container(
              decoration: BoxDecoration(
                  color: Color(0xFF333335),
                  borderRadius: BorderRadius.circular(8)),
              margin: EdgeInsets.all(10),
              height: 300,
              width: 350,
            ),
          ),
          Center(
            child: Container(
              margin: EdgeInsets.all(35),
              child: Text('For your height , a normal would be from 48.6 '
                  'to 63.3 kilograms'),
            ),
          ),
          GestureDetector(
            onTap: () {
              Navigator.pop(context);
            },
            child: Container(
              decoration: BoxDecoration(
                  color: Color(0xFF06C46C),
                  borderRadius: BorderRadius.circular(8)),
              height: 50,
              width: 369,
              child: Center(
                  child: Text(
                'Recalculate BMI',
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
              )),
            ),
          ),
        ],
      ),
    );
  }
}

and also if you look at how i position all my widget to get same styling of a design i saw on dribble enter link description here am doing it right ? because i feel like i am doing it the wrong way and am still a beginner and i was trying to recreate what i learnt from a course i bought on udemy?

>Solution :

Try below code hope its help to you. set rootNavigator: true

Refer Naviagtion here , here, here

   Navigator.of(
        context,
        rootNavigator: true,
      ).pop(
        context,
      );

Or try below solution also

Navigator.pop(context);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading