Today, I’m going to show you 4 very useful Flutter tricks that you can apply to your project right away. I won’t show you any packages or extensions as usual, but very simple but very useful tips!

Easier asset management

Managing assets can be very difficult. If you want to use the image multiple times in your application, you must specify the path again and again. But there is a simpler solution. Create an app asset class that stores all your app assets. Now you can use or easily invoke your assets.AppAssets.appLogoAppAssets.noConnection

Easier to import references

Seeing and managing thousands of imports at the beginning of a file is really annoying. That is why I will show you an easy way to reduce imports.

Suppose you have a folder Constants that contains files, , and .app_colors.dartapp_fonts.dartapp_theme.dartapp_assets.dart

In this folder, you now create a new file named constants.dart.

Here, you write an export statement for each file. Now you can access each of your files by simply importing constants.dart:

Remove the splash effect from the button

When you click the button, everyone knows about this splash effect, and I don’t like it at all.

So, I’m going to show you how to eliminate this effect with a single line.

To do this, you must use:splashFactory

Now your button looks like this when pressed:

(I keep clicking on the button)

Simpler platform-specific widgets

When you ask if a user is on iOS or Android, every Flutter developer probably knows this. As a result, you will then display specific wdigets, such as Switch or CupertinoSwitch. But what if I tell you you don’t need a query and you don’t need two widgets? How is it? Well, here’s what I’m going to show you right now:

Many widgets for Android and iOS have extensions in the Android version. For example, let’s build a switch with .adaptive:.adaptive

Okay, that’s good enough, but the best is yet to come: this also applies to icons. To do this, all you have to do is show the share icon on Android and iOS.Icons.adaptive.share

I don’t know exactly which widgets all of these apply to, but this feature applies to, and anyway, this feature applies to, and .SliderSwitchListTileCircularProgressIndicator

Visibility widget

Using a bool to query whether a widget should be visible typically looks like this:

But there is also a widget called Visibility:

That looks a lot better, right?

conclusion

Now we have completed today’s article. I really hope you enjoy these tricks.