mark
mark

Reputation: 1295

Printing the message in center of the screen in FLUTTER

This is my code to print the session gone inside my flutter app

else if (!snapshot.hasData && snapshot.hasError) {
              return Scaffold(
                body: Center(
                  child: Column(
                    children: <Widget>[
                      const Text('Session TimeOut, Log back in to continue'),
                      RaisedButton(
                        onPressed: () {
                          Navigator.of(context).pushReplacement(
                            CupertinoPageRoute(
                              builder: (_) => LoginPage(),
                            ),
                          );
                        },
                        child: const Text('LOG IN'),
                      ),
                    ],
                  ),
                ),
              );
            }

It is coming like this

here

I want the alert messaged Should come at the center of the screen, Any idea how to fix this

Upvotes: 0

Views: 747

Answers (2)

D&#225;niel R&#243;zsa
D&#225;niel R&#243;zsa

Reputation: 535

Column height is set to max by default. It means that it expand to the full screen height, so Center does not do anything with it. Also Column aligns its children to the top-center by default.

You have two options:

  1. set mainAxisSize: MainAxisSize.min, to your Column, and Center will work
  2. set mainAxisAlignment: MainAxisAlignment.center to your Column

Upvotes: 1

Nagual
Nagual

Reputation: 2089

you need to add to Column

mainAxisSize: MainAxisSize.min,
Scaffold(
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            const Text('Session TimeOut, Log back in to continue'),
            RaisedButton(
              onPressed: () {
                Navigator.of(context).pushReplacement(
                  CupertinoPageRoute(
                    builder: (_) => LoginPage(),
                  ),
                );
              },
              child: const Text('LOG IN'),
            ),
          ],
        ),
      ),
    );

Upvotes: 1

Related Questions