📄
FlutterCheatSheet
  • About
  • Flutter web
    • Download in flutter web
    • Fluter run web selain chrome
    • Mengatasi CORS
  • My Note
    • Cara mudah setting Firebase
    • solusi text overflow
    • Setting Firebase Mobile
    • Setting MinSDK Android
    • Run build runner
    • Load Json FromAsset
    • Set Height TabBar
    • WillPopScope
    • Dropdown with null
    • Interview Flutter
    • shortcut android studio
    • Build with different main.dart
    • Validating email
    • search delay
    • Hive
    • penggunaan sort maupun func lain
    • incompatible version of Kotlin.
    • Google Signin error
    • add Map to Map
    • Cors Anywhere
    • run scrcpy simple
    • android studio adb server version (41) doesn't match this client (39); killing
    • Connect adb with hotspot
    • Bloc , intinya...
    • Restorable state
    • Custom Theme DatePicker Flutter
    • membungkus widget dengan tema
    • All About Extention
    • Provider watch read
    • Provider , App works in debug mode but does not work in release mode
    • make extention
    • Sliver app bar
    • Custom Error screen
    • Rename Package
    • error build on AndroidStudio from vscode
    • add tooltip to all widget
    • Textformfield validator
    • Membuat String Rupiah
    • Sort List Dart
    • chart
    • membuat Date time lokal
    • Change default PageTransition
    • Show Hide Password
    • Error UserFriendly
    • Responsive adaptive layout
    • Tips SingleScrollingView
    • Build context
    • FittedBox
    • validation
      • Dropdown validation
    • alertDialog
      • Mixin
      • FocusNode
      • WebView url listener
      • tips statefull pada alertdialog
      • run-code-after-showdialog-is-dismissed
    • Set package in VS Code when creating a project
  • Usefull source
    • Setting JAVA_HOME
    • Tools for Flutter
    • WEBVIEW
    • membuat Marque
    • LazyLoad
    • Tips
      • Penggunaan Const
      • 3 Dots
      • How Disable all Widget
    • List article
    • List Web Complete Tutorial
    • List library
    • Parsing nested Json
    • Future
      • Tips Clean Code
      • Custom Future
      • Chaining Future
      • Catch error
    • Flutter Sample HTTP Request Github with https://reqres.in/
    • Const vs Final
    • Constructor
    • Function
    • Font
    • CRUD
    • Key
    • Free bootcamp
    • State Manajement
      • Provider
  • Widgets
    • Top 5 Box widget
    • Framework library
      • GetFlutter
      • FLUI
    • kumpulan widget
      • Spacer
      • ClipRRect
      • Switch
      • FittedBox
      • List dari Model
      • Dropdown
        • DropDown Multi
    • Deep Dive
      • Button
      • Card
      • Flexible and Expanded
      • Layout Builder
  • Interview Question
    • Kumpulan Pertannyaan Interview
      • Interview Question link Flutter
      • Interview Question With Answer
  • kasus dari stackoverflow
    • Text Red in Hero
    • firebase issued
    • Untitled
  • library
    • Rapido
    • autoscroll text
Powered by GitBook
On this page
  • Context Extension
  • Generally
  • String Extension
  • Future Extension
  • Widget Extension
  • Image Extension

Was this helpful?

  1. My Note

All About Extention

Previousmembungkus widget dengan temaNextProvider watch read

Last updated 4 years ago

Was this helpful?

Sometimes, big steps aren’t that big; actually, you should think just simple, and it will come to your hands at last.

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 so more using in every project and I’ve improved my extension at every project.

Let’s write extensions together 🙏

Context Extension

Context Extension Samples

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.

Generally

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 . 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)

extension PaddingExtension on BuildContext {
EdgeInsets get paddingHigh => EdgeInsets.all(highValue);
EdgeInsets get horizontalPaddingLow => EdgeInsets.symmetric(horizontal: lowValue);
}
  • Empty Box Sometimes need an empty box between the two widget, use the this way: Column(children:[xWidget,context.emptySizedWidthBoxLow,yWidget])

extension SizedBoxExtension on BuildContext {
Widget get emptySizedWidthBoxLow => SpaceSizedWidthBox(width: 0.03);
Widget get emptySizedHeightBoxLow => SpaceSizedHeightBox(height: 0.01);
}

And I mostly use this extension recently.

  • Navigation Extension And I mostly use this extension recently so this very useful application routing

String Extension

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.

Let’s look at example code:

Future Extension

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.

Widget Extension

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.

extension WidgetExtension on Widget { 
 Widget toVisible(bool val) => val ? this : SizedBox(height: 1);
}

So let's look at the sample:

Image Extension

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.

I prepared more string extension on my package. You can other string extension features.

Future Extension Sample

Image Rotation Sample

Thanks for reading 🙋‍♂️I hope will be a healthy year. We will see new articles ☘️ source:

look at
https://medium.com/flutter-community/flutter-short-but-golds-3df2b21d877f
CANVA
apple and google store
Context
page
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post