Skip to content

Instantly share code, notes, and snippets.

@mohammadkarbalaee
Last active March 8, 2023 17:42
Show Gist options
  • Save mohammadkarbalaee/cc48fa814c354ff822d497686febc46d to your computer and use it in GitHub Desktop.
Save mohammadkarbalaee/cc48fa814c354ff822d497686febc46d to your computer and use it in GitHub Desktop.
Daily Flutter experiences and tips and tricks which I learn along the way. I will store the tips of each day separately on a markdown file.

StateFulBuilder

the variable which the state inside StateFulBuilder is dependant on should be defined outside the builder method of StateFulBuilder. If it is defined inside, It will not have any affect.

Container Color

A container should have either its color specified or its decoration specified. They cannot be mixed up. If you want to use both of them, the trick is to define the color inside BoxDecoration and pass it through the decoration field of your Container.

Request body!!!

Watch out for this huge mistake. When you want to construct a map as body, do not use the key and value with the same property. Dart will not throw an error because key of the map can be dynamic so as the value.

here is an example of the mistake.

var code = "string";

{ code: code }

this is a valid Map object in dart, but not for us.

The correct syntax would be,

{ "code": code }

Null.toString()

null.toString() can be called and no error happens, the result will be "null". watch out.

Async function in SetState

Functions inside SetState have to be synchronous so don't put await inside SetState.

ScrollController

A single instance of ScrollController cannot be attached to multiple widgets.

ValueListenableBuilder inside GetX project

It is wrong to use this inside such type of project since it does not render inside GetX's widget tree. Anyway, it is silly to mix state management methods up.

Positioned

when you nest positioned widget inside a stack, it cannot have a parent widget. which means, the Positioned widget has to be the direct child of Stack to work properly

Format file in Android studio

the shortcut it this. ctlr + alt + shift + L

Importing

don't use "relative path" instead use "package" for your imports. For fucks sake bro. for fucks sake.

DataTime

DateTime class is inbuilt in dart and can parse date strings. just call the parse method of this class and you are good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment