Naming Convention - Dart
Naming Convention - Dart
● library firebase_dynamic_links;
● import 'socket/socket_manager.dart';
Variables, constants, parameters, and named
parameters should be in = lowerCamelCase
● var item;
● const bookPrice = 3.14;
● final urlScheme = RegExp('^([a-z]+):');
Use lowerCamelCase for function, and
method names.
● For example,
myVariable, calculateTotalAmount()
Specify types for class member
Always specify the type of member when its value type is known. Avoid using var when possible.
//Bad Prectice
● var item = 10; * final car = Car(); * const timeOut = 2000;
//good prectice
int item = 10;
final Car bar = Car();
String name = 'john';
const int timeOut = 2000;
Avoid using as instead, use is operator
//Bad Prectice
//good prectice
if (item is Animal)
item.name = 'Lion';
DON’T explicitly name libraries
//Bad Prectice
● library my_library;
Good
//Bad Prectice
if (overflowChars != other.overflowChars)
return overflowChars < other.overflowChars;
//Good prectice
if (overflowChars != other.overflowChars) {
return overflowChars < other.overflowChars;
}
Remember:1
1.Use Names That Are Detailed and Clear
2.Observe the Dart Package Naming Guidelines
3.File names should contain singular nouns.
4.PascalCase should be used for class and type names.
5.File Names with Prefixes for Related Components
6.Don’t use acronyms or abbreviations
7.Avoid large trees, split your code into small widgets
instead
8.DON’T use a leading underscore for identifiers that
aren’t private
9.DON’T use prefix letters
10.Avoid checking in comments that ask questions
Remember:2
1.Private variables names preceded with underscores
3.When working with infinite lists or very large lists, ListView .builder is
used in order to improve performance
Split the widget into different Widgets.