nb_utils
library
Functions
afterBuildCreated (dynamic onCreated ()? )
→ void
appBarWidget (String title , {Widget ? child , Widget ? titleWidget , List <Widget > ? actions , Color ? color , bool center = false , Color ? textColor , int textSize = 20 , bool showBack = true , Color ? shadowColor , double ? elevation , Widget ? backWidget , Brightness ? brightness , SystemUiOverlayStyle ? systemUiOverlayStyle , TextStyle ? titleTextStyle , PreferredSizeWidget ? bottom , Widget ? flexibleSpace })
→ AppBar
Default AppBar
boldTextStyle ({int ? size , Color ? color , FontWeight ? weight , String ? fontFamily , double ? letterSpacing , FontStyle ? fontStyle , double ? wordSpacing , TextDecoration ? decoration , TextDecorationStyle ? textDecorationStyle , TextBaseline ? textBaseline , Color ? decorationColor , Color ? backgroundColor , double ? height })
→ TextStyle
Styles
boxDecorationDefault ({BorderRadiusGeometry ? borderRadius , Color ? color , Gradient ? gradient , BoxBorder ? border , BoxShape ? shape , BlendMode ? backgroundBlendMode , List <BoxShadow > ? boxShadow , DecorationImage ? image })
→ Decoration
boxDecorationRoundedWithShadow (int radiusAll , {Color backgroundColor = whiteColor , Color ? shadowColor , double ? blurRadius , double ? spreadRadius , Offset offset = const Offset(0.0, 0.0) , LinearGradient ? gradient })
→ Decoration
rounded box decoration with shadow
boxDecorationWithRoundedCorners ({Color backgroundColor = whiteColor , BorderRadius ? borderRadius , LinearGradient ? gradient , BoxBorder ? border , List <BoxShadow > ? boxShadow , DecorationImage ? decorationImage , BoxShape boxShape = BoxShape.rectangle })
→ Decoration
rounded box decoration
boxDecorationWithShadow ({Color backgroundColor = whiteColor , Color ? shadowColor , double ? blurRadius , double ? spreadRadius , Offset offset = const Offset(0.0, 0.0) , LinearGradient ? gradient , BoxBorder ? border , List <BoxShadow > ? boxShadow , DecorationImage ? decorationImage , BoxShape boxShape = BoxShape.rectangle , BorderRadius ? borderRadius })
→ Decoration
box decoration with shadow
buildTitleWidget (BuildContext context , DialogType dialogType , Color ? primaryColor , Widget ? customCenterWidget , double height , double width , String ? centerImage , ShapeBorder ? shape )
→ Widget
title for dialog
clearSharedPref ()
→ Future <bool >
clear SharedPref
countDays (int difference )
→ String
Converts the time difference to a number of days.
This function truncates to the lowest day.
returns ("1 day" OR "X days")
countHours (int difference )
→ String
Converts the time difference to a number of hours.
This function truncates to the lowest hour.
returns ("1 hour" OR "X hours")
countMinutes (int difference )
→ String
Converts the time difference to a number of minutes.
This function truncates to the lowest minute.
returns ("1 minute" OR "X minutes")
countMonths (int difference )
→ String
Converts the time difference to a number of months.
This function rounds to the nearest month.
returns ("1 month" OR "X months" OR "1 year")
countSeconds (int difference )
→ String
Converts the time difference to a number of seconds.
This function truncates to the lowest second.
returns ("Just now" OR "X seconds")
countWeeks (int difference )
→ String
Converts the time difference to a number of weeks.
This function truncates to the lowest week.
returns ("1 week" OR "X weeks" OR "1 month")
countYears (int difference )
→ String
Converts the time difference to a number of years.
This function truncates to the lowest year.
returns ("1 year" OR "X years")
createMaterialColor (Color color )
→ MaterialColor
Returns MaterialColor from Color
createRichText ({required List <TextSpan > list , TextOverflow overflow = TextOverflow.clip , int ? maxLines , TextAlign textAlign = TextAlign.left , TextDirection ? textDirection , StrutStyle ? strutStyle })
→ RichText
currentMillisecondsTimeStamp ()
→ int
return current time in milliseconds
currentTimeStamp ()
→ int
return current timestamp
daysInMonth (int monthNum , int year )
→ int
returns number of days in given month
defaultBoxShadow ({Color ? shadowColor , double ? blurRadius , double ? spreadRadius , Offset offset = const Offset(0.0, 0.0) })
→ List <BoxShadow >
default box shadow
defaultInputDecoration ({String ? hint , String ? label , TextStyle ? textStyle })
→ InputDecoration
returns default InputDecoration for AppTextField widget
defaultPlaceHolder (BuildContext context , DialogType dialogType , double ? height , double ? width , Color ? primaryColor , {Widget ? child , ShapeBorder ? shape })
→ Widget
placeholder for dialog
dialogAnimatedWrapperWidget ({required Animation <double > animation , required Widget child , required DialogAnimation dialogAnimation , required Curve curve })
→ Widget
dialogShape ([double ? borderRadius ])
→ ShapeBorder
dynamicAppButtonPadding (BuildContext context )
→ EdgeInsets
enterFullScreen ()
→ void
exitFullScreen ()
→ void
finish (BuildContext context , [Object ? result ])
→ void
Go back to previous screen.
formatTime (int timestamp )
→ String
returns how much time ago from timestamp
FToastBuilder ()
→ TransitionBuilder
Simple builder method to create a TransitionBuilder
and for the use in MaterialApp builder method
getBool (String key , {dynamic defaultValue = false })
→ Future <bool >
Returns a Bool if exists in SharedPref
getBoolAsync (String key , {bool defaultValue = false })
→ bool
Returns a Bool if exists in SharedPref
getCenteredImage (BuildContext context , DialogType dialogType , Color ? primaryColor )
→ Widget ?
Build center image for dialog
getColorFromHex (String hexColor , {Color ? defaultColor })
→ Color
Returns Color from hex String.
getColorFromImage (Image image , [int quality = 10 ])
→ Future <List <int > ? >
get colors used in image
getDialogPrimaryColor (BuildContext context , DialogType dialogType , Color ? primaryColor )
→ Color
dialog primary color
getDouble (String key , {dynamic defaultValue = 0.0 })
→ Future <double >
Returns a Double if exists in SharedPref
getDoubleAsync (String key , {double defaultValue = 0.0 })
→ double
Returns a Double if exists in SharedPref
getIcon (DialogType dialogType , {double ? size })
→ Widget
get icon for dialog
getInt (String key , {dynamic defaultValue = 0 })
→ Future <int >
Returns a Int if exists in SharedPref
getIntAsync (String key , {int defaultValue = 0 })
→ int
Returns a Int if exists in SharedPref
getJSONAsync (String key , {Map <String , dynamic > ? defaultValue })
→ Map <String , dynamic >
Returns a JSON if exists in SharedPref
getMatchingSharedPrefKeys (String key )
→ List <String >
Returns List of Keys that matches with given Key
getMaterialYouColors ()
→ Future
Returns material you colors from Android
getMaterialYouPrimaryColor ()
→ Future <Color >
Returns primary color for material you theme
getMaterialYouTheme ()
→ Future <ThemeData >
Returns material you ThemeData
getPackageInfo ()
→ Future <PackageInfoData >
getPackageName ()
→ Future <String >
Get Package Name
getPositiveText (DialogType dialogType )
→ String
build positive text for dialog
getSelectedLanguageModel ({String ? defaultLanguage })
→ LanguageDataModel ?
getSharedPref ()
→ Future <SharedPreferences >
Returns SharedPref Instance
getSocialMediaLink (LinkProvider linkProvider , {String url = '' })
→ String
Use getSocialMediaLink function to build social media links
getString (String key , {dynamic defaultValue = '' })
→ Future <String >
Returns a String if exists in SharedPref
getStringAsync (String key , {String defaultValue = '' })
→ String
Returns a String if exists in SharedPref
getStringListAsync (String key )
→ List <String > ?
Returns a StringList if exists in SharedPref
getTitle (DialogType dialogType )
→ String
Build title
hasMatch (String ? s , String p )
→ bool
has match return bool for pattern matching
hideKeyboard (dynamic context )
→ void
Hide soft keyboard
hideStatusBar ()
→ Future <void >
This function will hide status bar
initialize ({double ? defaultDialogBorderRadius , List <LanguageDataModel > ? aLocaleLanguageList , String ? defaultLanguage })
→ Future <void >
invokeNativeMethod <T > (String channel , String method , [dynamic arguments ])
→ Future <T? >
Invoke Native method and get result
isAndroid12Above ()
→ Future <bool >
Return true if Android OS version is above 12
isConnectedToMobile ()
→ Future <bool >
returns true if connected to mobile
isConnectedToWiFi ()
→ Future <bool >
returns true if connected to wifi
isNetworkAvailable ()
→ Future <bool >
returns true if network is available
isSnapshotLoading (AsyncSnapshot snap , {bool checkHasData = false })
→ bool
Returns true is snapshot is loading
launchNewScreen <T > (BuildContext context , String tag )
→ Future <T? >
Go to new screen with provided screen tag.
launchNewScreenWithNewTask <T > (BuildContext context , String tag )
→ Future <T? >
Removes all previous screens from the back stack and redirect to new screen with provided screen tag
leapYear (int year )
→ bool
return true if given year is an leap year
log (Object ? value )
→ void
Prints only if in debug or profile mode
mailTo ({required List <String > to , String subject = '' , String body = '' , List <String > cc = const [] , List <String > bcc = const [] })
→ Uri
mailto: function to open native email app
makeNullable <T > (T? value )
→ T?
Make any variable nullable
onError (Object o )
→ Future <Null >
use this for catchError in Future functions
paste ()
→ Future <String >
Returns a string from Clipboard
pasteObject ()
→ Future
Returns a string from Clipboard
platformName ()
→ String
Returns current PlatformName
pop ([Object ? object ])
→ void
Dispose current screen or close current dialog
primaryTextStyle ({int ? size , Color ? color , FontWeight ? weight , String ? fontFamily , double ? letterSpacing , FontStyle ? fontStyle , double ? wordSpacing , TextDecoration ? decoration , TextDecorationStyle ? textDecorationStyle , TextBaseline ? textBaseline , Color ? decorationColor , Color ? backgroundColor , double ? height })
→ TextStyle
push <T > (Widget widget , {bool isNewTask = false , Duration ? duration })
→ Future <T? >
Redirect to given widget without context
radians (double degrees )
→ double
radius ([double ? radius ])
→ BorderRadius
returns Radius
radiusCircular ([double ? radius ])
→ Radius
returns Radius
radiusOnly ({double ? topRight , double ? topLeft , double ? bottomRight , double ? bottomLeft })
→ BorderRadius
returns custom Radius on each side
removeKey (String key )
→ Future <bool >
remove key from SharedPref
scrollBehaviour ()
→ (Widget Function(BuildContext , Widget ? ) ?)
Custom scroll behaviour
secondaryTextStyle ({int ? size , Color ? color , FontWeight ? weight , String ? fontFamily , double ? letterSpacing , FontStyle ? fontStyle , double ? wordSpacing , TextDecoration ? decoration , TextDecorationStyle ? textDecorationStyle , TextBaseline ? textBaseline , Color ? decorationColor , Color ? backgroundColor , double ? height })
→ TextStyle
setBool (String key , bool value )
→ Future <bool >
add a Bool in SharedPref
setBoolAsync (String key , bool value )
→ Future <bool >
add a Bool in SharedPref
setDarkStatusBar ()
→ void
Dark Status Bar
setDouble (String key , double value )
→ Future <bool >
add a Double in SharedPref
setDoubleAsync (String key , double value )
→ Future <bool >
//////////////////////////////////////////////////////////////////// DEPRECATED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
add a Double in SharedPref
setInt (String key , int value )
→ Future <bool >
add a Int in SharedPref
setIntAsync (String key , int value )
→ Future <bool >
add a Int in SharedPref
setJSONAsync (String key , String value )
→ Future <bool >
add a JSON in SharedPref
setLightStatusBar ()
→ void
Light Status Bar
setOrientationLandscape ()
→ void
Set orientation to landscape
setOrientationPortrait ()
→ void
Set orientation to portrait
setStatusBarColor (Color statusBarColor , {Color ? systemNavigationBarColor , Brightness ? statusBarBrightness , Brightness ? statusBarIconBrightness , int delayInMilliSeconds = 200 })
→ Future <void >
Change status bar Color and Brightness
setString (String key , String value )
→ Future <bool >
add a String in SharedPref
setStringAsync (String key , String value )
→ Future <bool >
add a String in SharedPref
setValue (String key , dynamic value , {bool print = true })
→ Future <bool >
Add a value in SharedPref based on their type - Must be a String, int, bool, double, Map<String, dynamic> or StringList
showBottomSheetOrDialog ({required BuildContext context , required Widget child , BottomSheetDialog bottomSheetDialog = BottomSheetDialog.Dialog })
→ Future
showConfirmDialog <bool > (dynamic context , String title , {String positiveText = 'Yes' , String negativeText = 'No' , Color ? buttonColor , Color ? barrierColor , bool? barrierDismissible , Function ? onAccept })
→ Future <bool? >
show confirm dialog box
showConfirmDialogCustom (BuildContext context , {required dynamic onAccept (BuildContext ), String ? title , String ? subTitle , String ? positiveText , String ? negativeText , String ? centerImage , Widget ? customCenterWidget , Color ? primaryColor , Color ? positiveTextColor , Color ? negativeTextColor , ShapeBorder ? shape , dynamic onCancel (BuildContext )?, bool barrierDismissible = true , double ? height , double ? width , bool cancelable = true , Color ? barrierColor , DialogType dialogType = DialogType.CONFIRMATION , DialogAnimation dialogAnimation = DialogAnimation.DEFAULT , Duration ? transitionDuration , Curve curve = Curves.easeInBack })
→ Future <bool ? >
show confirm dialog box
showInDialog <T > (BuildContext context , {Widget ? title , Widget ? child , Widget ? builder (BuildContext )?, ShapeBorder ? shape , TextStyle ? titleTextStyle , EdgeInsetsGeometry ? contentPadding , Color ? backgroundColor , DialogAnimation dialogAnimation = DialogAnimation.DEFAULT , double ? elevation , Color ? barrierColor , List <Widget > ? actions , bool barrierDismissible = true , bool hideSoftKeyboard = true , Duration ? transitionDuration , Curve curve = Curves.easeInBack })
→ Future <T? >
show child widget in dialog
showStatusBar ()
→ Future <void >
This function will show status bar
snackBar (BuildContext context , {String title = '' , Widget ? content , SnackBarAction ? snackBarAction , Function ? onVisible , Color ? textColor , Color ? backgroundColor , EdgeInsets ? margin , EdgeInsets ? padding , Animation <double > ? animation , double ? width , ShapeBorder ? shape , Duration ? duration , SnackBarBehavior ? behavior , double ? elevation })
→ void
Show SnackBar
snapWidgetHelper <T > (AsyncSnapshot <T > snap , {Widget ? errorWidget , Widget ? loadingWidget , String ? defaultErrorMessage , bool checkHasData = false , Widget errorBuilder (String )? })
→ Widget
Handle error and loading widget when using FutureBuilder or StreamBuilder
splashDelay ({int second = 2 })
→ Future <void >
Use this if you want to skip splash delay above Android 12
toast (String ? value , {ToastGravity ? gravity , dynamic length = Toast.LENGTH_SHORT , Color ? bgColor , Color ? textColor , bool print = false })
→ void
Toast for default time
toastLong (String ? value , {BuildContext ? context , ToastGravity gravity = ToastGravity.BOTTOM , dynamic length = Toast.LENGTH_LONG , Color ? bgColor , Color ? textColor , bool print = false })
→ void
Toast for long period of time
toasty (BuildContext context , String ? text , {ToastGravity ? gravity , dynamic length = Toast.LENGTH_SHORT , Color ? bgColor , Color ? textColor , bool print = false , bool removeQueue = false , Duration duration = const Duration(seconds: 2) , BorderRadius ? borderRadius , EdgeInsets ? padding })
→ void
Toast with Context