Larry Jing
Larry Jing

Reputation: 404

Why does my Flutter app look fine on the IOS emulator but overflow on Android?

I understand that there are different screen sizes, but is there a way to account for that? I also don't think the screen sizes are that different. The emulator for Android is a nexus 6 and the IOS emulator is an iphone 11, which is a difference of .14 inches. The IOS version fits comfortably while the Android overflows by a lot. Attached are screenshots.iPhone emulator

Android emulator

How would I fix this, aside from squishing everything closer together? Is there a way to make everything proportional to screen size, so it looks the same on IOS but then scales down to the Android phone? My Dart code is below:

Widget build(BuildContext context) {
return MaterialApp(
  home: Scaffold(
    backgroundColor: Colors.teal,
    body: SafeArea(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Center(
            child: CircleAvatar(
              radius: 100.0,
              backgroundImage: AssetImage('images/headshot.jpg'),
            ),
          ),
          SizedBox(
            height: 0.0,
          ),
          Container(
            child: Text(
              'Lawrence Jing',
              style: TextStyle(
                  fontSize: 50,
                  color: Colors.white,
                  fontFamily: 'Dancing_Script'),
            ),
          ),
          SizedBox(
            height: 10.0,
          ),
          Container(
            child: Text(
              'SERTIFIED CASTING INTERN',
              style: TextStyle(
                  fontSize: 20,
                  color: Colors.white,
                  fontWeight: FontWeight.bold),
            ),
          ),
          Card(
            color: Colors.amberAccent,
            margin: EdgeInsets.fromLTRB(50, 10, 50, 10),
            child: ListTile(
              leading: Row(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  Icon(Icons.school),
                  SizedBox(
                    width: 10.0,
                  ),
                  VerticalDivider(),
                ],
              ),
              title: Text(
                'University of Michigan',
                style: TextStyle(
                  color: Colors.blue,
                  fontSize: 19.0,
                  fontWeight: FontWeight.bold,
                ),
              ),
              enabled: false,
            ),
          ),
          SizedBox(
            height: 23.0,
            width: 200.0,
            child: Divider(
              color: Colors.teal[200],
            ),
          ),
          Card(
            color: Colors.white,
            margin: EdgeInsets.fromLTRB(50, 10, 50, 10),
            child: ListTile(
              leading: Icon(
                Icons.phone,
                color: Colors.teal,
              ),
              title: Text(
                '(650)278-7409',
                style: TextStyle(
                  color: Colors.teal[600],
                  fontSize: 20.0,
                  fontWeight: FontWeight.bold,
                ),
              ),
              enabled: true,
              onTap: () => launch("tel:+1234"),
              onLongPress: () => launch("sms: 1234"),
            ),
          ),
          SizedBox(
            height: 10.0,
          ),
          Card(
            color: Colors.white,
            margin: EdgeInsets.fromLTRB(50, 10, 50, 10),
            child: ListTile(
              leading: Icon(
                Icons.email,
                color: Colors.teal,
              ),
              title: Text(
                '[email protected]',
                style: TextStyle(
                  color: Colors.teal[600],
                  fontSize: 20.0,
                  fontWeight: FontWeight.bold,
                ),
              ),
              enabled: true,
              onTap: () => launch("mailto:email"),
            ),
          ),
          SizedBox(
            height: 10.0,
          ),
          Card(
            color: Colors.white,
            margin: EdgeInsets.fromLTRB(50, 10, 50, 10),
            child: ListTile(
              leading: Icon(
                Icons.account_circle,
                color: Colors.teal,
              ),
              title: Text(
                'LinkedIn',
                style: TextStyle(
                  color: Colors.teal[600],
                  fontSize: 20.0,
                  fontWeight: FontWeight.bold,
                ),
              ),
              enabled: true,
              onTap: () => launch("https://www.linkedin.com/in/lajing/"),
            ),
          ),
          SizedBox(
            height: 10.0,
          ),
          Card(
            color: Colors.white,
            margin: EdgeInsets.fromLTRB(50, 10, 50, 10),
            child: ListTile(
              leading: Icon(
                Icons.code,
                color: Colors.teal,
              ),
              title: Text(
                'GitHub',
                style: TextStyle(
                  color: Colors.teal[600],
                  fontSize: 20.0,
                  fontWeight: FontWeight.bold,
                ),
              ),
              enabled: true,
              onTap: () => launch("https://github.com/LarryJing"),
            ),
          ),
        ],
      ),
    ),
  ),
);}

As you can see, the size of everything is pretty much hardcoded.

Upvotes: 1

Views: 1514

Answers (2)

Nikhil Vadoliya
Nikhil Vadoliya

Reputation: 1578

You should be use SingleChildScrollView as parent of Column so if space not available then it will scrollable (or) you can use ListView instead of Column

For Example

 @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.teal,
        body: SafeArea(
          child: SingleChildScrollView(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Center(
                  child: CircleAvatar(
                    radius: 100.0,
                    backgroundImage: AssetImage('images/headshot.jpg'),
                  ),
                ),
                SizedBox(
                  height: 0.0,
                ),
                Container(
                  child: Text(
                    'Lawrence Jing',
                    style: TextStyle(
                        fontSize: 50,
                        color: Colors.white,
                        fontFamily: 'Dancing_Script'),
                  ),
                ),
                SizedBox(
                  height: 10.0,
                ),
                Container(
                  child: Text(
                    'SERTIFIED CASTING INTERN',
                    style: TextStyle(
                        fontSize: 20,
                        color: Colors.white,
                        fontWeight: FontWeight.bold),
                  ),
                ),
                Card(
                  color: Colors.amberAccent,
                  margin: EdgeInsets.fromLTRB(50, 10, 50, 10),
                  child: ListTile(
                    leading: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        Icon(Icons.school),
                        SizedBox(
                          width: 10.0,
                        ),
                        VerticalDivider(),
                      ],
                    ),
                    title: Text(
                      'University of Michigan',
                      style: TextStyle(
                        color: Colors.blue,
                        fontSize: 19.0,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    enabled: false,
                  ),
                ),
                SizedBox(
                  height: 23.0,
                  width: 200.0,
                  child: Divider(
                    color: Colors.teal[200],
                  ),
                ),
                Card(
                  color: Colors.white,
                  margin: EdgeInsets.fromLTRB(50, 10, 50, 10),
                  child: ListTile(
                    leading: Icon(
                      Icons.phone,
                      color: Colors.teal,
                    ),
                    title: Text(
                      '(650)278-7409',
                      style: TextStyle(
                        color: Colors.teal[600],
                        fontSize: 20.0,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    enabled: true,
                    onTap: () => launch("tel:+1234"),
                    onLongPress: () => launch("sms: 1234"),
                  ),
                ),
                SizedBox(
                  height: 10.0,
                ),
                Card(
                  color: Colors.white,
                  margin: EdgeInsets.fromLTRB(50, 10, 50, 10),
                  child: ListTile(
                    leading: Icon(
                      Icons.email,
                      color: Colors.teal,
                    ),
                    title: Text(
                      '[email protected]',
                      style: TextStyle(
                        color: Colors.teal[600],
                        fontSize: 20.0,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    enabled: true,
                    onTap: () => launch("mailto:email"),
                  ),
                ),
                SizedBox(
                  height: 10.0,
                ),
                Card(
                  color: Colors.white,
                  margin: EdgeInsets.fromLTRB(50, 10, 50, 10),
                  child: ListTile(
                    leading: Icon(
                      Icons.account_circle,
                      color: Colors.teal,
                    ),
                    title: Text(
                      'LinkedIn',
                      style: TextStyle(
                        color: Colors.teal[600],
                        fontSize: 20.0,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    enabled: true,
                    onTap: () => launch("https://www.linkedin.com/in/lajing/"),
                  ),
                ),
                SizedBox(
                  height: 10.0,
                ),
                Card(
                  color: Colors.white,
                  margin: EdgeInsets.fromLTRB(50, 10, 50, 10),
                  child: ListTile(
                    leading: Icon(
                      Icons.code,
                      color: Colors.teal,
                    ),
                    title: Text(
                      'GitHub',
                      style: TextStyle(
                        color: Colors.teal[600],
                        fontSize: 20.0,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    enabled: true,
                    onTap: () => launch("https://github.com/LarryJing"),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

Upvotes: 2

Shubham Gupta
Shubham Gupta

Reputation: 1997

Since you are using SizedBox with the specific height it will overflow if the screen size is small.You can use MediaQuery.of(context).size.height for using height of SizedBox as percentage or screens total height

The second approach would be to use Spacer and Expanded to space the content according to the available space in the Column.

Hope this helps.

Upvotes: 3

Related Questions