Skip to content

Commit 122878e

Browse files
committed
doc
1 parent 4b14d15 commit 122878e

File tree

5 files changed

+217
-28
lines changed

5 files changed

+217
-28
lines changed

.github/workflows/checkout.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: Dart
7+
8+
on:
9+
pull_request:
10+
branches: [ "main" ]
11+
paths:
12+
- 'lib/**'
13+
- '.github/**'
14+
push:
15+
branches: [ "main" ]
16+
paths:
17+
- '.github/**'
18+
19+
jobs:
20+
checkout:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Check out code
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Flutter
28+
uses: subosito/flutter-action@v2
29+
with:
30+
channel: stable
31+
flutter-version: 3.24.3
32+
33+
- name: Install dependencies
34+
run: flutter pub get
35+
36+
- name: Run tests with coverage
37+
run: flutter test --coverage
38+
39+
- name: Upload coverage to Codecov
40+
uses: codecov/codecov-action@v4
41+
with:
42+
token: ${{ secrets.CODECOV_TOKEN }}
43+
44+
- name: Analyze project source
45+
run: flutter analyze --fatal-infos --fatal-warnings lib/ test/
46+

README.md

Lines changed: 148 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,164 @@
1-
<!--
2-
This README describes the package. If you publish this package to pub.dev,
3-
this README's contents appear on the landing page for your package.
41

5-
For information about how to write a good package README, see the guide for
6-
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
2+
# Pike
73

8-
For general information about developing packages, see the Dart guide for
9-
[creating packages](https://dart.dev/guides/libraries/create-packages)
10-
and the Flutter guide for
11-
[developing packages and plugins](https://flutter.dev/to/develop-packages).
12-
-->
4+
![Pub Version](https://img.shields.io/pub/v/pike)
5+
![License](https://img.shields.io/github/license/contributors-company/pike)
6+
![Issues](https://img.shields.io/github/issues/contributors-company/pike)
7+
![Coverage](https://img.shields.io/codecov/c/github/contributors-company/pike)
8+
![Stars](https://img.shields.io/github/stars/contributors-company/pike)
139

14-
TODO: Put a short description of the package here that helps potential users
15-
know whether this package might be useful for them.
10+
`Pike` is a state management library for Flutter based on the **Event-Driven** pattern. It uses event streams to manage state and provides convenient components for interacting with the state, such as `PikeBuilder`, `PikeConsumer`, and `PikeProvider`.
1611

1712
## Features
1813

19-
TODO: List what your package can do. Maybe include images, gifs, or videos.
14+
- **State management using events**: The state is updated in response to events.
15+
- **Components for listening to and displaying state**: `PikeBuilder`, `PikeConsumer`, and `PikeProvider` are used to manage and display state changes.
16+
- **Customizable event handling**: Allows for custom event handlers and selective state rebuilds.
2017

21-
## Getting started
18+
## Installation
2219

23-
TODO: List prerequisites and provide or point to information on how to
24-
start using the package.
20+
Add `pike` to your `pubspec.yaml` file:
21+
22+
```yaml
23+
dependencies:
24+
pike: ^latest_version
25+
```
2526
2627
## Usage
2728
28-
TODO: Include short and useful examples for package users. Add longer examples
29-
to `/example` folder.
29+
### Creating a Pike instance
30+
31+
Create a `Pike` instance by passing an initial state:
32+
33+
```dart
34+
final class MockPike extends Pike<Event, State> {
35+
MockPike() : super(InitialState()) {
36+
on<Event>((event, emit) => switch(event) {
37+
FetchEvent() => _callback(event, emit),
38+
FetchWithExceptionEvent() => _callbackA(event, emit),
39+
});
40+
41+
}
42+
43+
Future<void> _callback(FetchEvent event, Emit<State> emit) async {
44+
emit(LoadedState());
45+
}
46+
47+
void _callbackA(FetchWithExceptionEvent event, Emit<State> emit) {
48+
emit(ExceptionState());
49+
}
50+
}
51+
52+
// Events
53+
54+
sealed class Event {}
55+
56+
class FetchEvent extends Event {}
57+
58+
class FetchWithExceptionEvent extends Event {}
59+
60+
// States
61+
62+
sealed class State {}
63+
64+
class InitialState extends State {}
65+
66+
class LoadedState extends State {}
67+
68+
class ExceptionState extends State {}
69+
```
70+
71+
### Adding events
72+
73+
Add events to the `Pike` instance to trigger state changes:
74+
75+
```dart
76+
pike.add(MyEvent());
77+
```
78+
79+
### Listening to state changes
80+
81+
Use `PikeBuilder` or `PikeConsumer` to rebuild your widgets when the state changes:
82+
83+
```dart
84+
PikeBuilder<MyPike, MyState>(
85+
builder: (context, state) {
86+
return Text('Current State: $state');
87+
},
88+
);
89+
```
90+
91+
### Providing the Pike instance
92+
93+
Wrap your widget tree with `PikeProvider` to provide the `Pike` instance to the widgets:
94+
95+
```dart
96+
PikeProvider<MyPike>(
97+
pike: pike,
98+
child: MyWidget(),
99+
);
100+
```
101+
102+
### Custom event handling with `PikeObserver`
103+
104+
You can implement `PikeObserver` to track the lifecycle and events of your `Pike` instances:
105+
106+
```dart
107+
class MyPikeObserver extends PikeObserver {
108+
@override
109+
void onCreate<P extends Pike<Object?, Object?>>(P pike) {
110+
print("Pike created");
111+
}
112+
113+
@override
114+
void onEvent<P extends Pike<Object?, Object?>, Event>(
115+
P pike,
116+
Event event,
117+
) {
118+
print("Event occurred: $event");
119+
}
120+
}
121+
```
122+
123+
## Components
124+
125+
### `PikeBuilder`
126+
127+
A widget that listens to state changes and rebuilds when the state updates.
128+
129+
```dart
130+
PikeBuilder<MyPike, MyState>(
131+
builder: (context, state) {
132+
return Text('Current State: $state');
133+
},
134+
);
135+
```
136+
137+
### `PikeConsumer`
138+
139+
A widget that listens to state changes and provides a custom listener to trigger side effects.
140+
141+
```dart
142+
PikeConsumer<MyPike, MyState>(
143+
builder: (context, state) {
144+
return Text('Current State: $state');
145+
},
146+
listener: (context, state) {
147+
// Handle side effects here
148+
},
149+
);
150+
```
151+
152+
### `PikeProvider`
153+
154+
A widget that provides a `Pike` instance to its descendants.
30155

31156
```dart
32-
const like = 'sample';
157+
PikeProvider<MyPike>(
158+
pike: pike,
159+
child: MyWidget(),
160+
);
33161
```
34162

35-
## Additional information
163+
## Codecov
36164

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

analysis_options.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ analyzer:
3939
linter:
4040
rules:
4141
# Public packages
42-
public_member_api_docs: true
42+
## TODO
43+
public_member_api_docs: false
4344
lines_longer_than_120_chars: true
4445

4546
# Enabling rules

pubspec.yaml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
name: pike
2-
description: "A new Flutter project."
2+
description: "Pike is an event-driven state management library, enabling efficient state updates and handling through events."
33
version: 0.0.1
4-
homepage:
4+
homepage: https://www.contributors.info/repository/pike
5+
6+
repository: https://github.com/contributors-company/pike
7+
8+
issue_tracker: https://github.com/contributors-company/pike/issues
9+
10+
topics:
11+
- pike
12+
- state-management
13+
- state
14+
- event-driven
15+
16+
platforms:
17+
android:
18+
ios:
19+
linux:
20+
macos:
21+
web:
22+
windows:
23+
524

625
environment:
726
sdk: ^3.5.4

test/mocks/mock_pike.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ final class MockPike extends Pike<Event, State> {
1212
}
1313

1414
Future<void> _callback(FetchEvent event, Emit<State> emit) async {
15-
print(event);
1615
emit(LoadedState());
1716
}
1817

1918
void _callbackA(FetchWithExceptionEvent event, Emit<State> emit) {
20-
print(event);
2119
emit(ExceptionState());
2220
}
2321
}

0 commit comments

Comments
 (0)