flutter_commons_lang 1.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 78

flutter_commons_lang #

commons_lang for flutter, provide DateUtils, StringUtils and so on...

Usage #

NumberUtils #

provider add/subtract/multiple/divide to safe calculate with scale,keep param's runtimeType or custom to returnType.

NumberUtils.getScale(1.12346);
NumberUtils.setScale(1.1246, scale: 2, roundingMode: ROUND_UP);

int a = NumberUtils.add(1, 2);
double b = NumberUtils.add(1, 2, returnType: double);

NumberUtils.add(0.3, 0.6);
NumberUtils.subtract(0.3, 0.2);
NumberUtils.multiply(0.3, 1.5);
NumberUtils.divide(0.3, 0.1);

NumberUtils.multiply(1.2354, 2.365, scale: 2);
NumberUtils.divide(12354, 7, scale: 5, roundingMode: ROUND_HALF_UP);

StringUtils #

provider some easy op.

print(StringUtils.isBlank(null));
print(StringUtils.isBlank(""));
print(StringUtils.isBlank("   "));
print(StringUtils.isBlank(" b "));

ListUtils #

provider the convert of list to string and string to list.

  List list = [1, 2, 3, 4, 5];
  String text = ListUtils.listToString(list);
  list = ListUtils.stringToList(text);
  text = ListUtils.listToString(list, ",");
  list = ListUtils.stringToList(text, ",");

DateUtils #

easy to op datetime. as today, yesterday as set hour,set day as truncate as daysOfTheMonth

DateTime time = DateUtils.parse("2018-12-11");
DateUtils.format(time);
DateUtils.format(time, "yyyy.MM.dd");

DateTime time1 = DateUtils.today();
DateTime time2 = DateUtils.today(hour:9);
DateTime time3 = DateUtils.yesterday();
DateTime time4 = DateUtils.set(DateTime.now(), year:2017);
DateTime time5 = DateUtils.truncate(DateTime.now(), hour:9, minute:30);
DateUtils.truncatedEquals(time1,time2,DateUtils.MONTH);
DateUtils.truncatedEquals(time1,time5,DateUtils.DAY);
DateUtils.daysOfTheMonth(time1);

Getting Started #

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

1.0.5 #

  • DateUtils add tomorrow

1.0.4 #

  • change DateUtils.format

1.0.3 #

  • StringUtils
  • NumberUtils
  • ListUtils

1.0.0 #

  • DateUtils

example/lib/main.dart

import 'package:flutter_commons_lang/flutter_commons_lang.dart';

void main() {
  ///StringUtils
  String text1 = "  ";
  print(text1.isEmpty);
  print(StringUtils.isBlank(null));
  print(StringUtils.isBlank(""));
  print(StringUtils.isBlank("   "));
  print(StringUtils.isBlank(" b "));

  ///NumberUtils
  print(NumberUtils.getScale(1.12346));
  print(NumberUtils.setScale(1.1246, scale: 2, roundingMode: ROUND_UP));

  int a = NumberUtils.add(1, 2);
  double b = NumberUtils.add(1, 2, returnType: double);
  print(a);
  print(b);

  print("0.2 + 0.1, original:${0.2 + 0.1}, target:${NumberUtils.add(0.2, 0.1)}");
  print("0.3 + 0.6, original:${0.3 + 0.6}, target:${NumberUtils.add(0.3, 0.6)}");
  print("0.3 - 0.2, original:${0.3 - 0.2}, target:${NumberUtils.subtract(0.3, 0.2)}");
  print("0.3 * 1.5, original:${0.3 * 1.5}, target:${NumberUtils.multiply(0.3, 1.5)}");
  print("0.3 / 0.1, original:${0.3 / 0.1}, target:${NumberUtils.divide(0.3, 0.1)}");

  print("1.2354 * 2.365, original:${1.2354 * 2.365}, target:${NumberUtils.multiply(1.2354, 2.365, scale: 2)}");
  print("12354 / 7, original:${12354 / 7}, target:${NumberUtils.divide(12354, 7, scale: 5, roundingMode: ROUND_HALF_UP)}");

  /// DateUtils
  String str = "2018-12-11";
  DateTime time = DateUtils.parse(str);
  print(time);
  print(DateUtils.format(time));
  print(DateUtils.format(time, "yyyy.MM.dd"));

  // 2018-05-01 12:27:35
  DateTime time1 = DateTime(2018, 5, 1, 12, 27, 35);
  DateTime time2 = DateUtils.set(time1, hour: 7);
  print(time1);
  print(time2);

  time1 = DateUtils.today();
  time2 = DateTime.now();
  print(time1);
  print("time2:$time2, year:${time2.year},month:${time2.month},day:${time2.day},weekday:${time2.weekday}");
  print(DateUtils.truncatedEquals(time1, time2, DateUtils.DAY_OF_MONTH));

  DateTime time3 = DateUtils.yesterday();
  DateTime time4 = DateUtils.set(DateTime.now(), year: 2017);
  DateTime time5 = DateUtils.truncate(DateTime.now(), hour: 9, minute: 30);
  print(time3);
  print(time4);
  print(time5);

  print(DateUtils.truncatedEquals(time1, time2, DateUtils.MONTH));
  print(DateUtils.truncatedEquals(time1, time5, DateUtils.DAY_OF_MONTH));
  print(DateUtils.daysOfTheMonth(time1));

  /// ListUtils
  List list = [1, 2, 3, 4, 5];
  String text = ListUtils.listToString(list);
  print(text);
  list = ListUtils.stringToList(text);
  print(list);

  text = ListUtils.listToString(list, ",");
  print(text);
  list = ListUtils.stringToList(text, ",");
  print(list);

  text = ListUtils.listToString(list, ",,");
  print(text);
  // it's error
  // list = ListUtils.stringToList(text, ",,");
  // print(list);
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_commons_lang: ^1.0.5

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_commons_lang/flutter_commons_lang.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
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]
78
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/src/date_utils.dart.

Run flutter format to format lib/src/date_utils.dart.

Format lib/src/list_utils.dart.

Run flutter format to format lib/src/list_utils.dart.

Format lib/src/number_utils.dart.

Run flutter format to format lib/src/number_utils.dart.

Format lib/src/string_utils.dart.

Run flutter format to format lib/src/string_utils.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
decimal ^0.3.2 0.3.5
flutter 0.0.0
flutter_localizations 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
intl 0.15.8 0.16.0
meta 1.1.7
path 1.6.4
rational 0.3.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8