Dart & Flutter Code Snippets

Are you a Flutter developer? If so, you’ll know that code snippets can be a life-saver. They’re perfect for when you need to quickly prototype an idea, or when you want to dive into someone else’s code. In this post, we’ve collected some of our favorite Flutter code snippets. Whether you’re just getting started with Flutter or you’re looking for new ways to improve your development process, we hope you find these snippets helpful!

Array & List

Iterate Through a Map
Use await Inside A Loop

Button

Circular Button
Rounded Button

Class & Object

Use the Super Argument
Create Getters and Setters

Container

Add Shadow to a Widget
Glassmorphism Card
Set Min Width and Min Height of a Container

Debug & Profiling

Evaluate a Variable’s Data Type

Device

Get Device Info

Enumeration

Create and Use Enum

File

Read and Write a Text File

Function

Create Genetic Extension
Create Extension Methods
Pass a Method as A Parameter

Icon

Add Launcher Icon
Display Counter Badge above an Icon

Image

Add Grayed Out Effect
The argument type 'ImageNetwork' can't be assigned to the parameter type 'ImageProvider<Object>?'
Set CircleAvatar Size
Image with Bezier Curves
Create a Circular Image
Convert BASE64 String into Image

Keyboard

Hide Soft Keyboard

Layout

Set Widget Center at Middle of Screen
Set Gradient Background Color for a Screen
Responsive Layout
Stack Page with ClipPath Wave
Tik Tok-like Video Player
Desktop Skype-like Chat Box

List

FutureBuilder with ListView

Menu & Navigation

Wave-shaped AppBar
Animated Stack Menu
Gmail Sidebar
Notched Bottom Bar
AppBar with Round Bottom
Override the Back Button in AppBar
Pass Data To Previous Screen
Create a Dropdown
Refresh Currently Active Page

Number

Ectract Number from String

Operating System

Detect Running Platform and Web

Progress Indicator

Progress Indicator with Animation

Text

Rounded Input TextField without Border
Text’s Default Font Size

Theme

Change Background Color of a Screen

Timer

Execute a Function After Delay
Countdown
Call a Function Repeatedly

Troubleshoot

Fix flutter upgrade Command Failed
Fix Unhandled Exception: This widget has been unmounted, so the State no longer has a context
Fix setState() or markNeedsBuild() called during build

Web

Change Page Title Dynamically

Leave a Comment

Your email address will not be published.