Skip to content

Commit

Permalink
chore: add int extension (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDevApps authored May 1, 2024
1 parent b26e316 commit 099b59f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flutter_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: MAIN CI
name: Main CI

on:
push:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and the Flutter guide for

# helper_extension

![testing workflow](https://github.com/ThomasDevApps/lottery/actions/workflows/flutter_test.yml/badge.svg)
![testing workflow](https://github.com/ThomasDevApps/helper_extension/actions/workflows/flutter_test.yml/badge.svg)

Packages containing a number of useful extensions not present by default.

Expand All @@ -33,6 +33,10 @@ Packages containing a number of useful extensions not present by default.

- `firstLetterToUpperCase`

## Int

- `toList`

## Widget

- `toFittedBox`
15 changes: 15 additions & 0 deletions lib/src/helper_extension_int.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extension HelperExtensionInt on int {
/// Function to convert a int to a List.
///
///```dart
/// final list = 3.toList();
/// print(list); // [0, 1, 2]
///```
List<int> toList() {
final list = List<int>.empty(growable: true);
for (int i = 0; i < this; i++) {
list.add(i);
}
return list;
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: helper_extension
description: A new Flutter project.
version: 0.0.2
version: 0.0.3

environment:
sdk: '>=3.1.3 <4.0.0'
Expand Down
18 changes: 18 additions & 0 deletions test/helper_extension_int_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:helper_extension/src/helper_extension_int.dart';

void main() {
group('Test toList', () {
test('Function return []', () {
expect(0.toList(), []);
});

test('Function return [0]', () {
expect(1.toList(), [0]);
});

test('Function return [0, 1, 2]', () {
expect(3.toList(), [0, 1, 2]);
});
});
}

0 comments on commit 099b59f

Please sign in to comment.