All About Extention
Last updated
Last updated
Sometimes, big steps arenโt that big; actually, you should think just simple, and it will come to your hands at last.CANVA
We will talk more extensions use case scenario. This exists in many other languages. Itโs the main goal, add more options for easy to use. I have more product in apple and google store so more using in every project and Iโve improved my extension at every project.
Letโs write extensions together ๐
Context Extension Samples
Context is the most using object in the flutter, you will see probably wherever in code. We can add main features on the context and we access features everywhere while having context.
I think which more using for my coding life and firstly write main features on context.
Media query needs to calculate device size operation or contains more device metrics.
Theme properties using while draw text style, container or any widget design.
Especially when doing form screen you may need keyboard state so you call just context and do everything now.
Look at this sample code:
Maybe we create some extension with build context. You want to look all context extension, look at this page. Letโs write a few samples together:
Padding Extension We most use padding on screens and add this extension on context and we call in this way: Padding(padding: context.paddingHigh)
Empty Box Sometimes need an empty box between the two widget, use the this way: Column(children:[xWidget,context.emptySizedWidthBoxLow,yWidget])
And I mostly use this extension recently.
Navigation Extension And I mostly use this extension recently so this very useful application routing
The string is a primitive type but weโll gain power so many features very easy use. This variable could be called everywhere but more use string validation, launch(open website or application), format & mask value and etc.
This hex string value to colour, just calls โFF45X2โ.color.
Validator string needs from formfield widget, you can use โisValidEmailโ to the end.
You need string value to trigger in mail application context so call โlaunchEmailโ like WhatsApp share.
String value need mask and unmask options from text field widget so you can call input formatted constants so you would mask on filed and if you want to unmask value call phoneFormatValue to the end.
I prepared more string extension on my package. You can look at other string extension features.
Letโs look at example code:
This one of my favourites extension. I need a widget from the future completed, you could be a future extension. (like service calls etc.)
Itโs a very easy way to manage future result from your widget. This manages success, error and loading case so you can central usage on the app.
Letโs look at the example code:
You create a base to build function and doesnโt need to declare loading, not found and error widget for every request.
I will have added new features in this widget extension so now has just visible extension. Visible need doesnโt data found or other user scenarios.
So let's look at the sample:
This extension just works rotate features on the image. Rotation need in a project because service back to reverse image and I was created this.
This main goal rotates to image base coordinates on the superficial.
Letโs look at the example code:
Finally, itโs everything okay just now :). You can use this extension by pieces or I create Kartal package. Kartal contains this extension and more features.
Thanks for reading ๐โโ๏ธI hope will be a healthy year. We will see new articles โ๏ธ source: https://medium.com/flutter-community/flutter-short-but-golds-3df2b21d877f
Future Extension Sample
Image Rotation Sample