- Remove unnecessary
super.key
- Old Constructor was
const Waterlog({super.key});
- The new constructor becomes
const Waterlog({Key? key})
- In Dart, the use of
super.key
is unnecessary when you don't have a superclass constructor that requires a key
. The Waterlog class is not extending any other class that has a constructor with a key
parameter.
- Follow flutter naming conventions
- Flutter follows camelCase convention
// Good naming convention
class MyClass {}
// Bad naming convention
class my_class {}
// example of naming convention in my code
class Waterlog extends StatelessWidget
- Use of descriptive variable and function names
// Good variable name
final String fullName = 'John Doe';
// Bad variable name
final String name = 'John Doe';
// Example of variable names and function names in my code
String? requiredWaterIntake;
void updateRequiredWaterIntake(String? intake) {}
- Single Responsibility Principle
- Each class or function should have a single responsibility and should not be responsible for multiple tasks
// Examples of functions and getters in my code
void updateRequiredWaterIntake(String? intake) {
requiredWaterIntake = intake;
if(kDebugMode) {
print("Updated Water Intake");
}
notifyListeners();
}
String? get waterIntake => requiredWaterIntake;
- Using
const
for values that will not change
- For example, providing padding to a widget where the value is a hardcoded number.
- Since the number is not going to change over time or by any user actions or by pre-programmed actions, we use const for values that are known at compile time to enhance performance and ensure immutability.
padding: const EdgeInsets.symmetric(horizontal: 50.0),