Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Update dart/flutter style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Dec 30, 2021
1 parent e8cd268 commit 299364d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/getting-started/the-first-mile.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ An on-boarding buddy will be assigned to you as part of our on-boarding process.
proper introduction to the team and your on-boarding buddy. Make sure you're free for lunch as we will have a welcome lunch with the team.
Subsequently, you'll be spending most of the day reading through our documentation and setting up your development environment.

### First two week
### First Two Weeks

Most of your first two week will be spent discovering our technologies, process and culture. You will also be spending some
time pair programming with your on-boarding buddy as well as the rest of the team.
Expand Down
10 changes: 5 additions & 5 deletions docs/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import ThemedImage from '@theme/ThemedImage';
/>

Every respectable organization that produces software adheres to certain best practices and conventions. These living documents
represent _our_ best practices and conventions that we developed over time from our experience and observations. We welcome
any improvements and suggestions to these documents, so don't be afraid to contribute!
represent conventions and practices that we consider to be good; that we developed over time from our experience and observations.
We welcome any improvements and suggestions to these documents, so don't be afraid to contribute!

The documents are sorted into three categories:
The documents are divided into three categories:
* [Getting Started](./getting-started/the-first-mile) - Essential information for new developers
* [Collaboration](./collaboration/git-gud.md) - Our conventions and practices
* [Style Guides](./style-guides) - Style guides for different languages (and technical writing)
* [Collaboration](./collaboration/git-gud) - Our conventions and practices
* [Style Guides](./style-guides/dart-flutter-style-guide) - Style guides for different languages (and technical writing)
46 changes: 44 additions & 2 deletions docs/style-guides/dart-flutter-style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,47 @@ sidebar_label: Dart/Flutter Style Guide
---

We follow Effective Dart's [style guide](https://dart.dev/guides/language/effective-dart/style) and
[documentation style guide](https://dart.dev/guides/language/effective-dart/documentation). An exception to this is the
characters line limit. Instead of **_80_** characters, we adhere to a **_120_** characters line limit.
[documentation style guide](https://dart.dev/guides/language/effective-dart/documentation).

## Characters Line Limit.

An exception to Effective Dart is the characters line limit. Instead of **_80_** characters, we adhere to a **_120_** characters line limit.

## Avoid `null` Assertions

Developers may be frustrated with converting nullable types to non-nullable types and forcefully convert a nullable type
using the null assertion operator. However, doing so comes with a loss of static safety. This is undesirable in most cases
since it circumvents the type system and is a potential source of bugs. Instead, the null-aware operator and checking if a
value is null should be performed.

The following section contains counterexamples and the recommended alternatives.

#### Calling a method of a nullable object
```dart
// Bad
String foo = NullableObject!.bar();
// Good
String? foo = NullableObject?.bar();
String foo = NullableObject?.bar() ?? 'default value';
```

#### Assigning a nullable object to a non-nullable object
```dart
// Bad
String foo = bar!;
// Good
final foo = bar;
if (foo == null) {
// Handle logic here
}
// foo is now non-nullable here
```

One caveat is tests. In tests, it is acceptable to use the `null` assertion operator. This is because the brevity and readability
of tests outweighs the loss of static safety. Furthermore, tests are localized and are therefore easier to reason about.

See [Dart null safety](https://dart.dev/null-safety/understanding-null-safety) for more information.
1 change: 1 addition & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const config = {
copyright: `Copyright © ${new Date().getFullYear()} Forus Labs Pte Ltd. Built with Docusaurus.`,
},
prism: {
additionalLanguages: ['dart'],
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
},
Expand Down
Binary file modified static/img/collaboration/create-pull-request-flowchart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 299364d

Please sign in to comment.