Closed
Description
This rule will help separate view classes from controllers, data models, etc.
Classes that extend base view classes should not contain logic, except for factory constructors. All logical operators should be prohibited in this classes.
class NoLogicView extends StatelessWidget {
const NoLogicView(this.model);
factory NoLogicView.create(TestModel model) {
if (model.enabled) return NoLogicViewEnabledChild(); // No error Avoid logic in view classes
return NoLogicViewDisabledChild();
}
final TestModel model;
@override
Widget build(BuildContext context) {
return Container(
color: model.enabled ? Colors.red : Colors.grey, // Error Avoid logic in view classes
child: Row(
children: [
if (model.enabled) const SizedBox(height: 10), // Error Avoid logic in view classes
Container(
color: containerColor,
),
],
),
);
}
Color get containerColor => model.enabled ? Colors.red : Colors.grey; // Error Avoid logic in view classes
}
class TestModel {
bool enabled = false;
}
NoLogicView noLogicView = NoLogicView(TestModel());