0% found this document useful (0 votes)
132 views10 pages

Naming Convention - Dart

The document provides naming conventions and best practices for Dart code. It recommends using UpperCamelCase for classes and enums, snake_case for libraries and packages, lowerCamelCase for variables, functions and methods. It also recommends specifying types, using is operator instead of as, using curly braces for flow control statements and following other naming and code structure guidelines.

Uploaded by

Jannatul Jannat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views10 pages

Naming Convention - Dart

The document provides naming conventions and best practices for Dart code. It recommends using UpperCamelCase for classes and enums, snake_case for libraries and packages, lowerCamelCase for variables, functions and methods. It also recommends specifying types, using is operator instead of as, using curly braces for flow control statements and following other naming and code structure guidelines.

Uploaded by

Jannatul Jannat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Classes, enums, typedefs, and extensions

name should =UpperCamelCase

class MainScreen { ... }


enum MainItem { .. }
typedef Predicate<T> = bool Function(T value);
extension MyList<T> on List<T> { ... }
Libraries, packages, directories, and source files
name should be in =
snake_case(lowercase_with_underscores)

● 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

Usually, The as cast operator throws an exception if the cast is not


possible. To avoid an exception being thrown, one can use is.

//Bad Prectice

● (item as Animal).name = 'Lion';

//good prectice

if (item is Animal)
item.name = 'Lion';
DON’T explicitly name libraries

//Bad Prectice

● library my_library;

Good

import asynchronous_package as async_pkg;


DO use curly braces for all flow
control statements

//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

2.Avoiding static/hard coded strings in the UI screens.

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.

4.When setState() is called on a State, all descendent widgets will


rebuild. Therefore, Split widget into small widgets so the setState() call
rebuilds only the part of the subtree, whose UI actually needs to change.

You might also like