## 构成 #

``````Calculate
//主类
- static Map<String, Function> funs
定义的方法映射

- static List<String> toNumberList
把字符串中的数字和算式符号提取为list

- static List<String> formatList
把数字和算式符号列表中重复的符号去除

- static num LinierCalculate
直接计算字符串式算式

- static num ListCalculate
计算list式算式

- static num plus
加法

- static num substract
减法

- static num multiply
乘法

- static num divide
除法

- static num percent
消费或者百分式算法
``````

## 安装 #

``````dependencies:
string_num_calculate: ^0.0.1
``````

## 用法说明 #

``````import 'package:string_num_calculate/string_num_calculate.dart';// 引入

Calculate.plus(1, 2);//=>3
Calculate.substract(1, 2);//=>-1
Calculate.multiply(1, 2);//=>2
Calculate.divide(1, 2);//=>.5
Calculate.percent(1, 2);//=>0.02
Calculate.ListCalculate(['1', '-', '5']);//=>-4
Calculate.toNumberList('1-5');//=>['1','-','5']
Calculate.formatList(['1', '+', '-', '5']);//=>['1','-','5']
Calculate.LinierCalculate('1+3+5');//=>9
``````

## 测试 #

``````// 加法计算
test('static [plus]计算加', () {
expect(Calculate.plus(1, 2), 3);
expect(Calculate.plus(1, -2), -1);
expect(Calculate.plus(-1, -2), -3);
expect(Calculate.plus(-.1, -2), -2.1);
expect(Calculate.plus(-.1, -0.2), -0.30000000000000004);
});
// 减法计算
test('static [substract]计算减', () {
expect(Calculate.substract(1, 2), -1);
expect(Calculate.substract(.1, -2), 2.1);
expect(Calculate.substract(0.1, -2), 2.1);
});
// 乘法计算
test('static [multiply]计算乘', () {
expect(Calculate.multiply(1, 2), 2);
expect(Calculate.multiply(1, -2), -2);
expect(Calculate.multiply(1, 0), 0);
});
// 除法计算
test('static [divide]计算除', () {
expect(Calculate.divide(1, 2), .5);
expect(Calculate.divide(1, -2), -.5);
});
// 小费计算
test('static [percent]计算百分数', () {
expect(Calculate.percent(1, 2), 0.02);
expect(Calculate.percent(1, -2), -0.02);
expect(Calculate.percent(100, 2), 2);
});

// 数字list计算
test('static [ListCalculate]数字list计算', () {
expect(Calculate.ListCalculate(['1', '-', '5']), -4);
expect(Calculate.ListCalculate(['1', '+', '5']), 6);
expect(Calculate.ListCalculate(['-1', '×', '5']), -5);
expect(Calculate.ListCalculate(['1', '%', '5']), 0.05);
});
// 数字字符串转换成数字list
test('static [toNumberList]数字字符串转list', () {
expect(Calculate.toNumberList('1-5'), ['1', '-', '5']);
expect(Calculate.toNumberList('-1+5'), ['-','1', '+', '5']);
expect(Calculate.toNumberList('1×5'), ['1', '×', '5']);
expect(Calculate.toNumberList('1%5'), ['1', '%', '5']);
});
// 数字list去除符号相同
test('static [formatList]数字字符串转list', () {
expect(Calculate.formatList(['1', '+', '-', '5']), ['1', '-', '5']);
expect(Calculate.formatList(['1', '+', '+', '5']), ['1', '+', '5']);
expect(Calculate.formatList(['1', '+', '×', '5']), ['1', '×', '5']);
expect(Calculate.formatList(['1', '+', '%', '5']), ['1', '%', '5']);
});
// 字符串计算
test('Calculate->[LinierCalculate]计算一个字符串计算', () {
expect(Calculate.LinierCalculate('1+.3+5'), 6.3);
expect(Calculate.LinierCalculate('-1+0.3+5'), 4.3);
expect(Calculate.LinierCalculate('-1*3+5'), 2);
expect(Calculate.LinierCalculate('-1/2+5'), 4.5);
});
``````

# 版本 0.0.1 #

## Use this package as a library

### 1. Depend on it

``````
dependencies:
string_num_calculate: ^0.0.2

``````

### 2. Install it

You can install packages from the command line:

with pub:

``````
\$ pub get

``````

with Flutter:

``````
\$ flutter pub get

``````

Alternatively, your editor might support `pub get` or `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:string_num_calculate/string_num_calculate.dart';
``````
 Popularity: Describes how popular the package is relative to other packages. [more] 0 Health: Code health derived from static analysis. [more] 100 Maintenance: Reflects how tidy and up-to-date the package is. [more] 40 Overall: Weighted score of the above. [more] 38

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

• Dart: 2.7.1
• pana: 0.13.6

#### Health suggestions

Fix `lib/src/calculate.dart`. (-0.50 points)

Analysis of `lib/src/calculate.dart` reported 1 hint:

line 78 col 16: Use isEmpty instead of length

#### Maintenance issues and suggestions

The description contains too many non-ASCII characters. (-20 points)

The site uses English as its primary language. The value of the `description` field in your package's `pubspec.yaml` field should primarily contain characters used in English.

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

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.