Skip to content

Issue with newly added const widgets #119664

@albertodev01

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!

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