Skip to content

Commit

Permalink
chore: improvements (#2)
Browse files Browse the repository at this point in the history
• Update ReadMe
• Add `separate` function in ListExtension
  • Loading branch information
ThomasDevApps authored May 1, 2024
1 parent 9333b73 commit b26e316
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 26 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/flutter_test.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
name: Flutter
name: MAIN CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main", "dev" ]
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
Expand All @@ -21,7 +23,7 @@ jobs:
run: flutter pub get

- name: Analyze project source
run: flutter analyze --no-fatal-infos
run: flutter analyze

- name: Run tests
run: flutter test
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,28 @@ and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
# helper_extension

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

TODO: List what your package can do. Maybe include images, gifs, or videos.
Packages containing a number of useful extensions not present by default.

## Getting started
## List

TODO: List prerequisites and provide or point to information on how to
start using the package.
- `replaceItem`
- `replaceItemAtIndex`
- `swapItems`
- `swapItemsAtIndex`
- `separate`

## Usage
## Map

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
- `replaceValue`

```dart
const like = 'sample';
```
## String

## Additional information
- `firstLetterToUpperCase`

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
## Widget

- `toFittedBox`
43 changes: 43 additions & 0 deletions coverage/lcov.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
SF:lib\src\helper_extension_map.dart
DA:6,1
DA:7,1
DA:8,1
LF:3
LH:3
end_of_record
SF:lib\src\helper_extension_list.dart
DA:5,1
DA:9,1
DA:10,1
DA:14,1
DA:18,1
DA:19,1
DA:23,1
DA:24,1
DA:25,1
DA:26,1
DA:31,1
DA:32,1
DA:33,2
DA:34,1
DA:35,1
DA:39,1
DA:40,1
DA:41,2
DA:42,2
DA:43,2
DA:44,3
LF:21
LH:21
end_of_record
SF:lib\src\helper_extension_string.dart
DA:7,5
LF:1
LH:1
end_of_record
SF:lib\src\helper_extension_text.dart
DA:10,0
DA:13,0
LF:2
LH:0
end_of_record
2 changes: 1 addition & 1 deletion lib/helper_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ library helper_extension;
export 'src/helper_extension_list.dart';
export 'src/helper_extension_map.dart';
export 'src/helper_extension_string.dart';
export 'src/helper_extension_text.dart';
export 'src/helper_extension_widget.dart';
13 changes: 13 additions & 0 deletions lib/src/helper_extension_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,17 @@ extension HelperExtensionList<E> on List<E> {
insert(firstIndex, secondItem);
insert(secondIndex, firstItem);
}

/// Function to add [separator] between each item of the list.
List<E> separate(E separator) {
final copy = List<E>.from(this);
if (copy.length > 1) {
for (var item in this) {
if (item != last) {
copy.insert(copy.indexOf(item) + 1, separator);
}
}
}
return copy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ library helper_extension;

import 'package:flutter/material.dart';

extension HelperExtensionText on Text {
/// Function to transform the [Text] to a [FittedBox].
extension HelperExtensionText on Widget {
/// Function to transform the [Widget] to a [FittedBox].
///
/// We set the [fit] to [BoxFit.scaleDown] to scale down the text
/// in the case of overflowed.
Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: helper_extension
description: A new Flutter project.
version: 0.0.1
homepage:
version: 0.0.2

environment:
sdk: '>=3.1.3 <4.0.0'
Expand Down
17 changes: 17 additions & 0 deletions test/helper_extension_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,21 @@ void main() {
list.swapItemsAtIndex(0, 1);
expect(list, ['b', 'a', 'c']);
});

group('Test separate', () {
test('Test case when length of list is 0', () {
final list = [];
expect(list.separate(','), []);
});

test('Test case when length of list is 1', () {
final list = ['a'];
expect(list.separate(','), ['a']);
});

test('Test case when length of list is 2', () {
final list = ['a', 'b'];
expect(list.separate(','), ['a', ',', 'b']);
});
});
}

0 comments on commit b26e316

Please sign in to comment.