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

Flutter – New page route is only leading to a blank page

I’ve already created one page route, to the feed_page, but now, when going from feed_page to new_post_page, the new_post_page is just blank on the simulated phone.

Here’s the obligatory code dump 🙂

In this first code dump (page of origin), I omitted the other contents of the appBar and the body of the scaffold:

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

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:we_rise/post_card.dart';
import 'new_post_page.dart';
import 'constants.dart';

class FeedPage extends StatefulWidget {
  @override
  _FeedPageState createState() => _FeedPageState();
}

class _FeedPageState extends State<FeedPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        ...
        ),
        actions: <Widget>[

// PAGE ROUTE IN QUESTION

          IconButton(
            icon: const Icon(Icons.add_circle),
            onPressed: () {
              Navigator.push(
                  context, MaterialPageRoute(builder: (context) => NewPostPage()));
            },
          ),
        ],
      ),
      body: ListView.builder(
        ...
      ),
    );
  }
}

And then the problematic new page that is just showing up blank in the simulated phone:

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

class NewPostPage extends StatefulWidget {
  @override
  _NewPostPageState createState() => _NewPostPageState();
}

class _NewPostPageState extends State<NewPostPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: const Color(0xFFFFC033),
        title: const Text('New Post'),
      ),
      body: Expanded(
        child: Column(
          children: const <Widget>[
            Text('Placeholder')
          ],
        )
      ),
    );
  }
}

>Solution :

Problem is in body, Remove Expanded widget from body only keep Column widget and Run, set as below.

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

class NewPostPage extends StatefulWidget {
  @override
  _NewPostPageState createState() => _NewPostPageState();
}

class _NewPostPageState extends State<NewPostPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: const Color(0xFFFFC033),
        title: const Text('New Post'),
      ),
      body: Column(
          children: const <Widget>[
            Text('Placeholder')
          ],
      ),
    );
  }
}
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