Open
Description
import 'package:flutter/material.dart';
class MyColors {
static const Color primary = Color(0xFF007AFF);
static const Color secondary = Color(0xFF6C757D);
}
const primaryClass = MyColors.primary;
const myColors = (
primary: Color(0xFF007AFF),
secondary: Color(0xFF6C757D),
);
const myColors2 = myColors; // works https://github.com/dart-lang/language/issues/2337
const primaryRecord = myColors.primary; // Error: Const variables must be initialized with a constant value.
If a record is const
, and its entries must be const
, could we get a way to assign it to a constant? Unfortunately I think a const return (const Color get primary
) would need to be present on the getter method. Could we under the hood create a const
instance and replace it inline? This may break some things.
The previous code would generate something like this:
const myColors = (
primary: const Color(0xFF007AFF);
);
const primaryRecord = const Color(0xFF007AFF); // myColors.primary -> const Color(0xFF007AFF);