Skip to content

Issue with newly added const widgets #119664

Closed

Description

@albertodev01

cc @goderbauer

With your recent fix in #119195, this code now works:

void main() {
  runApp(
    const MaterialApp(
      home: Scaffold(
        body: Wrap(
          children: [
            Text('a'),
          ],
        ),
      ),
    ),
  )
}

However, this one does not and even the analyzer complains:

void main() {
  runApp(
    const MaterialApp(
      home: Scaffold(
        body: Column(
          children: [
            Text('a'),
          ],
        ),
      ),
    ),
  )
}

The analyzer:

res

Of course, if you run it you get the error:

Launching lib\main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
lib/main.dart:8:11: Error: Constant evaluation error:
const MaterialApp(
^
/D:/flutter/packages/flutter/lib/src/widgets/basic.dart:4459:34: Context: Binary operator '==' requires receiver constant 'CrossAxisAlignment {}' of type 'Null', 'bool', 'int', 'double', or 'String', but was of type 'CrossAxisAlignment'.

  • 'CrossAxisAlignment' is from 'package:flutter/src/rendering/flex.dart' ('/D:/flutter/packages/flutter/lib/src/rendering/flex.dart').
    }) : assert(crossAxisAlignment != CrossAxisAlignment.baseline || textBaseline != null, 'textBaseline is required if you specify the crossAxisAlignment with CrossAxisAlignment.baseline');

Failed to compile application.


My flutter version is:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 3.7.0-32.0.pre.18, on Microsoft Windows [Version 10.0.19045.2486], locale
it-IT)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.5)
[√] Android Studio (version 2021.2)
[√] IntelliJ IDEA Community Edition (version 2021.3)
[√] IntelliJ IDEA Community Edition (version 2022.2)
[√] Connected device (3 available)
[√] HTTP Host Availability

• No issues found!

Activity

  1. changed the title [-]Issue with newly added `const` object[/-] [+]Issue with newly added `const` widgets[/+] on Feb 1, 2023
  2. self-assigned this
    on Feb 1, 2023
  3. goderbauer commented on Feb 1, 2023

    @goderbauer
    Member
  4. github-actions commented on Mar 3, 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.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions