extension_kit 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

extension_kit #

This is Dart extension kit. If this plugin is imported your project, it enable to use various extension function.

https://pub.dev/packages/extension_kit

Installation #

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

dependencies:
  extension_kit:

Feature list #

Implementation extension's list. It will be create more extension feature in future.

Usage #

Import extension_kit.

import 'package:extension_kit/extension_kit.dart';

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 #

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

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

Context #

isDark

final isDark = context.isDark; // Dark mode => true, not dark mode => false

deviceWidth, deviceHeight

final width = context.deviceWidth; // device width from MediaQuery.of(this).size
final height = context.deviceHeight; // device height from MediaQuery.of(this).size

hideKeyboard

GestureDetector(
  child: ...,
  onTap: () => context.hideKeyboard(),
),

0.1.1 #

Added extension of context and list.

0.1.0+4 #

Deleted unnecessary files.

0.1.0+3 #

Updated document.

0.1.0+2 #

Updated document.

0.1.0+1 #

Updated document.

0.1.0 #

First release.

example/lib/main.dart

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

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Page(),
    );
  }
}

class Page extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      ),
      body: GestureDetector(
        child: Center(
          child: Text('width: ${context.deviceWidth}, height: ${context.deviceHeight}\n'
              'Dark: ${context.isDark}\n'),
        ),
        onTap: () => context.hideKeyboard(),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

35 out of 35 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/extension/date_extension.dart.

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

Format lib/extension/double_extension.dart.

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

Format lib/extension/int_extension.dart.

Run flutter format to format lib/extension/int_extension.dart.

Format lib/extension/list_extension.dart.

Run flutter format to format lib/extension/list_extension.dart.

Format lib/extension/num_extension.dart.

Run flutter format to format lib/extension/num_extension.dart.

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.11 1.14.12
meta 1.1.8
path 1.6.4
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
pedantic_mono any