簡體   English   中英

斷言在 Web 版本上失敗,但在 iOS Flutter 上成功

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

當我在 Chrome 上運行我的應用程序時,當我在 iOS 上運行它時,我有不同的行為。 當我到達此屏幕時會發生這種情況:

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. 你現在有什么可能導致這種不同的行為嗎? 我跟蹤了沿樹傳遞 userRepository 的所有小部件,一切都很好。事實上,在 iOS 上運行正常。

這是我的 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!

你看到有什么要更新的嗎? 我在 High Sierra,所以我想我不能 go 高於 Flutter 版本 1.12.13+hotfix.5。 我還看到頻道是未知的..它與它有關嗎? 一如既往地感謝您的時間和幫助。 干杯。

找到原因..不是斷言,而是我在backButton上進行的平台檢查,僅包括 iOS ..我添加了對 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