Flutter应用在发布模式下显示白屏?

8
我在Flutter应用程序中遇到了非常奇怪的问题!当我在调试模式下测试我的应用程序时,它工作正常,但在发布模式下却显示白屏。这个应用程序已经在Playstore上发布了。几天后,我改变了这个应用程序。我想发布第二个版本。当我尝试构建发布apk时,在调试模式下工作正常,但在发布模式下显示白屏。为什么会发生这种情况?这是Flutter版本问题吗?

image one

image two

这里是代码

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:tv/Online.dart';
import 'package:tv/paypal.dart';
import 'package:url_launcher/url_launcher.dart';


class Donateus extends StatefulWidget {
  @override
  _DonateusState createState() => _DonateusState();
}

class _DonateusState extends State<Donateus> {
  bool _isExpandedonline=false;
  bool _isExpandedpaypal=false;
  bool _isExpandedetransfer=false;
  bool _isExpandedtexttogive=false;

  void customLaunch(command) async {
    if (await canLaunch(command)) {
      await launch(command);
    } else {
      print(' could not launch $command');
    }
  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child:Padding(
          padding: EdgeInsets.all(10),

          child: Container(
            child:Expanded(
              child: Column(
                children: <Widget>[
                  Text(
                    'WAYS TO DONATE',
                    style: TextStyle(
                      fontFamily: 'TT NORMS',
                      fontSize: 20,
                      fontWeight: FontWeight.w100,
                    ),


                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 10),
                    child: Text(
                      'All of our Donations are processed through Cornerstone Asian Church.We are a registered Canadian Charity (842869265RR0001). A Canadian Tax-deductible receipt will be issued to you.',
                      style: TextStyle(

                          fontSize: 14
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 10),
                    child: ExpansionTile(
                        onExpansionChanged: (value) {
                          _isExpandedonline=value;
                          setState(() {});
                        },
                        children: <Widget>[
                          Text(
                            'Give a single gift, or schedule a recurring amount by using your Credit cards (i.e Mastercard, VISA, AMEX).'
                                'Note: Cornerstone uses the giving provider, Tithe.ly to securely process online donations from all over the world. Our Church will cover all associated fees for this service which are 2.5% + 15 cents (CAD) for all  Credit Cards. AMEX is 3.5% + 30 cents (CAD). However, if you wish to cover the fees as well, you can click on the option to "Cover Fees".',style: TextStyle(

                            fontSize: 14,


                          ),)
                        ],

                        title: Row(
                          children: <Widget>[
                            Image.asset(
                              'images/online.png',
                            ),
                            GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => Online()),
                                );
                              },
                              child: Text(

                                'Online Giving',
                                style: TextStyle(
                                  fontFamily: 'TT NORMS',
                                  fontSize: 18,
                                  fontWeight: FontWeight.w100,
                                  color: _isExpandedonline ? Colors.amber[800] : Colors.black,

                                ),


                              ),

                            )

                          ],


                        )),

                  ),

                  Padding(
                    padding: EdgeInsets.only(left: 10),
                    child: ExpansionTile(
                        onExpansionChanged: (value) {
                          _isExpandedpaypal=value;
                          setState(() {});
                        },
                        children: <Widget>[
                          Text(
                            'You can send your funds through PayPal to email livinghopetv@cornerstoneasianchurch.com',style: TextStyle(
                            fontSize: 14,


                          ),)
                        ],
                        title: Row(
                          children: <Widget>[
                            Image.asset(
                              'images/paypal.png',
                            ),
                            Padding(
                              padding: EdgeInsets.only(left: 10),
                              child: Text(
                                'PAYPAL',
                                style: TextStyle(

                                  fontFamily: 'TT NORMS',
                                  color:_isExpandedpaypal ? Colors.amber[800] : Colors.black,
                                  fontSize: 18,
                                  fontWeight: FontWeight.w100,
                                ),
                              ),
                            ),
                            GestureDetector(
                              onTap: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => paypal()),
                                );
                              },
                              child: Image.asset(
                                'images/donatebutton.png',
                                height: 33,
                              ),
                            )
                          ],
                        )),
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 10),

                    child: ExpansionTile(
                        onExpansionChanged: (value) {
                          _isExpandedetransfer=value;
                          setState(() {});
                        },
                        children: <Widget>[
                          Text(
                            'You can send your funds via Interac E-Transfer to email*',style: TextStyle(
                            fontSize: 14,


                          ),),

                          Text(
                            '
    cacoffering@gmail.com',
                            style: TextStyle(
                              color: Colors.blue,
                              fontSize: 18,

                            ),
                          ),

                          Text(
                            '
    This is an auto-deposit account
    so you you do not have to set up any password.
    Please do indicate the Purpose for your donation.
    This service is only available within Canada.',style: TextStyle(
                            fontSize: 14,


                          ),),
                        ],
                        title: Row(
                          children: <Widget>[
                            Image.asset(
                              'images/etransfer.png',
                              height: 28,
                            ),
                            Text(
                              'INTERAC E-TRANSFER',
                              style: TextStyle(

                                fontFamily: 'TT NORMS',
                                fontSize: 18,
                                fontWeight: FontWeight.w100,
                                color:_isExpandedetransfer? Colors.amber[800] : Colors.black,

                              ),
                            ),
                          ],
                        )),
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 10),
                    child: ExpansionTile(
                        onExpansionChanged: (value) {
                          _isExpandedtexttogive=value;
                          setState(() {});
                        },
                        children: <Widget>[
                          Text('STEP 1: TEXT the word GIVE to',style: TextStyle(
                            fontSize: 14,


                          ),),
                          Text(
                            '(844) 329-1637',
                            style: TextStyle(
                              color: Colors.red,
                            ),
                          ),
                          SizedBox(
                            height: 20,
                          ),
                          Text(
                            'STEP 2: Complete the information on link received via TEXT for the first time only.',style:TextStyle(
                            fontSize: 14,


                          ),),
                          SizedBox(
                            height: 20,
                          ),
                          Text(
                            'STEP 3: Once you are setup for TEXT GIVING you can continue to TEXT the amount without having to fill your information again. Simply TEXT the amounti.e 10, 15 etc to the number directly.',style: TextStyle(
                            fontSize: 14,


                          ),)
                        ],
                        title: Row(
                          children: <Widget>[
                            Image.asset(
                              'images/text.png',
                              height: 30,
                            ),
                            GestureDetector(
                              onTap: () {
                                customLaunch('sms:8443291637');
                              },
                              child: Padding(
                                padding: EdgeInsets.only(left: 10),
                                child: Text(
                                  'TEXT TO GIVE',
                                  style: TextStyle(
                                    fontSize: 18,
                                    fontWeight: FontWeight.w100,
                                    fontFamily: 'TT NORMS',
                                    color:_isExpandedtexttogive? Colors.amber[800] : Colors.black,

                                  ),
                                ),
                              ),
                            )
                          ],
                        )),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

1
嗨,当我不正确地使用Expanded小部件时,我也遇到了同样的问题。你可以分享一下你的代码吗? - Yakhyo Mashrapov
@ Yakhyo Mashrapov 检查代码 - mark anthony
1
只需删除 Expanded 并将 mainAxisSize: MainAxisSize.max, 添加到 Column 中即可。希望这能帮到您。 - Yakhyo Mashrapov
1
@Yakhyo Mashrapov,你是对的,这是扩展小部件错误。 - mark anthony
6个回答

14

问题在于你不能使用Expand作为父级部件,这意味着Expanded小部件必须是后代或父级,在调试模式下,你可以在终端中清楚地看到“Incorrect Usage of Parent Widget”,它会在调试模式下工作,但在发布版本中将显示空白页面,因此请注意上面的警告或错误。

不正确的使用方法

child: Container(
            child:Expanded(
              child: Column(

例子

Expanded(
      child: Container(),
    ),

在行/列中

Row(
  children: [
    Expanded(
      child: MyWidget(),
    ),
    Expanded(
      child:Text("Text Widget"),
    ),
  ],
)

3

当我将gradle版本从gradle-5.6.2-all升级到gradle-6.1.1-all并构建gradle com.android.tools.build:gradle:3.5.0到com.android.tools.build:gradle:4.0.1时,我遇到了问题。

最终,我在app/build.gradle文件中添加了解决方案。

 buildTypes {
    release {
        signingConfig signingConfigs.debug
        shrinkResources false
        minifyEnabled false
        useProguard false
    }
}

3

很不幸,这个问题可能有多个原因。我所遇到的一个原因是,在 Android 构建中,默认情况下似乎已经打开了 minifyEnabled。我进行了如下设置:

shrinkResources false
minifyEnabled false
useProguard false

构建正常运行。 只需将useProguard设置为true,其他设置为false即可像之前一样缩小代码大小;这是由于混淆导致的。 更多信息请参见https://medium.com/@swav.kulinski/flutter-and-android-obfuscation-8768ac544421


这个可以用,谢谢!但是有没有其他的方法可以启用这些配置呢? - VipiN Negi
我不确定你所说的“启用这些配置”是什么意思。这是指Android构建gradle文件。你在寻找什么样的替代方案? - ezaspi

1

请检查 Android 清单文件中的 android.permission.INTERNET 权限。


如我所说,#rstrelba已经被添加了。在第一个版本上工作时它运行良好,并且成功地上传到Playstore。在第二个版本中,我只是添加了推送通知,但当我尝试上传第二个版本时出现了这个问题。 - mark anthony

0

我遇到了同样的问题,而且当然是我的错。 我尝试更改buildconfig.release配置、不同的Gradle版本、删除口味,但实际上这是一个简单的异步错误,其中数据在初始化(提取)之前开始显示。

调试模式下的应用程序运行良好,但在发布模式下却会显示白屏。错误与真正原因完全不同:如果您点击空白屏幕,则会出现以下消息:

E/flutter ( 6149): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Null check operator used on a null value
E/flutter ( 6149): #0      RenderBox.hitTest (package:flutter/src/rendering/box.dart:2234)
E/flutter ( 6149): #1      RenderBoxContainerDefaultsMixin.defaultHitTestChildren.<anonymous closure> (package:flutter/src/rendering/box.dart:2596)
E/flutter ( 6149): #2      BoxHitTestResult.addWithPaintOffset (package:flutter/src/rendering/box.dart:787)
E/flutter ( 6149): #3      RenderBoxContainerDefaultsMixin.defaultHitTestChildren (package:flutter/src/rendering/box.dart:2591)
E/flutter ( 6149): #4      RenderCustomMultiChildLayoutBox.hitTestChildren (package:flutter/src/rendering/custom_layout.dart:412)

0

如果在发布版或配置文件模式下出现空白屏幕,那么 widget 库异常应该放在哪里?您可以在调试应用程序时在调试控制台中捕获异常。

在您的代码中,我看到了无用的 ContainerExpanded widget,在 SingleChildScrollView 内部。考虑将它们删除,这应该会有所帮助。

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child:Padding(
          padding: EdgeInsets.all(10),
          child: Column(
                children: ... 
            ),
          ),
        ),
    );
  }

感谢您的回答,也正确地扩展了小部件错误。 - mark anthony

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接