flutter_extension_kits 0.1.1

  • Readme
  • Changelog
  • Installing
  • 65

extensions #

This project is a starting point to build useful widget extensions for most used widgets such as padding and containers to minimize UI codes

🎖 Installation #

dependencies:
  extensions: "^0.0.2"

Import #

import 'package:flutter_extension_kits/flutter_extension_kits.dart';

Usage For Widgets #

Text('Line 01').paddingAll(8);
Text('Line 02').paddingOnly(left : 2, top : 4, right : 6, bottom : 8 );
Text('Line 03').paddingSymmetric(horizontal : 10, vertical : 20);

Usage For Variables #

int #

millisecondsToDate

print(1601996400000.millisecondsToDate()); // DateTime(2020, 10, 7)

double #

roundWithDigit

const value1 = 10.45678;
print(value1.roundWithDigit(1));   // 10.5
print(value1.roundWithDigit(2));   // 10.46
print(value1.roundWithDigit(3));   // 10.457
print(value1.roundWithDigit(0));   // 10.45678
print(value1.roundWithDigit(-1));  // 10.45678

const value2 = 10.434321;
print(value2.roundWithDigit(1));   // 10.4
print(value2.roundWithDigit(2);    // 10.43
print(value2.roundWithDigit(3));   // 10.434

num #

commaFormat

print(100.commaFormat());         // '100'
print(1000.commaFormat());        // '1,000'
print(1000000.commaFormat());     // '1,000,000'
print(1000000.123.commaFormat()); // '1,000,000.123'

String #

format

const String text = 'Today is {1} and tomorrow is {0}';
final List<String> placeHolders = List<String>()
  ..add('Tuesday')
  ..add('Monday');

final String finalString = text.format(placeHolders);
//'Today is Monday and tomorrow is Tuesday';

toDate

print('20201008'.toDate());       // DateTime(2020, 10, 8)

toInt

print('123'.toInt());             // 123

toDouble

print('123.4567'.toDouble());     // 123.4567

isNewLine

print('\n'.isNewLine());          // true
print('test'.isNewLine());        // false

Date #

formatString

final date = DateTime(2020, 10, 7);
print(date.formatString());                     // '10.07 2020'
print(date.formatString(format: 'yyyy/MM/dd')); // '2020/10/07'

diffDays, diffHours, diffMinutes, diffSeconds

final dateA = DateTime(2020, 10, 7, 20, 10, 30);
final dateB = DateTime(2020, 8, 2, 10, 5, 10);
final dateC = DateTime(2020, 10, 7, 20, 10, 30);

// dateA - dateB
print(dateA.diffDays(dateB));       // 66
print(dateA.diffHours(dateB));      // 1594
print(dateA.diffMinutes(dateB));    // 95645
print(dateA.diffSeconds(dateB));    // 5738720

Beautify Time Left/Ago

  //Time Left
  // Current testing time is 2020/05/25 9:11PM
  final expiryDate01 = DateTime(2021, 10, 7, 20, 10, 30);
  print(expiryDate01.beautifyTime(strSuffix: 'left')); //1 year 5 months left

  final expiryDate02 = DateTime(2020, 10, 7, 20, 10, 30);
  print(expiryDate02.beautifyTime(strSuffix: 'left')); //4 months left

  final expiryDate03 = DateTime(2020, 5, 15, 20, 10, 30);
  print(expiryDate03.beautifyTime(strSuffix: 'left')); //10 days left

  final expiryDate04 = DateTime(2020, 5, 25, 20, 23, 30);
  print(expiryDate04.beautifyTime(strSuffix: 'left')); //46 minutes left

  // Current testing time is 2020/05/25 8:53PM
  final lastUpdatedDate01 = DateTime(2018, 12, 7, 20, 5, 10);
  print(lastUpdatedDate01.beautifyTime(bUTC: false, bAddPlural: true)); //1year 6m

  final lastUpdatedDate02 = DateTime(2019, 10, 7, 20, 5, 10);
  print(lastUpdatedDate02.beautifyTime(bUTC: false, bAddPlural: true)); //8months 

  final lastUpdatedDate03 = DateTime(2020, 5, 25, 10, 5, 10);
  print(lastUpdatedDate03.beautifyTime(bUTC: false, bAddPlural: true)); //10hours 

  final lastUpdatedDate04 = DateTime(2020, 5, 25, 20, 5, 10);
  print(lastUpdatedDate04.beautifyTime(bUTC: false, bAddPlural: true)); //48minute

  final lastUpdatedDate05 = DateTime(2020, 5, 25, 20, 53, 10);
  print(lastUpdatedDate05.beautifyTime(bUTC: false, bAddPlural: true)); //Just now
  //Time Left
  // Current testing time is 2020/05/25 9:11PM
  final expiryDate01 = DateTime(2021, 10, 7, 20, 10, 30);
  print(expiryDate01.beautifyTime(strSuffix: 'left')); //1 year 5 months left

  final expiryDate02 = DateTime(2020, 10, 7, 20, 10, 30);
  print(expiryDate02.beautifyTime(strSuffix: 'left')); //4 months left

  final expiryDate03 = DateTime(2020, 5, 15, 20, 10, 30);
  print(expiryDate03.beautifyTime(strSuffix: 'left')); //10 days left

  final expiryDate04 = DateTime(2020, 5, 25, 20, 23, 30);
  print(expiryDate04.beautifyTime(strSuffix: 'left')); //46 minutes left

  // Current testing time is 2020/05/25 8:53PM
  final lastUpdatedDate01 = DateTime(2018, 12, 7, 20, 5, 10);
  print(lastUpdatedDate01.beautifyTime(bUTC: false, bAddPlural: true)); //1year 6m

  final lastUpdatedDate02 = DateTime(2019, 10, 7, 20, 5, 10);
  print(lastUpdatedDate02.beautifyTime(bUTC: false, bAddPlural: true)); //8months 

  final lastUpdatedDate03 = DateTime(2020, 5, 25, 10, 5, 10);
  print(lastUpdatedDate03.beautifyTime(bUTC: false, bAddPlural: true)); //10hours 

  final lastUpdatedDate04 = DateTime(2020, 5, 25, 20, 5, 10);
  print(lastUpdatedDate04.beautifyTime(bUTC: false, bAddPlural: true)); //48minute

  final lastUpdatedDate05 = DateTime(2020, 5, 25, 20, 53, 10);
  print(lastUpdatedDate05.beautifyTime(bUTC: false, bAddPlural: true)); //Just nows 10hrs
  //Time Left
  // Current testing time is 2020/05/25 9:11PM
  final expiryDate01 = DateTime(2021, 10, 7, 20, 10, 30);
  print(expiryDate01.beautifyTime(strSuffix: 'left')); //1 year 5 months left

  final expiryDate02 = DateTime(2020, 10, 7, 20, 10, 30);
  print(expiryDate02.beautifyTime(strSuffix: 'left')); //4 months left

  final expiryDate03 = DateTime(2020, 5, 15, 20, 10, 30);
  print(expiryDate03.beautifyTime(strSuffix: 'left')); //10 days left

  final expiryDate04 = DateTime(2020, 5, 25, 20, 23, 30);
  print(expiryDate04.beautifyTime(strSuffix: 'left')); //46 minutes left

  // Current testing time is 2020/05/25 8:53PM
  final lastUpdatedDate01 = DateTime(2018, 12, 7, 20, 5, 10);
  print(lastUpdatedDate01.beautifyTime(bUTC: false, bAddPlural: true)); //1year 6m

  final lastUpdatedDate02 = DateTime(2019, 10, 7, 20, 5, 10);
  print(lastUpdatedDate02.beautifyTime(bUTC: false, bAddPlural: true)); //8months 

  final lastUpdatedDate03 = DateTime(2020, 5, 25, 10, 5, 10);
  print(lastUpdatedDate03.beautifyTime(bUTC: false, bAddPlural: true)); //10hours 

  final lastUpdatedDate04 = DateTime(2020, 5, 25, 20, 5, 10);
  print(lastUpdatedDate04.beautifyTime(bUTC: false, bAddPlural: true)); //48minute

  final lastUpdatedDate05 = DateTime(2020, 5, 25, 20, 53, 10);
  print(lastUpdatedDate05.beautifyTime(bUTC: false, bAddPlural: true)); //Just now
  //Time Left
  // Current testing time is 2020/05/25 9:11PM
  final expiryDate01 = DateTime(2021, 10, 7, 20, 10, 30);
  print(expiryDate01.beautifyTime(strSuffix: 'left')); //1 year 5 months left

  final expiryDate02 = DateTime(2020, 10, 7, 20, 10, 30);
  print(expiryDate02.beautifyTime(strSuffix: 'left')); //4 months left

  final expiryDate03 = DateTime(2020, 5, 15, 20, 10, 30);
  print(expiryDate03.beautifyTime(strSuffix: 'left')); //10 days left

  final expiryDate04 = DateTime(2020, 5, 25, 20, 23, 30);
  print(expiryDate04.beautifyTime(strSuffix: 'left')); //46 minutes left

  // Current testing time is 2020/05/25 8:53PM
  final lastUpdatedDate01 = DateTime(2018, 12, 7, 20, 5, 10);
  print(lastUpdatedDate01.beautifyTime(bUTC: false, bAddPlural: true)); //1year 6m

  final lastUpdatedDate02 = DateTime(2019, 10, 7, 20, 5, 10);
  print(lastUpdatedDate02.beautifyTime(bUTC: false, bAddPlural: true)); //8months 

  final lastUpdatedDate03 = DateTime(2020, 5, 25, 10, 5, 10);
  print(lastUpdatedDate03.beautifyTime(bUTC: false, bAddPlural: true)); //10hours 

  final lastUpdatedDate04 = DateTime(2020, 5, 25, 20, 5, 10);
  print(lastUpdatedDate04.beautifyTime(bUTC: false, bAddPlural: true)); //48minute

  final lastUpdatedDate05 = DateTime(2020, 5, 25, 20, 53, 10);
  print(lastUpdatedDate05.beautifyTime(bUTC: false, bAddPlural: true)); //Just now
  //Time Left
  // Current testing time is 2020/05/25 9:11PM
  final expiryDate01 = DateTime(2021, 10, 7, 20, 10, 30);
  print(expiryDate01.beautifyTime(strSuffix: 'left')); //1 year 5 months left

  final expiryDate02 = DateTime(2020, 10, 7, 20, 10, 30);
  print(expiryDate02.beautifyTime(strSuffix: 'left')); //4 months left

  final expiryDate03 = DateTime(2020, 5, 15, 20, 10, 30);
  print(expiryDate03.beautifyTime(strSuffix: 'left')); //10 days left

  final expiryDate04 = DateTime(2020, 5, 25, 20, 23, 30);
  print(expiryDate04.beautifyTime(strSuffix: 'left')); //46 minutes left

  // Current testing time is 2020/05/25 8:53PM
  final lastUpdatedDate01 = DateTime(2018, 12, 7, 20, 5, 10);
  print(lastUpdatedDate01.beautifyTime(bUTC: false, bAddPlural: true)); //1year 6m

  final lastUpdatedDate02 = DateTime(2019, 10, 7, 20, 5, 10);
  print(lastUpdatedDate02.beautifyTime(bUTC: false, bAddPlural: true)); //8months 

  final lastUpdatedDate03 = DateTime(2020, 5, 25, 10, 5, 10);
  print(lastUpdatedDate03.beautifyTime(bUTC: false, bAddPlural: true)); //10hours 

  final lastUpdatedDate04 = DateTime(2020, 5, 25, 20, 5, 10);
  print(lastUpdatedDate04.beautifyTime(bUTC: false, bAddPlural: true)); //48minute

  final lastUpdatedDate05 = DateTime(2020, 5, 25, 20, 53, 10);
  print(lastUpdatedDate05.beautifyTime(bUTC: false, bAddPlural: true)); //Just now 5mins
  //Time Left
  // Current testing time is 2020/05/25 9:11PM
  final expiryDate01 = DateTime(2021, 10, 7, 20, 10, 30);
  print(expiryDate01.beautifyTime(strSuffix: 'left')); //1 year 5 months left

  final expiryDate02 = DateTime(2020, 10, 7, 20, 10, 30);
  print(expiryDate02.beautifyTime(strSuffix: 'left')); //4 months left

  final expiryDate03 = DateTime(2020, 5, 15, 20, 10, 30);
  print(expiryDate03.beautifyTime(strSuffix: 'left')); //10 days left

  final expiryDate04 = DateTime(2020, 5, 25, 20, 23, 30);
  print(expiryDate04.beautifyTime(strSuffix: 'left')); //46 minutes left

  // Current testing time is 2020/05/25 8:53PM
  final lastUpdatedDate01 = DateTime(2018, 12, 7, 20, 5, 10);
  print(lastUpdatedDate01.beautifyTime(bUTC: false, bAddPlural: true)); //1year 6m

  final lastUpdatedDate02 = DateTime(2019, 10, 7, 20, 5, 10);
  print(lastUpdatedDate02.beautifyTime(bUTC: false, bAddPlural: true)); //8months 

  final lastUpdatedDate03 = DateTime(2020, 5, 25, 10, 5, 10);
  print(lastUpdatedDate03.beautifyTime(bUTC: false, bAddPlural: true)); //10hours 

  final lastUpdatedDate04 = DateTime(2020, 5, 25, 20, 5, 10);
  print(lastUpdatedDate04.beautifyTime(bUTC: false, bAddPlural: true)); //48minute

  final lastUpdatedDate05 = DateTime(2020, 5, 25, 20, 53, 10);
  print(lastUpdatedDate05.beautifyTime(bUTC: false, bAddPlural: true)); //Just now
  //Time Left
  // Current testing time is 2020/05/25 9:11PM
  final expiryDate01 = DateTime(2021, 10, 7, 20, 10, 30);
  print(expiryDate01.beautifyTime(strSuffix: 'left')); //1 year 5 months left

  final expiryDate02 = DateTime(2020, 10, 7, 20, 10, 30);
  print(expiryDate02.beautifyTime(strSuffix: 'left')); //4 months left

  final expiryDate03 = DateTime(2020, 5, 15, 20, 10, 30);
  print(expiryDate03.beautifyTime(strSuffix: 'left')); //10 days left

  final expiryDate04 = DateTime(2020, 5, 25, 20, 23, 30);
  print(expiryDate04.beautifyTime(strSuffix: 'left')); //46 minutes left

  // Current testing time is 2020/05/25 8:53PM
  final lastUpdatedDate01 = DateTime(2018, 12, 7, 20, 5, 10);
  print(lastUpdatedDate01.beautifyTime(bUTC: false, bAddPlural: true)); //1year 6m

  final lastUpdatedDate02 = DateTime(2019, 10, 7, 20, 5, 10);
  print(lastUpdatedDate02.beautifyTime(bUTC: false, bAddPlural: true)); //8months 

  final lastUpdatedDate03 = DateTime(2020, 5, 25, 10, 5, 10);
  print(lastUpdatedDate03.beautifyTime(bUTC: false, bAddPlural: true)); //10hours 

  final lastUpdatedDate04 = DateTime(2020, 5, 25, 20, 5, 10);
  print(lastUpdatedDate04.beautifyTime(bUTC: false, bAddPlural: true)); //48minute

  final lastUpdatedDate05 = DateTime(2020, 5, 25, 20, 53, 10);
  print(lastUpdatedDate05.beautifyTime(bUTC: false, bAddPlural: true)); //Just now

isCompare

// dateA >= dateB => true
// dateA < dateB => false
final dateA = DateTime(2020, 10, 7, 20, 10, 30);
final dateB = DateTime(2020, 8, 2, 10, 5, 10);
final dateC = DateTime(2020, 10, 7, 20, 10, 30);

print(dateA.isCompare(dateB));  // true
print(dateA.isCompare(dateC));  // true
print(dateB.isCompare(dateA));  // false

List #

max

print([10, 2, 3].max());      // 10
print([0.3, 1.2, 0.8].max()); // 1.2

Keybased event manager #

var someEvent = ExtendedEvent();
someEvent.subscribe('key01', (args) {
  print('Event triggered');
});
print('Triggering event');
someEvent.broadcast();
print('Total subscribers : ' + someEvent.subscriberCount.toString());
bool bUnsubscribeStatus = someEvent.unsubscribe('key02');
if (!bUnsubscribeStatus)
  print('Failed to unsubscribe event');
else
  print('key02 unsubscribed from the manager');
bUnsubscribeStatus = someEvent.unsubscribe('key01');
if (!bUnsubscribeStatus)
  print('Failed to unsubscribe event');
else
  print('key01 unsubscribed from the manager');
//Trigger won't reived anymore since we've unsubscribed from the manager
someEvent.broadcast();
print('Total subscribers : ' + someEvent.subscriberCount.toString());
var someEvent = ExtendedEvent();
someEvent.subscribe('key01', (args) {
  print('Event triggered');
});
print('Triggering event');
someEvent.broadcast();
print('Total subscribers : ' + someEvent.subscriberCount.toString());
bool bUnsubscribeStatus = someEvent.unsubscribe('key02');
if (!bUnsubscribeStatus)
  print('Failed to unsubscribe event');
else
  print('key02 unsubscribed from the manager');
bUnsubscribeStatus = someEvent.unsubscribe('key01');
if (!bUnsubscribeStatus)
  print('Failed to unsubscribe event');
else
  print('key01 unsubscribed from the manager');
//Trigger won't reived anymore since we've unsubscribed from the manager
someEvent.broadcast();
print('Total subscribers : ' + someEvent.subscriberCount.toString());: 8 );
var someEvent = ExtendedEvent();
someEvent.subscribe('key01', (args) {
  print('Event triggered');
});
print('Triggering event');
someEvent.broadcast();
print('Total subscribers : ' + someEvent.subscriberCount.toString());
bool bUnsubscribeStatus = someEvent.unsubscribe('key02');
if (!bUnsubscribeStatus)
  print('Failed to unsubscribe event');
else
  print('key02 unsubscribed from the manager');
bUnsubscribeStatus = someEvent.unsubscribe('key01');
if (!bUnsubscribeStatus)
  print('Failed to unsubscribe event');
else
  print('key01 unsubscribed from the manager');
//Trigger won't reived anymore since we've unsubscribed from the manager
someEvent.broadcast();
print('Total subscribers : ' + someEvent.subscriberCount.toString());

[0.0.1] #

  • Released initial

[0.0.2] #

  • Added some extensions for variables
  • Added padding extensions for the widgets

[0.0.3] #

  • Added C# looks a like Format extension for the string

[0.0.4] #

  • Added beautifications for dateTime comparasions

[0.0.5] #

  • Added some more options in beauty times

[0.0.6] #

  • Fixed padding only and symmetric params

[0.0.8] #

  • Added even manager support

[0.0.9] #

  • Added readme file for keybased event manager

[0.1.1] #

  • Fixed beautify date bug

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_extension_kits: ^0.1.1

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_extension_kits/flutter_extension_kits.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
43
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • flutter_extension_kits that is a package requiring null.

Health suggestions

Fix lib/extensions/string_extension.dart. (-0.50 points)

Analysis of lib/extensions/string_extension.dart reported 1 hint:

line 13 col 35: Avoid using braces in interpolation when not needed.

Format lib/extensions/date_extension.dart.

Run flutter format to format lib/extensions/date_extension.dart.

Format lib/extensions/double_extension.dart.

Run flutter format to format lib/extensions/double_extension.dart.

Fix additional 6 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/extensions/extended_event.dart (Run flutter format to format lib/extensions/extended_event.dart.)
  • lib/extensions/extended_eventargs.dart (Run flutter format to format lib/extensions/extended_eventargs.dart.)
  • lib/extensions/int_extension.dart (Run flutter format to format lib/extensions/int_extension.dart.)
  • lib/extensions/list_extension.dart (Run flutter format to format lib/extensions/list_extension.dart.)
  • lib/extensions/num_extension.dart (Run flutter format to format lib/extensions/num_extension.dart.)
  • lib/extensions/widget_extension.dart (Run flutter format to format lib/extensions/widget_extension.dart.)

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

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_extension_kits.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
intl ^0.16.1 0.16.1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
path 1.7.0
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test