idkit_extension 0.0.2 copy "idkit_extension: ^0.0.2" to clipboard
idkit_extension: ^0.0.2 copied to clipboard

This package is mainly used to extend common functions of some classes in Flutter development, making it more convenient and simple for developers to develop.

example/lib/main.dart

import 'package:idkit_extension/idkit_extension.dart';

void main() {
  removeAllSpaces();
  toNumber();
  toCollection();
  toID();
  toCC();
  toPhone();
  toVerifyNumber();
  toAmount();
  toStringFromList();
  formStringToKeepPoint();
  formNumToKeepPoint();
}

/// 1. Remove all spaces in the string.
void removeAllSpaces() {
  const String testStr = ' aa bb  cc dd  ';
  print(testStr.trimAll());
}

/// 2. Convert a string to a number.
void toNumber() {
  const String value = '110';
  print(value.toInt()); // 110
  print(value.toDouble()); // 110.0
}

/// 3. Convert string to collection.
void toCollection() {
  const String testStr = 'abcd';
  print(testStr.toList()); // [a,b,c,d]

  const String testStr1 = '1,2,10,21';
  print(testStr1.toList(patternSplit: ',')); // [1,2,10,21]
}

/// 4. ID card verification.
void toID() {
  const String id1 = '53010219200508011X';
  print(id1.isIDCard()); // true

  const String id2 = '53010219200508012X';
  print(id2.isIDCard()); // false
}

/// 5. Verify that the string is all Chinese characters.
void toCC() {
  const String txt1 = '我是who';
  print(txt1.isChineseCharacters()); // false

  const String txt2 = '我是 大鲨鱼,是吗';
  print(txt2.isChineseCharacters()); // true
}

/// 6. Verify that the string is a qualified phone number.
void toPhone() {
  const String phone = '18801210281';
  print(phone.isPhoneNumber()); // true

  const String phone1 = '12801210281';
  print(phone1.isPhoneNumber()); // false
}

/// 7. Verify whether it is a string composed of 0-9.
void toVerifyNumber() {
  const String phone = '18801210281';
  print(phone.isAllNumber()); // true

  const String phone1 = '12801210281#';
  print(phone1.isAllNumber()); // false
}

/// 8. Amount formatted in thousandths.
void toAmount() {
  const String amount = '12345';
  print(amount.thousands()); // 12,345

  const String amount1 = '12345.087';
  print(amount1.thousands()); // 12,345.087
}

/// 9. Splicing between collection elements.
void toStringFromList() {
  const List<String> list = <String>['T', 'h', 'i', 's'];
  print(list.splicing()); // This

  const List<String> list1 = <String>['2021', '11', '17'];
  print(list1.splicing('-')); // 2021-11-17
}

/// 11. Convert a string of numbers to a number with specified decimal places
void formStringToKeepPoint() {
  final String a = '111.03'.keepFractionDigits(0);
  print(a);

  final String b = '111.03'.keepFractionDigits(1);
  print(b);

  final String c = '111.03'.keepFractionDigits(2);
  print(c);

  final String d = '111.03'.keepFractionDigits(3);
  print(d);

  final String e = '111'.keepFractionDigits(2);
  print(e);

  final String f = '111.034'.keepFractionDigits(2);
  print(f);

  final String f1 = '111.036'.keepFractionDigits(2);
  print(f1);

  final String f2 = '111.036'.keepFractionDigits(2, round: false);
  print(f2);

  final String g = '111.996'.keepFractionDigits(2);
  print(g);

  final String g1 = '111.994'.keepFractionDigits(2);
  print(g1);

  final String h = 'xx23343'.keepFractionDigits(3);
  print(h);
}

/// 12. Convert a string of numbers to a number with specified decimal places
void formNumToKeepPoint() {
  final String a = 111.03.keepFractionDigits(0);
  print(a);

  final String b = 111.03.keepFractionDigits(1);
  print(b);

  final String c = 111.03.keepFractionDigits(2);
  print(c);

  final String d = 111.03.keepFractionDigits(3);
  print(d);

  final String e = 111.keepFractionDigits(2);
  print(e);

  final String f = 111.034.keepFractionDigits(2);
  print(f);

  final String f1 = 111.036.keepFractionDigits(2);
  print(f1);

  final String f2 = 111.036.keepFractionDigits(2, round: false);
  print(f2);

  final String g = 111.996.keepFractionDigits(2);
  print(g);

  final String g1 = 111.994.keepFractionDigits(2);
  print(g1);
}
1
likes
120
pub points
0%
popularity

Publisher

unverified uploader

This package is mainly used to extend common functions of some classes in Flutter development, making it more convenient and simple for developers to develop.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-2-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on idkit_extension