Skip to content

[flutter_tools] Auto-detection of unsound null safety should fail for web dev builds #118331

Description

@nshahan

Any application that requires unsound null safety should be forced to pass an explicit flag when running flutter run -d chrome. Auto-detecting unsound null safety should be an error.

It sounds like this is working as intended for all implementations except development mode for the web (JS compiler).

I reproduction case should be to create an app and add a language version comment to the library that contains the entrypoint:

// @dart = 2.11

Then run flutter run -d chrome. It prints a warning but that should be an error.
Running with the explicit flag: flutter run -d chrome --no-sound-null-safety should still work with a warning.

Activity

  1. nshahan commented on Jan 11, 2023

    @nshahan
    ContributorAuthor
  2. danagbemava-nc commented on Jan 12, 2023

    @danagbemava-nc
    Member

    Reproducible using the code sample below.

    code sample
    // @dart = 2.11
    import 'package:flutter/material.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatelessWidget {
      const MyApp({Key key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'ReorderableListView + Dismissible Items'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      const MyHomePage({Key key, @required this.title}) : super(key: key);
    
      final String title;
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
    
      @override
      Widget build(BuildContext context) {
    
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: const Center(
            child: Text('some text'),
          ),
        );
      }
    }
    
    logs
    Launching lib/main.dart on Chrome in debug mode...
    This app is linked to the debug service: ws://127.0.0.1:50964/TFe4lan2NJg=/ws
    Debug service listening on ws://127.0.0.1:50964/TFe4lan2NJg=/ws
    Running without sound null safety ⚠️
    Dart 3 will only support sound null safety, see https://dart.dev/null-safety
    Connecting to VM Service at ws://127.0.0.1:50964/TFe4lan2NJg=/ws
    
    Launching lib/main.dart on macOS in debug mode...
    --- xcodebuild: WARNING: Using the first of multiple matching destinations:
    { platform:macOS, arch:arm64, id:00008103-000329201AD1001E }
    { platform:macOS, arch:x86_64, id:00008103-000329201AD1001E }
    : Error: Library doesn't support null safety.
    // @dart = 2.11
    ^^^^^^^^^^^^^^^
    
    Target kernel_snapshot failed: Exception
    
    Command PhaseScriptExecution failed with a nonzero exit code
    ** BUILD FAILED **
    
    Exception: Build process failed
    Exited
    
    Launching lib/main.dart on iPhone 14 in debug mode...
    Updating project for Xcode compatibility.
    Upgrading project.pbxproj
    Upgrading Runner.xcscheme
    Removing script build phase dependency analysis.
    Xcode build done.                                           34.7s
    Failed to build iOS app
    Error (Xcode): lib/main.dart:1:1: Error: Library doesn't support null safety.
    Could not build the application for the simulator.
    Error launching application on iPhone 14.
    Exited
    
    flutter doctor -v
    [!] Flutter (Channel master, 3.7.0-19.0.pre.13, on macOS 13.1 22C65 darwin-arm64, locale en-GB)
        • Flutter version 3.7.0-19.0.pre.13 on channel master at /Users/nexus/dev/sdks/flutters
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter
          SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK
          checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision f8628b5cb1 (4 hours ago), 2023-01-11 18:48:03 -0800
        • Engine revision 4a8d6866a1
        • Dart version 3.0.0 (build 3.0.0-112.0.dev)
        • DevTools version 2.20.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform
          update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.2)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14C18
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    
    [✓] VS Code (version 1.74.3)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.56.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-arm64   • macOS 13.1 22C65 darwin-arm64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 109.0.5414.87
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
  3. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    platform-webWeb applications specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    a: null-safetySupport for Dart's null safety feature
    and removed
    in triagePresently being triaged by the triage team
    on Jan 12, 2023
  4. added
    P1High-priority issues at the top of the work list
    on Jan 17, 2023
  5. github-actions commented on Mar 4, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  6. locked as resolved and limited conversation to collaborators on Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1High-priority issues at the top of the work lista: null-safetySupport for Dart's null safety featurefound in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versiontoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions