Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pageview display grey screen when in release mode

Tags:

flutter

He everyone,

I have an issue with the following code:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Expanded(
          child: PageView(
            children: <Widget>[
              Container(
                color: Colors.red,
              ),
              Container(
                color: Colors.yellow,
              ),
              Container(
                color: Colors.green,
              ),
              Container(
                color: Colors.blue,
              ),
            ],
          ),
        ),
      ],
    );
  }
}

When I run it using "flutter run" it displays exactly what I need but when I use the "--release" parameter it completely stops working and displays a grey screen. Any help is appreciated!

like image 657
maplesyrup Avatar asked Feb 19 '20 04:02

maplesyrup


1 Answers

You're using Expanded inside a Widget (Stack) who has its own fit. In order to fix it, remove Expanded and apply the fit parameter to your Stack

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<ThisApp> {
  @override
  Widget build(BuildContext context) {
    return Stack(
      fit: StackFit.expand, // StackFit.expand fixes the issue
      children: <Widget>[
        PageView(
          children: <Widget>[
            Container(
              color: Colors.red,
            ),
            Container(
              color: Colors.yellow,
            ),
            Container(
              color: Colors.green,
            ),
            Container(
              color: Colors.blue,
            ),
          ],
        )
      ],
    );
  }
}

Using debug mode, you'd notice the stack trace telling your about that error. Because --release always try to avoid issues/crashes, will disable that part of the UI, aka = grey screen.

like image 161
Mariano Zorrilla Avatar answered Oct 23 '22 20:10

Mariano Zorrilla