Season Two: Flutter Short BUT Gold’s

Veli Bacık
4 min readSep 25, 2022

Huhu, the season two has been come. Let’s show what we have in this season and what we can do with a little component.

You can check the first version with this here.

Let’s build new flutter apps with a few codes. My main goal is to show how much flutter or dart strength do we have. Let’s start then this code solution.

Padding

Probably most of using widget is padding, so I made a special class. This class is new edge insets but your custom value on design file.

You should add your other value like general low etc.

Asset Helper

Actually, the other most of used component is image and I need to declare local image path in the class. On this point, I’m going to implement a small singleton pattern design and I called it this class always with this single instance.

Infinity List view

That’s so other important point. Many backend services doesn’t return the whole data for backend usage resources, then going to create pagination. This extension will solve your problem so easily. You just put it in your service call in call back, then that’s it. It’ll be updated for your new response.

Close keyboard

Sometimes need to close keyboard when user touch anywhere in view, so this solution will solve this requirement basically.

After you just wrap your page with this widget and that ready to use.

Page Special Sheet

Maybe if you write flutter on this time, you probably used bottom sheet. In generally, we made some operation with custom ui design code. Thus, its class becomes valuable.

And you can just call this code.

 CustomPage().show(context)

Native Gallery Open

As usually I used many times related gallery operation and customers want to open native gallery. These code helpful when this request come.

Separate Scaffold

Perhaps scaffold widget is the most used component, and sometimes it has depended on complex widget. So I preferred separate all widget to in module folder for manage better.

Finally, it should be like this for folder path.

Cancelable Generic Operation

That’s so so so important ability for me and so easy implementation. Of course, for what? For example, you have a like button and user can be press many times, but you want to call service by last press value. This is the time it will work for your business for your duration time.

Let’s look how we do that:

Finally, you can try like this view, and you should see service call when delayed complete.

Remove Widget

There is so easy and it will save your time sometimes. If you complete flutter setup for VS Code extension etc., you will see remove widget when open the insight. You just change the name child instead of other call like body. Then you can remove sub widget.

Query Values

Service operation like data fetch, update In the base point in mobile project. Many times we need to add some parameter in the request. And I’m using enumeration for these queries with map entry function, and you can use better for constants or etc.

Boolean Checker

Sometimes your backend return the string value directly “true” or “false” and you need to control value check. It will be useful at the time.

And you can use like this:

Text('false'.isTrue ? 'ok' : 'nok');

Durations

I love Icon -> Icons like usage since the day I was started to flutter. This enum like work this. Many times we need to use duration like delay like animation etc. You just add your project time values to your business.

Firebase Collection Extension

Firebase is the most usage package for flutter side, and I’m interested more then Firebase ODM, so we’re getting data services with Firebase references. This mixin will work your generic parse problem so easily.

You can give your reference call in every way it will be going to parse and return like the base model.

\

Finally, the pretty useful article is end. I’ll try to create more short but gold items, and I’ll share the new articles.

While writing flutter, you have many change to “create short but gold” solution. You should be thought OOP and other design patterns thinks. Dart and flutter very convenient like these usages.

You can follow this article at this video

If you follow me on twitter, I’m sharing like these solutions anytime. And I made kartal package on pubdev consisting of these solutions

https://github.com/VB10/short_but_gold

--

--

Veli Bacık

We always change the world, so just want it. [OLD]Google Developer Expert Flutter & Dart, Gamer, Work More!