Skip to content

Commit b62f176

Browse files
authored
Release 0.13.0 (#29)
1 parent eaff1e2 commit b62f176

File tree

72 files changed

+1224
-1270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1224
-1270
lines changed

CHANGELOG.md

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
1+
12
# Changelog
23

3-
## [0.12.0] * Breaking Changes *
4+
## [0.13.0]
5+
6+
**Breaking Changes!**
7+
8+
* Removed the direct export `page.dart`. It's now included in `paged_list.dart` and `paged_filter_list.dart`,
9+
* Removed export of `view_state`,
10+
* Replaced `ViewStateBuilder` builders:
11+
* `onReady` -> `initial`
12+
* `onLoading` -> `loading`
13+
* `onRefreshing` -> `refreshing`
14+
* `onSuccess` -> `data`
15+
* `onEmpty` -> `empty`
16+
* `onError` -> `error`
17+
* Replaced `ConnectionBuilder` builders:
18+
* `onOnline` -> `online`
19+
* `onOffline` -> `offline`
20+
* Replaced `ViewStateListener` callbacks:
21+
* `onSuccess` -> `onData`
22+
23+
## [0.12.0]
24+
25+
**Breaking Changes!**
426

527
* Migrated to `dart` 3.0,
628
* Removed: `@Deprecated` methods,
@@ -16,28 +38,38 @@
1638

1739
* Migrated to `bloc` 8.0.x and `flutter_bloc` 8.0.x,
1840

19-
## [0.9.0] * Breaking Changes *
41+
## [0.9.0]
42+
43+
**Breaking Changes!**
2044

2145
* Migrated to `bloc` 7.0.0 and `flutter_bloc` 7.0.1,
2246
* Migrated to `null-safety`.
2347

24-
## [0.8.0] * Breaking Changes *
48+
## [0.8.0]
49+
50+
**Breaking Changes!**
2551

2652
* Migrated to `bloc` 6.1.1 and `flutter_bloc` 6.1.1.
2753

28-
## [0.7.0] * Breaking Changes *
54+
## [0.7.0]
55+
56+
**Breaking Changes!**
2957

3058
* Migrated to `bloc` 5.0.1 and `flutter_bloc` 5.0.1.
3159

32-
## [0.6.0] * Breaking Changes *
60+
## [0.6.0]
61+
62+
**Breaking Changes!**
3363

3464
* Changed `Page` should be imported via `package:flutter_bloc_patterns/page.dart`.
3565

36-
## [0.5.0] * Breaking Changes *
66+
## [0.5.0]
67+
68+
**Breaking Changes!**
3769

38-
* Changed: `RefreshView`, `ViewState` and `ViewStateBuilder` should be imported
70+
* Changed: `RefreshView`, `ViewState` and `ViewStateBuilder` should be imported
3971
via `package:flutter_bloc_patterns/view.dart`,
40-
* Changed: `ViewStateListener` for handling features that need to occur once per state change such
72+
* Changed: `ViewStateListener` for handling features that need to occur once per state change such
4173
as navigation, showing a `SnackBar`, showing a `Dialog`, etc,
4274
* Added: `const` constructors for `ViewState`.
4375

@@ -79,4 +111,4 @@
79111
* Added: `ListBloc` - a basic list BLoC with no filtering nor pagination,
80112
* Added: `FilterListBloc` - a list BLoC with filtering, but without pagination,
81113
* Added: `PagedListBloc` - a list BLoC with pagination but without filtering,
82-
* Added: `DetailsBloc` - a BLoC that allows to fetch a single element with given identifier.
114+
* Added: `DetailsBloc` - a BLoC that allows to fetch a single element with given identifier.

README.md

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,52 @@ A set of most common BLoC use cases build on top [flutter_bloc](https://github.c
88
## Key contepts
99

1010
##### BLoC
11+
1112
BLoC, aka **B**usiness **Lo**gic **C**omponent, is a state management system for Flutter. It's main goal is to separate business logic from the presentation layer. The BLoC handles user actions or any other events and generates new state for the view to render.
1213

1314
##### Repository
15+
1416
A `Repository` to handles data operations. It knows where to get the data from and what API calls to make when data is updated. A `Repository` can utilize a single data source as well as it can be a mediator between different data sources, such as database, web services and caches.
1517

1618
##### ViewStateBuilder
19+
1720
`ViewStateBuilder` is responsible for building the UI based on the view state. It's a wrapper over the `BlocBuilder` widget so it accepts a `bloc` object and a set of handy callbacks, which corresponds to each possible state:
1821

19-
* `onReady` - informs the presentation layer that view is in it's initial state, and no action has taken place yet,
20-
* `onLoading` - informs the presentation layer that the data is being loaded, so it can display a loading indicator,
21-
* `onRefreshing` - informs the presentation layer that the data is being refreshed, so it can display a refresh indicator or/and the current state of list items,
22-
* `onSuccess` - informs the presentation layer that the loading is completed and a `nonnull` and not empty data was retrieved,
23-
* `onEmpty` - informs the presentation layer that the loading is completed, but `null` or empty data was retrieved,
24-
* `onError` - informs the presentation layer that the loading or refreshing has ended with an error. It also provides an error that has occurred.
22+
* `initial` - informs the presentation layer that view is in it's initial state, and no action has taken place yet,
23+
* `loading` - informs the presentation layer that the data is being loaded, so it can display a loading indicator,
24+
* `refreshing` - informs the presentation layer that the data is being refreshed, so it can display a refresh indicator or/and the current state of list items,
25+
* `data` - informs the presentation layer that the loading is completed and a `nonnull` and not empty data was retrieved,
26+
* `empty` - informs the presentation layer that the loading is completed, but `null` or empty data was retrieved,
27+
* `error` - informs the presentation layer that the loading or refreshing has ended with an error. It also provides an error that has occurred.
2528

2629
##### ViewStateListener
30+
2731
`ViewStateListener` is responsible for performing an action based on the view state. It should be used for functionality that needs to occur only in response to a state change such as navigation, showing a `SnackBar` etc. `ViewStateListener` is a wrapper over the `BlocListener` widget so it accepts a `bloc` object as well as a `child` widget and a set of handy callbacks corresponding to a given state:
2832

2933
* `onLoading` - informs the presentation layer that the data is being loaded,
3034
* `onRefreshing` - informs the presentation layer that the data is being refreshed,
31-
* `onSuccess` - informs the presentation layer that the loading is completed and a `nonnull` and not empty data was retrieved,
35+
* `onData` - informs the presentation layer that the loading is completed and a `nonnull` and not empty data was retrieved,
3236
* `onEmpty` - informs the presentation layer that the loading is completed, but `null` or empty data was retrieved,
3337
* `onError` - informs the presentation layer that the loading or refreshing has ended with an error. It also provides an error that has occurred.
3438

3539
## Features
3640

3741
### ListBloc
38-
The most basic use case. Allows to fetch, refresh and display a list of items without filtering and pagination. Thus, `ListBloc` should be used only with a reasonable amount of data. `ListBloc` provides the methods for loading and refreshing data: `loaditems()` and `refreshitems()`. The former is most suitable for initial data fetch or for retry action when the first fetch fails. The latter is designed for being called after the initial fetch succeeds. It can be performed when the list has already been loaded. To display the current view state `ListBloc` cooperates with `BlocBuilder` as well as `ViewStateBuilder`.
42+
43+
The most basic use case. Allows to fetch, refresh and display a list of items without filtering and pagination. Thus, `ListBloc` should be used only with a reasonable amount of data.
44+
45+
`ListBloc` provides the methods for loading and refreshing data:
46+
47+
* `loaditems()` - most suitable for initial data fetch or for retry action when the first fetch fails,
48+
* `refreshitems()` - designed for being called after the initial fetch succeeds.
49+
50+
To display the current view state `ListBloc` cooperates with `BlocBuilder` as well as `ViewStateBuilder`.
3951

4052
##### ListRepository
4153

4254
A `ListRepository` implementation should provide only one method:
4355

44-
`Future<List<T>> getAll();` - this method is responsible for providing all the data to the `ListBloc`.
56+
* `Future<List<T>> getAll();` - this method is responsible for providing all the data to the `ListBloc`.
4557

4658
Where:
4759
* `T` is the item type returned by this repository.
@@ -51,14 +63,15 @@ Where:
5163
[List BLoC Sample App](example/lib/src/list_app.dart)
5264

5365
### FilterListBloc
66+
5467
An extension to the `ListBloc` that allows filtering.
5568

5669
##### FilterRepository
5770

5871
`FilterListRepository` provides two methods:
5972

60-
`Future<List<T>> getAll();` - this method is called when a `null` filter is provided and should return all items,
61-
`Future<List<T>> getBy(F filter);` - this method is called with `nonnull` filter and should return only items that match it.
73+
* `Future<List<T>> getAll();` - this method is called when a `null` filter is provided and should return all items,
74+
* `Future<List<T>> getBy(F filter);` - this method is called with `nonnull` filter and should return only items that match it.
6275

6376
Where:
6477
* `T` is the item type returned by this repository,
@@ -69,18 +82,22 @@ Where:
6982
[Filter List BLoC Sample App](example/lib/src/list_filter_app.dart)
7083

7184
### PagedListBloc
72-
A list BLoC with pagination but without filtering. It works best with [Infinite Widgets](https://github.com/jaumard/infinite_widgets) but a custom presentation layer can provided as well.
85+
86+
A list BLoC with pagination but without filtering. It works best with [Infinite Widgets](https://github.com/jaumard/infinite_widgets) but a custom presentation layer can be provided as well.
7387

7488
#### Page
89+
7590
Contains information about the current page, this is `number` and `size`.
7691

7792
#### PagedList
93+
7894
List of items with information if there are more items or not.
7995

8096
#### PagedListRepository
97+
8198
`PagedListRepository` comes with only one method:
8299

83-
`Future<List<T>> getAll(Page page);` - this method retrieves items meeting the pagination restriction provided by the `page` object.
100+
* `Future<List<T>> getAll(Page page);` - this method retrieves items meeting the pagination restriction provided by the `page` object.
84101
When items are exceeded it should return an empty list or throw `PageNotFoundException`. `PagedListBloc` will handle both cases in the same way.
85102

86103
Where:
@@ -91,19 +108,22 @@ Where:
91108
[Paged List BLoC Sample App](example/lib/src/list_paged_app.dart)
92109

93110
### PagedListFilterBloc
94-
A list BLoC with pagination and filtering. It works best with [Infinite Widgets](https://github.com/jaumard/infinite_widgets) but a custom presentation layer can provided as well.
111+
112+
A list BLoC with pagination and filtering. It works best with [Infinite Widgets](https://github.com/jaumard/infinite_widgets) but a custom presentation layer can be provided as well.
95113

96114
#### Page
115+
97116
Contains information about the current page, this is `number` and `size`.
98117

99118
#### PagedList
119+
100120
List of items with information if there are more items or not.
101121

102122
#### PagedListFilterRepository
103123
`PagedListFilterRepository` provides only two methods:
104124

105-
`Future<List<T>> getAll(Page page);` - retrieves items meeting the pagination restriction provided by the `page` object.
106-
`Future<List<T>> getBy(Page page, F filter);` - retrieves items meeting pagination as well as the filter restrictions provided by the `page` and `filter` objects.
125+
* `Future<List<T>> getAll(Page page);` - retrieves items meeting the pagination restriction provided by the `page` object.
126+
* `Future<List<T>> getBy(Page page, F filter);` - retrieves items meeting pagination as well as the filter restrictions provided by the `page` and `filter` objects.
107127

108128
When items are exceeded it should return an empty list or throw `PageNotFoundException`. `PagedListFilterBloc` will handle both cases in the same way.
109129

@@ -120,9 +140,10 @@ Where:
120140
A BLoC that allows to fetch a single item with given identifier.
121141

122142
#### DetailsRepository
143+
123144
`DetailsRepository` comes with only one method:
124145

125-
`Future<T> getById(I id);` - this method retrieves an item with given id. When there's no item matching the id the `null` should be returned or `itemNotFoundException` should be thrown. In both cases the `DetailsBloc` will emit `Empty` state.
146+
* `Future<T> getById(I id);` - this method retrieves an item with given id. When there's no item matching the id the `null` should be returned. In this cases the `DetailsBloc` will emit `Empty` state.
126147

127148
Where:
128149
* `T` is the item type returned by this repository,
@@ -155,8 +176,12 @@ Or whatever works for you. A sample implementation using `connectivity_plus` may
155176
class ConnectivityPlusRepository implements ConnectionRepository {
156177
@override
157178
Stream<Connection> observe() {
158-
return connectivity.onConnectivityChanged.map(
159-
(ConnectivityResult result) => result != ConnectivityResult.none
179+
// Required due to https://github.com/fluttercommunity/plus_plugins/issues/2527
180+
return MergeStream([
181+
Stream.fromFuture(_connectivity.checkConnectivity()),
182+
_connectivity.onConnectivityChanged,
183+
]).map(
184+
(ConnectivityResult result) => result != ConnectivityResult.none
160185
? Connection.online
161186
: Connection.offline,
162187
);
@@ -170,8 +195,8 @@ class ConnectivityPlusRepository implements ConnectionRepository {
170195

171196
It's a wrapper over the `BlocBuilder` widget so it accepts a `bloc` object and provides `WidgetBuilder` functions for possible states:
172197

173-
* `onOnline` - a builder for the the `Connection.online` state,
174-
* `onOffline` - a builder for the the `Connection.offline` state,
198+
* `online` - a builder for the the `Connection.online` state,
199+
* `offline` - a builder for the the `Connection.offline` state,
175200

176201
#### ConnectionListener
177202

@@ -190,7 +215,7 @@ It should be used for functionality that needs to occur only once in response to
190215

191216
## Dart version
192217

193-
- Dart 2: >= 2.12.0
218+
- Dart 3: >= 3.0.0
194219

195220
## Author
196221
- [Karol Lisiewicz](https://github.com/klisiewicz)

example/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Samples illustrating the usage of BLoC Patterns.
88
3. [Paged List BLoC](lib/src/list_paged_app.dart).
99
4. [Paged Filter List BLoC](lib/src/list_paged_filter_app.dart).
1010
5. [Details BLoC](lib/src/list_details_app.dart).
11+
6. [Connection BLoC](lib/src/connection_app.dart).

example/android/app/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727

2828
android {
29-
compileSdkVersion 32
29+
compileSdkVersion 33
3030

3131
sourceSets {
3232
main.java.srcDirs += 'src/main/kotlin'
@@ -36,8 +36,8 @@ android {
3636
defaultConfig {
3737
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3838
applicationId "pl.karollisiewicz.bloc.example"
39-
minSdkVersion 16
40-
targetSdkVersion 32
39+
minSdkVersion 19
40+
targetSdkVersion 33
4141
versionCode flutterVersionCode.toInteger()
4242
versionName flutterVersionName
4343
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
@@ -53,6 +53,7 @@ android {
5353
lint {
5454
disable 'InvalidPackage'
5555
}
56+
namespace 'pl.karollisiewicz.bloc.example'
5657
}
5758

5859
flutter {

example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="pl.karollisiewicz.bloc.example">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32
<!-- Flutter needs it to communicate with the running application
43
to allow setting breakpoints, to provide hot reload, etc.
54
-->

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="pl.karollisiewicz.bloc.example">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32

43
<uses-permission android:name="android.permission.INTERNET" />
54

example/android/app/src/profile/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="pl.karollisiewicz.bloc.example">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32
<!-- Flutter needs it to communicate with the running application
43
to allow setting breakpoints, to provide hot reload, etc.
54
-->

example/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:7.2.1'
9+
classpath 'com.android.tools.build:gradle:8.1.4'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
}
1212
}
@@ -26,6 +26,6 @@ subprojects {
2626
project.evaluationDependsOn(':app')
2727
}
2828

29-
task clean(type: Delete) {
29+
tasks.register('clean', Delete) {
3030
delete rootProject.buildDir
3131
}

example/android/gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ org.gradle.jvmargs=-Xmx1536M
33
android.enableR8=true
44
android.useAndroidX=true
55
android.enableJetifier=true
6+
android.defaults.buildfeatures.buildconfig=true
7+
android.nonTransitiveRClass=false
8+
android.nonFinalResIds=false

example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip

0 commit comments

Comments
 (0)