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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With