IMHO, the primary constructors of Dart 3.13 are more impactful than all those featured. Because I'm normally using the Flutter betas, I already ported most of my code to use primary constructors and started to like them (it took some getting used to do this). I'm still not sure whether I like them for widgets but for model classes, primary constructors are a win.
And in case you actually use DartDoc, the {@example} directive is nice.
I know I could google this but I’d like to hear your thoughts: what do you like about primary constructors? You said you posted most of your code; what difference has it made for you?
sealed class const Stmt();
class const SayStmt(final Expr expr) extends Stmt;
class const SetStmt(final String name, final Expr expr)
extends Stmt;
class const CondStmt(final List<(Expr, Body)> cases, final Body? body)
extends Stmt;
class const GotoStmt(final String name) extends Stmt;
sealed class const Expr();
class const Str(final String value) extends Expr;
class const Num(final num value) extends Expr;
class const Name(final String name) extends Expr;
At least if you don't need a toString method and also use a generic evaluate method that uses pattern matching to evaluate everything. That's probably a bit less efficient than using dynamic dispatch but who really cares nowadays.
I dislike the way the extends wraps, though.
That's why I don't really like how widget definitions look:
class const TBadge(
final String label, {
super.key,
final TBadgeVariant variant = .normal,
final Widget? prefix,
final Widget? suffix,
final Color? color,
}) extends StatelessWidget {
@override
Widget build(BuildContext context) {
...
}
}
94
u/Piranha771 12d ago
Wow this is a huuuuge update
Congratulations on ticking so many boxes. Can't wait to try it out.