Consider (enable use_key_in_widget_constructors lint):
import 'package:flutter/widgets.dart';
class Foo extends StatelessWidget {
final String txt = getNonConstString();
static String getNonConstString() => 'Hello World';
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
It would generate:
class Foo extends StatelessWidget {
final String txt = getNonConstString();
// ^^^^^^^^^^^^^^^^^ const_eval_method_invocation
const Foo({super.key});
//^^^^^ const_constructor_with_field_initialized_by_non_const
static String getNonConstString() => 'Hello World';
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
We should be able to detect that the const version would be invalid and omit the const then.
CC @bwilkerson @srawlins
Consider (enable
use_key_in_widget_constructorslint):It would generate:
We should be able to detect that the
constversion would be invalid and omit theconstthen.CC @bwilkerson @srawlins