Skip to content

Positional parameters being placed after named parameters causes compilation error #2308

Closed as not planned
@youssef-attia

Description

@youssef-attia

What happened?

I expected DartPad to accept positional parameters being placed in any order with named parameters but this is not the case.

Steps to reproduce problem

The minimum case to reproduce the error is:

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const Text(key: Key('hello'), 'hello',);
  }
}

The errors that DartPad returns is:
"Error compiling to JavaScript:
/tmp/dartpadUTEEFM/lib/main.dart:10:18: Error: Constant evaluation error:
return const Text(key: Key('hello'), 'hello');
^
/tmp/dartpadUTEEFM/lib/main.dart:10:28: Context: The variable '(unnamed)' is not a constant, only constant expressions are allowed.
return const Text(key: Key('hello'), 'hello');"

The error can be fixed by changing the line: return const Text(key: Key('hello'), 'hello',); to return const Text('hello', key: Key('hello'),);

Metadata

Metadata

Assignees

No one assigned

    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