Aus öffentlichen Paketdaten erstellte Orientierung.
nb_utils ist ein umfassender Flutter-Paket, der eine Sammlung essenzieller Widgets und Hilfsmethoden bietet, die die App-Entwicklung vereinfachen sollen. Es stellt wiederverwendbare Komponenten und Hilfsfunktionen bereit, die häufige UI- und Logikprobleme lösen und Boilerplate-Code reduzieren. Mit Unterstützung für alle wichtigen Plattformen – Android, iOS, Web, macOS, Windows und Linux – erhöht es die Produktivität von Entwicklern, die plattformübergreifende Anwendungen erstellen. Der Paket ist ideal, um Funktionalitäten mit konsistenten, gut strukturierten Werkzeugen zu beschleunigen.
Anwendungsfälle
Schnelle UI-Prototypenerstellung
Häufige Wiederverwendung von Widgets
Plattformübergreifende Entwicklung
Formularverarbeitungswerkzeuge
Schnellnavigation einrichten
Zustandsverwaltungs-Schnellzugriffe
Hauptmerkmale
Vorab erstellte Benutzeroberflächenkomponenten
Umfangreiche Hilfsmethoden
plattformunabhängiger Entwurf
Einfache Integration über pub
Konsistente Styling-Hilfen
Zeitsparende Entwicklungswerkzeuge
Geeignet für
Anfänger bis fortgeschrittene Flutter-Entwickler
Schnell vorankommende Projektteams
Apps, die konsistente UI-Muster erfordern
Entwickler, die weniger Boilerplate suchen
Projekte mit engen Fristen
Hinweise
Kann die Bundle-Größe leicht erhöhen
Eingeschränkte Anpassungsmöglichkeiten bei einigen Widgets
Abhängig von externen Abhängigkeiten
Am besten mit modularem Architektur verwendet
Nicht geeignet für hochspezialisierte Benutzeroberflächen
Grundkenntnisse in Dart/Flutter erforderlich
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
Show some love and like to support the project
Say Thanks Here
Follow Me on Twitter
Platform Support
Android
iOS
MacOS
Web
Linux
Windows
✔️
✔️
✔️
✔️
✔️
✔️
Installation
Add this package to pubspec.yaml as follows:
$ flutter pub add nb_utils
Import package
import'package:nb_utils/nb_utils.dart';
Initialize nb_utils in main.dart file for initializing Shared Preferences and other variables.
Also you can assign your Chat GPT key here.
/// Open a new screenHomePage().launch(context);
/// Animate the new page (Slide, Rotate, Scale, Fade)HomePage().launch(context, pageRouteAnimation: PageRouteAnimation.Slide);
/// Remove all screens from back stack and opens new screenHomePage().launch(context, isNewTask: true);
// Returns to previous Screenfinish(context);
// Returns to previous Screen with a resultfinish(context, object);
/// Toast a Stringtoast('This is a string');
/// Prints only if in debug or profile mode - (parameter is Object)log('Your string');
voidhideKeyboard(context)
/// If you are opening Dialog in initState method and you want to use BuildContext but yet it is not created,/// You can use afterBuildLayout in initState method like this.afterBuildLayout(() {
// Get Callback after your build widget is rendered
});
/// Get Package Name from Native Platform (Android, iOS)awaitgetPackageName();
/// Get Package Name, Version Code, Version Name (Android, iOS)awaitgetPackageInfo();
/// Return true if Android OS version is above 12Future<bool> isAndroid12Above()
/// Handle error and loading widget when using FutureBuilder or StreamBuilder/// "snap" is the snapShot value we get from FutureBuilder or StreamBuilderreturnsnapWidgetHelper(snap);
/// See the example below. You can Use FutureBuilder or StreamBuilder.FutureBuilder(
builder(_, snap) {
if (snap.hasData) {
returnYourWidget();
} else {
/// This function will handle loading and error automatically./// You can modify loading and error widget in parameters.returnsnapWidgetHelper(snap);
}
}
),
// Basic SnackBarsnackBar(context, title: 'Sample toast'),
// EnhancedsnackBar(
context,
title: 'Sample toast',
textColor: Colors.blue,
backgroundColor: Colors.white,
elevation: 8,
shape: RoundedRectangleBorder(borderRadius: radius(30)),
margin: EdgeInsets.all(16),
duration: 3.seconds,
);
/// To use SharedPreference, you must call initialize() method in main.dart file as mentioned in Installations section/// setValue method has (String key, dynamic value) parameters/// add a Double in SharedPrefawaitsetValue("key", 20.0);
/// add a bool in SharedPrefawaitsetValue("key", false);
/// add a int in SharedPrefawaitsetValue("key", 10);
/// add a String in SharedPrefawaitsetValue("key", "value");
/// add a String List in SharedPrefawaitsetValue("key", ['value', 'value', 'value']);
/// Returns a Bool if exists in SharedPref/// You can set a default value if it returns nullgetBoolAsync("key");
/// Returns a Double if exists in SharedPrefgetDoubleAsync("key");
/// Returns a Int if exists in SharedPrefgetIntAsync("key");
/// Returns a String if exists in SharedPrefgetStringAsync("key");
/// Returns a JSON if exists in SharedPrefgetJSONAsync("key");
/// Remove a key from SharedPrefawaitremoveKey("key");
/// Returns List of Keys that matches with given KeygetMatchingSharedPrefKeys('key')
BorderRadiusradius([double? radius])
RadiusradiusCircular([double? radius])
BorderRadiusradiusOnly({double? topRight,double? topLeft,double? bottomRight,double? bottomLeft,})
ShapeBorderdialogShape([double? borderRadius])
/// Apply default BoxDecoration with default shadow and border radiusContainer(
decoration: boxDecorationDefault(), // You can modify based on your preference
),
InputDecorationdefaultInputDecoration({String? hint, String? label, TextStyle? textStyle})
Widgets
/// Give Blur effect to any widget/// Use Blur widget to know more properiesBlur(
child: AnyWidget(),
)
/// Making an app for Web? You must have to perform something on mouse hover event./// Use HoverWidget to get your widget is being hovering or notHoverWidget(
builder: (_, isHovering) {
returnAnyWidget();
},
),
/// Wrap MaterialApp Widget with RestartAppWidget/// Use: RestartAppWidget.init(context);/// Call above line any where to restart your Flutter app.RestartAppWidget(
child: MaterialApp(),
)
/// Default AppButton/// Use AppButton on your app to try more propertiesAppButton(
text: "Submit",
color: Colors.green, // Optional
onTap: () {
//Your logic
},
),
/// Use PlaceHolderWidget while your network image is loadingPlaceHolderWidget(),
/// Use GradientBorder while your network image is loadingGradientBorder(
gradient: LinearGradient(
colors: [
Colors.orange,
Colors.yellow,
Colors.pink,
],
),
strokeWidth: 4.0,
child: AnyWidget(),
)
/// Use RoundedCheckBox widget to get nicely rounded check box/// It has many optional parameters to get personalized check box widgetRoundedCheckBox(
isChecked: true,
text: 'Remember me',
onTap: (val) {
//
},
),
/// Use SizeListener widget to get callback when its child widget size changesSizeListener(
child: AnyWidget(),
onSizeChange: (size) {
log(size.width.toString());
},
),
/// Add read more button to a long textReadMoreText(
'Long Text',
),
/// Build Horizontal List widget without giving specific height to it.HorizontalList(
itemBuilder: (BuildContext context, int index) {
returnAnyWidget();
},
itemCount: 25,
),
/// Make your Flutter App Responsive in any device out there with Responsive widgetResponsive(
mobile: MobileWidget(),
tablet: TabletWidget(), // Optional
web: WebWidget(), // Optional
),
/// Use SnapHelperWidget to handle loading and error widget automatically/// Still you can specify custom Loader Widget and Error WidgetSnapHelperWidget<T>(
future: future,
onSuccess: (data) {
returnAnyWidget();
},
),
Marquee(
direction: Axis.horizontal,
animationDuration: Duration(milliseconds: 100),
pauseDuration: Duration(milliseconds: 100),
child: Text("Please enter a long text to see the effect of the marquee widget"),
),
/// You can use .timeAgo on a DateTime object like thisString result = DateTime.now().timeAgo;
boolget isToday
boolget isYesterday
boolget isTomorrow
/// return current time in millisecondsintcurrentMillisecondsTimeStamp()
/// return current timestampintcurrentTimeStamp()
boolleapYear(int year)
/// returns how much time ago from timestampStringformatTime(int timestamp)
/// returns number of days in given monthintdaysInMonth(int monthNum, int year)
doublevalidate({double value = 0.0})
boolisBetween(num first, num second)
Sizeget size
Duration Extensions
/// await Duration(seconds: 1).delay();Future<void> get delay
int Extensions
/// Validate given int is not null and returns given value if null.intvalidate({int value = 0})
/// Leaves given height of space ex: 16.height,Widgetget height
/// Leaves given width of space ex: 16.width,Widgetget width
/// HTTP status codeboolisSuccessful()
BorderRadiusborderRadius([double? val])
/// Returns microseconds duration/// 5.microsecondsDurationget microseconds
Durationget milliseconds
Durationget seconds
Durationget minutes
Durationget hours
Durationget days
boolisBetween(num first, num second)
Sizeget size
// return suffix (th,st,nd,rd) of the given month day numberStringtoMonthDaySuffix()
// returns month name from the given intStringtoMonthName({bool isHalfName = false})
// returns WeekDay from the given intStringtoWeekDay({bool isHalfName = false})
List Extensions
/// Validate given List is not null and returns blank list if null.List<T> validate()
/// Generate forEach but gives index for each elementvoidforEachIndexed(voidaction(T element, int index))
intsumBy(intFunction(T) selector)
doublesumByDouble(numFunction(T) selector)
double?averageBy(numFunction(T) selector)
num Extensions
/// Validate given double is not null and returns given value if null.numvalidate({num value = 0})
/// Returns price with currencyStringtoCurrencyAmount()
ScrollController Extensions
ScrollController scrollController = ScrollController();
/// animate to top
scrollController.animToTop();
/// animate to Bottom
scrollController.animToBottom();
/// animate to specific position
scrollController.animateToPosition(20.0);
/// jump to the start of the list without animation
scrollController.jumpToTop();
/// jump to the end of the list without animation
scrollController.jumpToBottom();
/// Change status bar Color and BrightnesssetStatusBarColor(Colors.blue);
setDarkStatusBar();
setLightStatusBar();
/// Show Status BarshowStatusBar();
/// Hide Status BarhideStatusBar();
/// Set orientation to portraitsetOrientationPortrait();
/// Set orientation to landscapesetOrientationLandscape();
/// Get current PlatformName as a StringStringplatformName();
/// Enter FullScreen Mode (Hides Status Bar and Navigation Bar)enterFullScreen();
/// Unset Full Screen to normal state (Now Status Bar and Navigation Bar Are Visible)exitFullScreen();
/// Returns a string from ClipboardFuture<String> paste();
/// Invoke Native method and get resultvar data = awaitinvokeNativeMethod(CHANNEL_NAME, METHOD_NAME, [dynamic arguments]);
/// Pass your token here to get Map<String, dynamic>Map<String, dynamic> JwtDecoder.decode(token);
boolJwtDecoder.isExpired(token);
DateTimeJwtDecoder.getExpirationDate(token);
DurationJwtDecoder.getTokenTime(token);
DurationJwtDecoder.getRemainingTime(token);
Show Dialogs
/// Show Dialog with Default AnimationshowInDialog(context, builder: (context) => AnyWidget());
/// Show Dialog with Rotate AnimationshowInDialog(context, builder: (context) => AnyWidget(), dialogAnimation: DialogAnimation.ROTATE);
/// Show Dialog with Scale AnimationshowInDialog(context, builder: (context) => AnyWidget(), dialogAnimation: DialogAnimation.SCALE);
/// Show Dialog with Top to Bottom AnimationshowInDialog(context, builder: (context) => AnyWidget(), dialogAnimation: DialogAnimation.SLIDE_TOP_BOTTOM);
/// Show Dialog with Bottom to Top AnimationshowInDialog(context, builder: (context) => AnyWidget(), dialogAnimation: DialogAnimation.SLIDE_BOTTOM_TOP);
/// Show Dialog with Left to Right AnimationshowInDialog(context, builder: (context) => AnyWidget(), dialogAnimation: DialogAnimation.SLIDE_LEFT_RIGHT);
/// Show Dialog with Right to Left AnimationshowInDialog(context, builder: (context) => AnyWidget(), dialogAnimation: DialogAnimation.SLIDE_RIGHT_LEFT);
/// Show Confirmation Dialog/// Second parameter is TitleshowConfirmDialog(
context,
'Do you want to logout from the app?',
onAccept: (context) {
//
},
);
Custom Dialogs
AppButton(
text: "Add",
onTap: () {
showConfirmDialogCustom(
context,
title: "Do you want to add this item?",
dialogType: DialogType.ADD,
onAccept: () {
snackBar(context, title: 'Added');
},
);
},
),