flutter_extentions 0.0.2

Resources: #

Why I need this? When you’re using someone else’s API or when you implement a library that’s widely used, it’s often impractical or impossible to change the API. But you might still want to add some functionality.

let me know if you want something specific or you found a bug at bar.idan@gmail.com

Let get started 💪🏻 #

  1. Go to pubspec.yaml
  2. add a dart_extentions and replace [version] with the latest version:
 dart_extentions: ^[version]
  1. click the packages get button or flutter pub get

Iterable Extensions #

.forEachIndexed() #

Performs the given action on each element on iterable, providing sequential index with the element.

["red","green","blue"].forEachIndexed((item, index) { 
	print("$item, $index"); 
}); // 0: red // 1: green // 2: blue```  

.sortedDescending() #

Returns a new list with all elements sorted according to descending natural sort order.

var list = [1,2,3,4,5];  
final descendingList = list.sortedDescending();  
print(descendingList); // [5, 4, 3, 2, 1]

.count() #

Return a number of the existing elements by a specific predicate

final users = []  
  ..add(User(33, "Miki"))  
  ..add(User(45, "Anna"))  
  ..add(User(19, "Amit"));  
final aboveAgeTwenty = users.count((user) => user.age > 20);  
print(aboveAgeTwenty); // 2

.distinctBy() #

Returns a list containing only the elements from given collection having distinct keys.

// example 1
final users = ["Idan", "Ian", "Ronit"];  
users.distinctBy((u) => u.toLowerCase().startsWith("I")); // Idan 

// example 2
final users = <User>[]
	..add(User(11, 'idan'))
	..add(User(12, 'ronit'))
	..add(User(11, 'asaf'));  

final dist = users.distinctBy((u) => u.age);    
dist.forEach((u) => print(u.age)); //  11, 12

.zip() #

Zip is used to combine multiple iterables into a single list that contains the combination of them two.

final soldThisMonth = <Motorcycle>[]  
  ..add(Motorcycle(2020, 'BMW R1200GS'))  
  ..add(Motorcycle(1967, 'Honda GoldWing'))  

final soldLastMonth = <Motorcycle>[]  
  ..add(Motorcycle(2014, 'Honda Transalp'))  
  ..add(Motorcycle(2019, 'Ducati Multistrada'))  
final sales = soldThisMonth.zip(soldLastMonth).toList();  
				    (this from soldThisMonth)      (this from so	ldLastMonth)
print(sales); // [[brand: BMW R1200GS year: 2020, brand: Honda Transalp year: 2014],
				  [brand: Honda GoldWing year: 1967, brand: Ducati Multistrada year: 2019]]

See iterable.dart for more examples.

String Extensions #

.replaceAfter #

Replace part of string after the first occurrence of given delimiter.

print("myemail@".replaceAfter("@", "gmail.com")); // myemail@gmail.com 

.ifEmpty #

if the string is empty perform an action.

"".ifEmpty(() => print("do any action here")); // do any action here

.toDoubleOrNull() #

Parses the string as an ineger or returns null if it is not a number.

var number = '12345'.toIntOrNull(); // 12345  
var notANumber = '123-45'.toIntOrNull(); // null  

License #

Copyright 2020 Idan Ayalon
Licensed under the Apache License, Version 2.0 (the "License");  
you may not use this file except in compliance with the License.  
You may obtain a copy of the License at  
Unless required by applicable law or agreed to in writing, software  
distributed under the License is distributed on an "AS IS" BASIS,  
See the License for the specific language governing permissions and  
limitations under the License.  

[0.0.1] - TODO: Add release date.

  • dates tools
  • iterable tools
  • strings tools

Use this package as a library

1. Depend on it

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

  flutter_extentions: ^0.0.2

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:flutter_extentions/data_stractures/stack.dart';
import 'package:flutter_extentions/date.dart';
import 'package:flutter_extentions/generated/i18n.dart';
import 'package:flutter_extentions/iterable.dart';
import 'package:flutter_extentions/strings.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Health suggestions

Format lib/data_stractures/stack.dart.

Run flutter format to format lib/data_stractures/stack.dart.

Format lib/date.dart.

Run flutter format to format lib/date.dart.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Format lib/iterable.dart.

Run flutter format to format lib/iterable.dart.

Format lib/strings.dart.

Run flutter format to format lib/strings.dart.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and flutter_extentions.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
intl ^0.16.1 0.16.1
quiver ^2.0.0 2.1.2+1
Transitive dependencies
collection 1.14.11 1.14.12
matcher 0.12.6
meta 1.1.8
path 1.6.4
sky_engine 0.0.99
stack_trace 1.9.3
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
test ^1.9.2