简体   繁体   English

断言在 Web 版本上失败,但在 iOS Flutter 上成功

[英]Assertion fails on Web version, but succeeds on iOS Flutter

I have a different behaviour when I run my app on Chrome then when I run it on iOS.当我在 Chrome 上运行我的应用程序时,当我在 iOS 上运行它时,我有不同的行为。 It happens when I get to this screen:当我到达此屏幕时会发生这种情况:

import 'dart:io';
import 'package:fixit_shop_flutter/fixit_shop_app/authentication_bloc/user_repository.dart';
import 'package:fixit_shop_flutter/fixit_shop_app/register/bloc/register_bloc.dart';
import 'package:fixit_shop_flutter/fixit_shop_app/register/register_form.dart';
import 'package:fixit_shop_flutter/localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class RegisterScreen extends StatelessWidget {
  final UserRepository _userRepository;

  RegisterScreen({Key key, @required UserRepository userRepository})
      : assert(userRepository != null),
        _userRepository = userRepository,
        super(key: key);

  @override
  Widget build(BuildContext context) {
    dynamic backButton =
        Platform.isIOS ? CupertinoIcons.back : Icons.arrow_back;
    return Stack(
      children: [
        Image.asset('assets/mainBg.png',
            height: MediaQuery.of(context).size.height,
            width: MediaQuery.of(context).size.width,
            fit: BoxFit.cover),
        Scaffold(
          backgroundColor: Colors.transparent,
          appBar: AppBar(
            centerTitle: true,
            elevation: 0,
            title: Text(
              AppLocalizations.instance.text('RegisterScreenTitle'),
//              textAlign: TextAlign.center,
              style: TextStyle(
                  color: Colors.orange,
                  fontSize: 22,
                  fontWeight: FontWeight.w500,
                  letterSpacing: 1),
            ),
            backgroundColor: Colors.transparent,
            leading: IconButton(
                icon: Icon(backButton),
                color: Colors.redAccent,
                onPressed: () {
                  Navigator.pop(context);
                }),
          ),
          body: BlocProvider<RegisterBloc>(
            create: (context) => RegisterBloc(userRepository: _userRepository),
            child: RegisterForm(),
          ),
        ),
      ],
    );
  }
}

If on iOS the screen loads normally, while when running the web version it throws the Another exception was thrown: Failed assertion: boolean expression must not be null error. If on iOS the screen loads normally, while when running the web version it throws the Another exception was thrown: Failed assertion: boolean expression must not be null error. Do you now what could cause this different behaviour?你现在有什么可能导致这种不同的行为吗? I followed all the widgets that pass the userRepository along the tree and is all good..as in fact on iOS runs properly.我跟踪了沿树传递 userRepository 的所有小部件,一切都很好。事实上,在 iOS 上运行正常。

Here is my flutter doctor:这是我的 flutter 医生:

[✓] Flutter (Channel unknown, v1.12.13+hotfix.5, on Mac OS X 10.13.6 17G65, locale en-IT)
    • Flutter version 1.12.13+hotfix.5 at /Users/vinnytwice/Developer/flutter
    • Framework revision 27321ebbad (5 months ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/vinnytwice/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    • CocoaPods version 1.8.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 44.0.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] Connected device (3 available)
    • iPad Pro (10.5-inch) • 23C29147-A4F3-4B9F-8182-9C813D5A54AD • ios            • com.apple.CoreSimulator.SimRuntime.iOS-12-2 (simulator)
    • Chrome               • chrome                               • web-javascript • Google Chrome 81.0.4044.129
    • Web Server           • web-server                           • web-javascript • Flutter Tools

• No issues found!

Do you see anything to update?你看到有什么要更新的吗? I'm on High Sierra so I think I can't go above Flutter version 1.12.13+hotfix.5.我在 High Sierra,所以我想我不能 go 高于 Flutter 版本 1.12.13+hotfix.5。 Also I see that the channel is unknown..could it have something to do with it?我还看到频道是未知的..它与它有关吗? As always many thanks for your time and help.一如既往地感谢您的时间和帮助。 Cheers.干杯。

found the reason.. it wasn't the assertion but the platform check I was doing on backButton , that only included iOS..I added the check for the web and it now works es expected.找到原因..不是断言,而是我在backButton上进行的平台检查,仅包括 iOS ..我添加了对 web 的检查,它现在可以正常工作。 I'll leave the question up as might help others porting their apps to web.我会留下这个问题,因为可能会帮助其他人将他们的应用程序移植到 web。

dynamic backButton;
    if (kIsWeb) {
      backButton = Icons.arrow_back;
    } else if (Platform.isIOS) {
      backButton = CupertinoIcons.back;
    } else {
      backButton = Icons.arrow_back;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM