supercharged 1.6.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 98

⚡️ Supercharged #

Pub Tests

Supercharged brings all the comfort features from languages like Kotlin to all Flutter developers.

  • 💪 fully tested
  • 📝 well documented
  • 💼 enterprise-ready

⛏️ Getting started #

Add the dependency supercharged: ^1.X.X (find recent version) to your project and start using Supercharged everywhere:

import 'package:supercharged/supercharged.dart';

🌞 Highlights #

Transform any String to colors

"#ff00ff".toColor(); // painless hex to color
"red".toColor(); // supports all web color names

Helpful substring functions:

"mode:production".allAfter(":"); // "production"
"<html>".allBetween("<", ">"); // "html"`
"flutter is cool".allBefore(" is"); // "flutter"

Handle user input:

"2.1".toDouble(); // 2.1
"42".toInt(); // 42
12.between(0, 30); // true

Effortless aggregation for Iterable<int> and Iterable<double>:

[1, 2, 3].sum(); // 6
[1, 2, 3].average(); // 2
[1, 2, 3].min(); // 1
[1, 2, 3].max(); // 3

Advanced aggregation for any Iterable:

var persons = [Person(age: 20), Person(age: 30), Person(age: 40)];
persons.sumBy((p) => p.age); // 90
persons.averageBy((p) => p.age); // 30
persons.count((p) => p.age < 35); // 2
persons.minBy((a,b) => a.age.compareTo(b.age)); // Person(age: 20)
persons.maxBy((a,b) => a.age.compareTo(b.age)); // Person(age: 40)

Safely access Iterable:

[].firstOrNull(); // return null instead
[].lastOrNull();  // of throwing error

[].firstOrElse(() => Placeholder()); // Produce default values
[].lastOrElse(() => Placeholder());  // on the fly

[1, 2, 3].elementAtOrNull(4); // Never go out of bounds
[1, 2, 3].elementAtOrElse(4, () => 0);

Group up data to match view:

var persons = [
    Person(name: "John", age: 21),
    Person(name: "Carl", age: 18),
    Person(name: "Peter", age: 56),
    Person(name: "Sarah", age: 61)
];

persons.groupBy(
    (p) => p.age < 40 ? "young" : "old",
    valueTransform: (p) => p.name
); // {"young": ["John", "Carl"], "old": ["Peter", "Sarah"]}

Chunking for easy pagination:

["a", "b", "c", "d", "e"].chunked(3); // [ ["a", "b", "c"], ["d", "e"] ]
["a", "b", "c"].chunked(2, fill: () => ""); // [ ["a", "b"], ["c", ""] ]

More natural durations and dates:

var duration = 5.minutes + 30.seconds;
duration += 0.5.hours;

var future = 2.days.fromNow() + 20.minutes;
var past = 15.minutes.ago();

var allDaysOf2020 = DateTime(2020).until(DateTime(2021));
var allFullHoursOfFirstJanuary2020 =
  DateTime(2020, 1, 1).until(DateTime(2020, 1, 2), by: 1.hours);

Simplified data sorting:

 persons = [
    Person(name: "John", age: 21),
    Person(name: "Carl", age: 18),
    Person(name: "Peter", age: 56),
    Person(name: "Sarah", age: 61)
  ];

  persons.sortedByNum((p) => p.age); // list sorted by age
  persons.sortedByString((p) => p.name); // list sorted by name
  persons  // sorted with comparator
      .sortedBy((a, b) => a.name.compareTo(b.name));

  persons // sorting is fully integrated into processing chain
      .filter((p) => p.name.length < 5)
      .sortedByNum((p) => p.age)
      .map((p) => p.name)
      .toList();

Solid tween shortcuts for animations:

100.0.tweenTo(200.0); // Tween(begin: 100.0, end: 200.0)
Colors.red.tweenTo(Colors.blue); // ColorTween(...)
0.0.tweenTo(100.0).curved(Curves.easeInOut); // Apply accelleration

Replace your classic for-loop:

0.rangeTo(5); // [0, 1, 2, 3, 4, 5]
3.rangeTo(1); // [3, 2, 1]

var list = ["dog", "cat", "mouse"];
0.until(list.length); // [0, 1, 2]

list.forEachIndexed((index, value) {
    // index: 0, value: "dog"
    // index: 1, value: "cat"
    // index: 2, value: "mouse"
});

📑 API documentation #

You can discover all 78 features in the API documentation. Each feature is well documented with an example.

Feel free to quickly jump into a topic:

📈 Improve #

Supercharged will improve in future updates. Help me by reporting bugs, submit new ideas for features or anything else that you want to share.

  • Just write an issue on GitHub. ✏️
  • And don't forget to hit the like button for this package ✌️

1.6.0 #

  • New: double between method
  • New: int between method

1.5.1 #

  • Fixed: Unit test for DateTime duration method

1.5.0 #

  • New: DateTime duration method

1.4.0 #

  • New: Animatable animatedBy method
  • New: Animatable curved method

1.3.0 #

  • New: int tweenTo method
  • New: double tweenTo method
  • New: Color tweenTo method
  • New: Duration / operator

1.2.1 #

  • Fixed: typo in API documentation

1.2.0 #

  • New: DateTime + operator
  • New: DateTime - operator
  • New: DateTime rangeTo method
  • New: DateTime until method
  • New: Duration fromNow method
  • New: Duration ago method
  • New: Iterable lastIndex getter
  • New: Iterable withoutFirst method
  • New: Iterable withoutLast method
  • Improved: Added null check for int until
  • Improved: Added null check for int times
  • Improved: Removed implicit casts and improved usage of strong types

1.1.0 #

  • New: Iterable sortedBy method
  • New: Iterable sortedByNum method
  • New: Iterable sortedByString method
  • New: Iterable chunked method has additional parameter fill
  • Improved: More efficient implementation for minBy and maxBy
  • Fixed: typo in API documentation

1.0.0 #

  • Initial release

example/example.md

📝 Examples #

import 'package:flutter/material.dart';
import 'package:supercharged/supercharged.dart';

main() {
  // Transform any String to colors
  "#ff00ff".toColor(); // painless hex to color
  "red".toColor(); // supports all web color names

  // Helpful substring functions:
  "mode:production".allAfter(":"); // "production"
  "<html>".allBetween("<", ">"); // "html"`
  "flutter is cool".allBefore(" is"); // "flutter"

  // Handle user input:
  "2.1".toDouble(); // 2.1
  "42".toInt(); // 42
  12.between(0, 30); // true

  // Effortless aggregation for Iterable<int> and Iterable<double>:
  [1, 2, 3].sum(); // 6
  [1, 2, 3].average(); // 2
  [1, 2, 3].min(); // 1
  [1, 2, 3].max(); // 3

  // Advanced aggregation for any Iterable:
  var persons = [Person(age: 20), Person(age: 30), Person(age: 40)];
  persons.sumBy((p) => p.age); // 90
  persons.averageBy((p) => p.age); // 30
  persons.count((p) => p.age < 35); // 2
  persons.minBy((a, b) => a.age.compareTo(b.age)); // Person(age: 20)
  persons.maxBy((a, b) => a.age.compareTo(b.age)); // Person(age: 40)

  // Safely access Iterable:
  [].firstOrNull(); // return null instead
  [].lastOrNull(); // of throwing error

  [].firstOrElse(() => Placeholder()); // Produce default values
  [].lastOrElse(() => Placeholder()); // on the fly

  [1, 2, 3].elementAtOrNull(4); // Never go out of bounds
  [1, 2, 3].elementAtOrElse(4, () => 0);

  // Group up data to match view:
  persons = [
    Person(name: "John", age: 21),
    Person(name: "Carl", age: 18),
    Person(name: "Peter", age: 56),
    Person(name: "Sarah", age: 61)
  ];

  persons.groupBy((p) => p.age < 40 ? "young" : "old",
      valueTransform: (p) =>
          p.name); // {"young": ["John", "Carl"], "old": ["Peter", "Sarah"]}

  // Chunking for easy pagination:
  ["a", "b", "c", "d", "e"].chunked(3); // [ ["a", "b", "c"], ["d", "e"] ]
  ["a", "b", "c"].chunked(2, fill: () => ""); // [ ["a", "b"], ["c", ""] ]

  // More natural durations and dates:
  var duration = 5.minutes + 30.seconds;
  duration += 0.5.hours;

  var future = 2.days.fromNow() + 20.minutes;
  var past = 15.minutes.ago();

  var allDaysOf2020 = DateTime(2020).until(DateTime(2021));
  var allFullHoursOfFirstJanuary2020 =
      DateTime(2020, 1, 1).until(DateTime(2020, 1, 2), by: 1.hours);

  // Simplified data sorting:
  persons = [
    Person(name: "John", age: 21),
    Person(name: "Carl", age: 18),
    Person(name: "Peter", age: 56),
    Person(name: "Sarah", age: 61)
  ];

  persons.sortedByNum((p) => p.age); // list sorted by age
  persons.sortedByString((p) => p.name); // list sorted by name
  persons
      .sortedBy((a, b) => a.name.compareTo(b.name)); // sorted with comparator

  persons // sorting is fully integrated into processing chain
      .filter((p) => p.name.length < 5)
      .sortedByNum((p) => p.age)
      .map((p) => p.name)
      .toList();

  // Solid tween shortcuts for animations
  100.0.tweenTo(200.0); // Tween(begin: 100.0, end: 200.0)
  Colors.red.tweenTo(Colors.blue); // ColorTween(...)

  // Replace your classic for loop:
  0.rangeTo(5); // [0, 1, 2, 3, 4, 5]
  3.rangeTo(1); // [3, 2, 1]

  var list = ["dog", "cat", "mouse"];
  0.until(list.length); // [0, 1, 2]

  list.forEachIndexed((index, value) {
    // index: 0, value: "dog"
    // index: 1, value: "cat"
    // index: 2, value: "mouse"
  });
}

class Person {
  final String name;
  final int age;

  Person({this.age, this.name = ""});
}

class Placeholder {}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  supercharged: ^1.6.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:supercharged/supercharged.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
97
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
98
Learn more about scoring.

We analyzed this package on Jun 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test