他大家,
我有以下代码的问题:
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,
),
],
),
),
],
);
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用“flutter run”运行它时,它会准确显示我需要的内容,但是当我使用“--release”参数时,它完全停止工作并显示灰屏。任何帮助表示赞赏!
Mar*_*lla 24
您正在使用自己适合Expanded的小部件 (堆栈)。为了修复它,删除Expanded拟合参数并将其应用于您的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,
),
],
)
],
);
}
}
Run Code Online (Sandbox Code Playgroud)
使用调试模式,您会注意到堆栈跟踪告诉您有关该错误的信息。因为--release总是尽量避免问题/崩溃,将禁用 UI 的那部分,又名 = 灰屏。
小智 8
就我而言,调试模式下没有错误或警告。我通过在release mode.
使用Android Studio,
它还会将 apk 保存在Built build\app\outputs\flutter-apk\app-release.apk
| 归档时间: |
|
| 查看次数: |
6265 次 |
| 最近记录: |