fluiver
A comprehensive package that includes expressive extensions, common helpers, and essential widgets.
The expressiveness emulates IDE behaviors rather than merely minimizing code verbosity, distinguishing it from the typical approaches of many other packages.
Extensions
BuildContext
Screen Size
context.screenWidth => MediaQuery.of(context).size.width
context.screenHeight => MediaQuery.of(context).size.height
Brightness
context.isPlatformDark => MediaQuery.of(context).platformBrightness == Brightness.dark
context.isPlatformLight => MediaQuery.of(context).platformBrightness == Brightness.light
context.isThemeDark => Theme.of(context).brightness == Brightness.dark
context.isThemeLight => Theme.of(context).brightness == Brightness.light
Orientation
context.isOrientationPortrait => MediaQuery.of(context).orientation == Orientation.portrait
context.isOrientationLandscape => MediaQuery.of(context).orientation == Orientation.landscape
View Padding
context.topViewPadding => MediaQuery.of(context).viewPadding.top
context.bottomViewPadding => MediaQuery.of(context).viewPadding.bottom
context.bottomViewInset => MediaQuery.of(context).viewInsets.bottom
Directionality
context.isLTR => Directionality.of(context) == TextDirection.ltr
context.isRTL => Directionality.of(context) == TextDirection.rtl
ColorScheme
// Formula
Color {$type}Color => Theme.of(context).colorScheme.{$type}Color!
// Examples
Color primaryColor => Theme.of(context).colorScheme.primaryColor
Color tertiaryColor => Theme.of(context).colorScheme.tertiaryColor
Color onErrorColor => Theme.of(context).colorScheme.onErrorColor
TextTheme
// Formula
TextStyle {$type}TextStyle => Theme.of(context).textTheme.{$type}!
// Examples
TextStyle headlineLargeTextStyle => Theme.of(context).textTheme.headlineLarge!
TextStyle bodyLargeTextStyle => Theme.of(context).textTheme.bodyLarge!
TextStyle labelMediumTextStyle => Theme.of(context).textTheme.labelMedium!
BorderRadius
add(double value)
// Formula
myBorderRadius + BorderRadius.add$type$(double value);
addAll
addLeft
addTop
addRight
addBottom
addTopLeft
addTopRight
addBottomRight
addBottomLeft
EdgeInsets
Add(double value)
// Formula
myEdgeInsets + EdgeInsets.add$type$($type$: value);
addAll
addLeft
addTop
addRight
addBottom
Set(double value)
// Formula
myEdgeInsets.copyWith($type$: value);
setLeft
setTop
setRight
setBottom
setHorizontal
setVertical
Only
// Formula
EdgeInsets.only($type$: value);
setLeft
setTop
setRight
setBottom
setHorizontal
setVertical
TextStyle
Color
// Formula
TextStyle get withColor{$type} => textStyle.copyWith(color: {$type});
// Examples
TextStyle get withColorWhite38 => textStyle.copyWith(color: Colors.white38);
TextStyle get withColorWhite => textStyle.copyWith(color: Colors.white);
TextStyle get withColorBlack70 => textStyle.copyWith(color: Colors.black70);
ThemeColor
// Formula
TextStyle get with{$type}Color => textStyle.copyWith(color: Theme.of(context).colorScheme.{$type});
// Example
TextStyle get withPrimaryColor(BuildContext context) => textStyle.copyWith(color: Theme.of(context).colorScheme.primary);
TextStyle get withSecondaryColor(BuildContext context) => textStyle.copyWith(color: Theme.of(context).colorScheme.secondary);
TextStyle get withErrorColor(BuildContext context) => textStyle.copyWith(color: Theme.of(context).colorScheme.error);
FontWeight
// Formula
TextStyle get withWeight{$type} => textStyle.copyWith(fontWeight: FontWeight.w${type});
// Example
TextStyle get withWeight100 => textStyle.copyWith(fontWeight: FontWeight.w100);
TextStyle get withWeight400 => textStyle.copyWith(fontWeight: FontWeight.w400);
TextStyle get withWeight700 => textStyle.copyWith(fontWeight: FontWeight.w700);
TextDecoration
// Formula
with{$type} => textStyle.copyWith(decoration: TextDecoration.{$type});
// Examples
withUnderline => textStyle.copyWith(decoration: TextDecoration.underline);
withOverline => textStyle.copyWith(decoration: TextDecoration.overline);
withLineThrough => textStyle.copyWith(decoration: TextDecoration.lineThrough);
Size
withSize(double size) => textStyle.copyWith(fontSize: size);
DateTime
TimeOfDay toTime(); /// Creates [TimeOfDay] from [DateTime]
DateTime truncateTime(); /// Sets '0' everything other than [year, month, day].
DateTime withTimeOfDay(TimeOfDay time); /// copies [hour, minute] from [time] and sets '0' everything smaller
DateTime addYears(int years);
DateTime addMonths(int months);
DateTime addWeeks(int weeks);
DateTime addDays(int days);
DateTime addHours(int hours);
DateTime addMinutes(int minutes);
DateTime addSeconds(int seconds);
bool get isToday;
bool get isTomorrow;
bool get isYesterday;
bool isWithinFromNow(Duration duration); /// Checks is difference between [DateTime.now()] and [DateTime] is smaller than [duration]
Map
bool any(bool Function(K key, V value) test); // Similar to [Iterable.any]
bool every(bool Function(K key, V value) test); // Similar to [Iterable.every]
MapEntry<K, V>? firstWhereOrNull(bool Function(K key, V value) test); // Similar to [Iterable.firstWhereOrNull]
Map<K, V> where(bool Function(K key, V value) test); // Similar to [Iterable.where]
Map<T, V> whereKeyType<T>(); // Similar to [Iterable.whereType]
Map<K, T> whereValueType<T>(); // Similar to [Iterable.whereType]
MapEntry<K, V>? entryOf(K k); // Similar to `[]` operator but returns [MapEntry]
Set
Set<E> subset(int start, [int? end]); // Creates a new sub [Set]
String
String capitalize();
String capitalizeAll({String separator = ' ', String? joiner});
/// Retrieves first letters of each word separated by [separator] and merge them with [joiner]
String initials({String separator = ' ', String joiner = ''});
Iterable
[1, 2, 3].to2D(2) // [[1, 2], [3]]
[[1, 2], [3]].from2D // [1, 2, 3]
[Foo(), Foo(), Foo()].widgetJoin(() => Divider()) // [Foo(), Divider(), Foo(), Divider(), Foo()]
Iterable<int>
int sum(); // sum of every element
double average(); // average value of iterable
Uint8List toBytes(); // Create a byte array from this
Iterable<double>
double sum(); // sum of every element
double average(); // average value of iterable
IterableNum<T extends num>
T get lowest; // lower value in iterable
T get highest; /// highest value in iterable
Principles
Only commonly needed widgets and helpers are implemented.
For extensions, few comparison will explain the motivation behind.
context.mediaQuery // BAD: therefore, it's not implemented
MediaQuery.of(context) // GOOD: better fast read, more characteristic
// MediaQuery.of(context).viewInsets.bottom
context.mediaQuery.viewInsets.bottom // BAD: number of dots is same
context.bottomViewInset // GOOD: two dots less and decent readability
// Theme.of(context).textTheme.bodyMediumTextStyle!
context.bodyMedium // BAD: less expressive
context.bodyMediumTextStyle // GOOD: more expressive, better auto code-completion
Package Name
Inspired by google/quiver-dart
flutter
+ quiver
= fluiver