处于释放模式时,网页浏览显示灰屏 [英] Pageview display grey screen when in release mode
问题描述
大家好,
我对以下代码有疑问:
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,
),
],
),
),
],
);
}
}
当我使用"flutter run"运行它时,它会完全显示我需要的内容,但是当我使用"--release"参数时,它将完全停止工作并显示灰屏.感谢您的帮助!
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!
推荐答案
您正在小部件 (堆栈) Expanded
>谁适合自己.为了对其进行修复,请删除 Expanded
并将fit参数应用于您的 Stack
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,
),
],
)
],
);
}
}
使用调试模式,您会注意到堆栈跟踪告诉您有关该错误的信息.由于--release
始终会尝试避免出现问题/崩溃,因此将禁用UI的那部分,即=灰色屏幕.
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.
这篇关于处于释放模式时,网页浏览显示灰屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!