Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release

on:
workflow_dispatch:
release:
types: [published]

jobs:
test:
name: Test and Analyze
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Flutter
uses: subosito/flutter-action@v1
with:
channel: 'stable'

- name: Download pub dependencies
run: flutter pub get

- name: Check formatting
run: flutter format --set-exit-if-changed --dry-run .

- name: Run analyzer
run: flutter analyze

- name: Run tests
run: flutter test
publish:
name: Publish to pub.dev
if: success()
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: flutter_bloc_patterns
uses: k-paxian/dart-package-publisher@master
with:
accessToken: ${{ secrets.OAUTH_ACCESS_TOKEN }}
refreshToken: ${{ secrets.OAUTH_REFRESH_TOKEN }}
format: true
skipTests: true
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Flutter analyze and tests

on:
pull_request:
branches:
- 'master'
tags-ignore:
- 'v*'

jobs:
on-pull-request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v1
with:
channel: 'stable'

- name: Download pub dependencies
run: flutter pub get

- name: Check formatting
run: flutter format --set-exit-if-changed --dry-run .

- name: Run analyzer
run: flutter analyze

- name: Run tests
run: flutter test
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Changelog

## [0.9.0] * Breaking Changes *

* Migrating to `bloc` 7.0.0 and `flutter_bloc` 7.0.1,
* Migrating to `null-safety`.

## [0.8.0] * Breaking Changes *

* Migrating to `bloc` 6.1.1 and `flutter_bloc` 6.1.1.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Where:

## Dart version

- Dart 2: >= 2.6.0
- Dart 2: >= 2.12.0

## Author
- [Karol Lisiewicz](https://github.com/klisiewicz)
12 changes: 6 additions & 6 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ android {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
Expand All @@ -43,7 +40,7 @@ android {
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

buildTypes {
Expand All @@ -53,6 +50,9 @@ android {
signingConfig signingConfigs.debug
}
}
lint {
disable 'InvalidPackage'
}
}

flutter {
Expand All @@ -62,6 +62,6 @@ flutter {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.2.71'
ext.kotlin_version = '1.3.40'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 2 additions & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
org.gradle.jvmargs=-Xmx1536M

android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
8 changes: 4 additions & 4 deletions example/lib/src/album/model/album.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import 'package:flutter/foundation.dart';
@immutable
class Album {
final int id;
final String title;
final String? title;

const Album({
@required this.id,
required this.id,
this.title,
}) : assert(id != null);
});

factory Album.fromJson(Map<String, dynamic> json) {
return Album(
id: json['id'] as int,
title: json['title'] as String,
title: json['title'] as String?,
);
}
}
10 changes: 5 additions & 5 deletions example/lib/src/album/model/photo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class Photo {
final String thumbnailUrl;

Photo({
this.id,
this.title,
this.url,
this.thumbnailUrl,
required this.id,
required this.title,
required this.url,
required this.thumbnailUrl,
});

factory Photo.fromJson(dynamic json) {
factory Photo.fromJson(Map json) {
return Photo(
id: json['id'] as int,
title: json['title'] as String,
Expand Down
33 changes: 21 additions & 12 deletions example/lib/src/album/model/photo_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,45 @@ import 'dart:io';

import 'package:example/src/album/model/album.dart';
import 'package:example/src/album/model/photo.dart';
import 'package:example/src/common/url.dart';
import 'package:flutter_bloc_patterns/page.dart';
import 'package:flutter_bloc_patterns/paged_filter_list.dart';
import 'package:http/http.dart' as http;

class PagedFilterPhotoRepository
implements PagedListFilterRepository<Photo, Album> {
static const _photosUrl = '$baseUrl/photos';

@override
Future<List<Photo>> getAll(Page page) => getBy(page, null);
Future<List<Photo>> getAll(Page page) async {
final uri = _buildUri(page, null);
return _getPhotosFrom(uri);
}

@override
Future<List<Photo>> getBy(Page page, Album album) async {
final response = await http.get(_buildUrl(page, album));
final uri = _buildUri(page, album);
return _getPhotosFrom(uri);
}

Future<List<Photo>> _getPhotosFrom(Uri uri) async {
final response = await http.get(uri);
if (response.statusCode != HttpStatus.ok) {
throw Exception('Failed to load photos');
}

final dynamic postsJson = json.decode(response.body);
return (postsJson is List)
? postsJson.map((photo) => Photo.fromJson(photo)).toList()
? postsJson.map((photo) => Photo.fromJson(photo as Map)).toList()
: [];
}

String _buildUrl(Page page, Album album) {
final pageQuery = '_start=${page.offset}&_limit=${page.size}';
final userQuery = (album != null) ? 'albumId=${album.id}' : null;
final query = pageQuery + (userQuery != null ? '&$userQuery' : '');
return '$_photosUrl/?$query';
static Uri _buildUri(Page page, Album? album) {
return Uri(
scheme: 'http',
host: 'jsonplaceholder.typicode.com',
path: 'photos',
queryParameters: {
'_start': '${page.offset}',
'_limit': '${page.size}',
if (album != null) 'albumId': '${album.id}'
},
);
}
}
10 changes: 6 additions & 4 deletions example/lib/src/album/ui/photos_list_empty.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';

class PhotosListEmpty extends StatelessWidget {
const PhotosListEmpty({Key key}) : super(key: key);
const PhotosListEmpty({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) => const Center(
child: Text('No photos found'),
);
Widget build(BuildContext context) {
return const Center(
child: Text('No photos found'),
);
}
}
9 changes: 6 additions & 3 deletions example/lib/src/album/ui/photos_list_paged.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class PhotosListPaged extends StatelessWidget {

const PhotosListPaged(
this.page, {
Key key,
@required this.onLoadNextPage,
Key? key,
required this.onLoadNextPage,
}) : super(key: key);

@override
Expand All @@ -30,7 +30,10 @@ class PhotosListPaged extends StatelessWidget {
class _PhotoGridItem extends StatelessWidget {
final Photo photo;

const _PhotoGridItem(this.photo, {Key key}) : super(key: key);
const _PhotoGridItem(
this.photo, {
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand Down
12 changes: 8 additions & 4 deletions example/lib/src/common/error_message.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import 'package:flutter/widgets.dart';

class ErrorMessage extends StatelessWidget {
final dynamic error;
final Object error;

const ErrorMessage({
Key key,
this.error,
required this.error,
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) => Center(child: Text(error.toString()));
Widget build(BuildContext context) {
return Center(
child: Text(error.toString()),
);
}
}
10 changes: 6 additions & 4 deletions example/lib/src/common/loading_indicator.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';

class LoadingIndicator extends StatelessWidget {
const LoadingIndicator({Key key}) : super(key: key);
const LoadingIndicator({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) => const Center(
child: CircularProgressIndicator(),
);
Widget build(BuildContext context) {
return const Center(
child: CircularProgressIndicator(),
);
}
}
22 changes: 12 additions & 10 deletions example/lib/src/common/loading_page_indicator.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import 'package:flutter/material.dart';

class LoadingPageIndicator extends StatelessWidget {
const LoadingPageIndicator({Key key}) : super(key: key);
const LoadingPageIndicator({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) => Container(
padding: const EdgeInsets.symmetric(vertical: 8),
child: const Center(
child: SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(strokeWidth: 1.5),
),
Widget build(BuildContext context) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: Center(
child: SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(strokeWidth: 1.5),
),
);
),
);
}
}
1 change: 0 additions & 1 deletion example/lib/src/common/url.dart

This file was deleted.

Loading