Skip to content

Commit 6f178a2

Browse files
committed
move to flutter v2
1 parent c2c1353 commit 6f178a2

File tree

11 files changed

+136
-187
lines changed

11 files changed

+136
-187
lines changed

.github/workflows/dart.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
java-version: '12.x'
2020
- uses: subosito/flutter-action@v1
2121
with:
22-
flutter-version: '1.22.0'
22+
flutter-version: '2.0.5'
2323
channel: 'stable'
2424
- name: Install dependencies
2525
run: flutter pub get

lib/habr/api.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Habr {
3636
String ordString = orderToText[order];
3737
final url =
3838
"$api_url_v2/articles/?query=$query&order=$ordString&fl=ru&hl=ru&page=$page";
39-
final response = await safe(http.get(url));
39+
final response = await safe(http.get(Uri.parse(url)));
4040
return response
4141
.then(checkHttpStatus)
4242
.map(parseJson)
@@ -49,49 +49,49 @@ class Habr {
4949
final url =
5050
"$api_url_v2/articles/?period=daily&sort=date&fl=ru&hl=ru&page=$page";
5151
logInfo("Get articles by $url");
52-
final response = await safe(http.get(url));
52+
final response = await safe(http.get(Uri.parse(url)));
5353
return response
5454
.then(checkHttpStatus)
55-
.asyncMap(asyncParseJson)
56-
.then((val) => val.map((data) => parsePostPreviewsFromJson(data)));
55+
.mapAsync(asyncParseJson)
56+
.mapRight((data) => parsePostPreviewsFromJson(data));
5757
}
5858

5959
Future<Either<AppError, PostPreviews>> userPosts(String user,
6060
{int page = 1}) async {
6161
final url =
6262
"$api_url_v2/articles/?user=$user&sort=date&fl=ru&hl=ru&page=$page";
6363
logInfo("Get articles by $url");
64-
final response = await safe(http.get(url));
64+
final response = await safe(http.get(Uri.parse(url)));
6565
return response
6666
.then(checkHttpStatus)
67-
.asyncMap(asyncParseJson)
68-
.then((val) => val.map((data) => parsePostPreviewsFromJson(data)));
67+
.mapAsync(asyncParseJson)
68+
.mapRight((data) => parsePostPreviewsFromJson(data));
6969
}
7070

7171
Future<Either<AppError, AuthorInfo>> userInfo(String user) async {
7272
final url = "$api_url_v2/users/$user/card?fl=ru&hl=ru";
7373
logInfo("Get user info by $url");
74-
final response = await safe(http.get(url));
74+
final response = await safe(http.get(Uri.parse(url)));
7575
return response
7676
.then(checkHttpStatus)
77-
.asyncMap(asyncParseJson)
78-
.then((val) => val.map((data) => parseAuthorInfoFromJson(data)));
77+
.mapAsync(asyncParseJson)
78+
.mapRight((data) => parseAuthorInfoFromJson(data));
7979
}
8080

8181
Future<Either<AppError, Post>> article(String id) async {
8282
final url = "$api_url_v2/articles/$id";
8383
logInfo("Get article by $url");
84-
final response = await safe(http.get(url));
84+
final response = await safe(http.get(Uri.parse(url)));
8585
return response
8686
.then(checkHttpStatus)
87-
.asyncMap(asyncParseJson)
88-
.then((val) => val.map((data) => parsePostFromJson(data)));
87+
.mapAsync(asyncParseJson)
88+
.mapRight((data) => parsePostFromJson(data));
8989
}
9090

9191
Future<Either<AppError, Comments>> comments(String articleId) async {
9292
final url = "$api_url_v2/articles/$articleId/comments";
9393
logInfo("Get comments by $url");
94-
final response = await safe(http.get(url));
94+
final response = await safe(http.get(Uri.parse(url)));
9595
return response
9696
.then(checkHttpStatus)
9797
.map(parseJson)

lib/habr_storage/cache_tables.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CachedAuthorDao extends DatabaseAccessor<Cache> with _$CachedAuthorDaoMixi
4444
CachedAuthorDao(this.db) : super(db);
4545

4646
Future<List<CachedAuthor>> getAuthors(Iterable<String> ids) => (select(cachedAuthors)..where((authors) => authors.id.isIn(ids))).get();
47-
Future<CachedAuthor> getAuthor(String id) => (select(cachedAuthors)..where((authors) => authors.id.equals(id))).getSingle();
47+
Future<CachedAuthor> getAuthor(String id) => (select(cachedAuthors)..where((authors) => authors.id.equals(id))).getSingleOrNull();
4848
Future insertAuthor(Insertable<CachedAuthor> author) => into(cachedAuthors).insert(author);
4949
}
5050

@@ -78,11 +78,11 @@ class CachedPostDao extends DatabaseAccessor<Cache> with _$CachedPostDaoMixin {
7878
Future<int> count() async {
7979
final countExp = cachedPosts.id.count(distinct: true);
8080
final query = selectOnly(cachedPosts)..addColumns([countExp]);
81-
final result = await query.map((row) => row.read(countExp)).getSingle();
81+
final result = await query.map((row) => row.read(countExp)).getSingleOrNull();
8282
return result;
8383
}
8484

85-
Future<CachedPost> getPost(String id) => (select(cachedPosts)..where((posts) => posts.id.equals(id))).getSingle();
85+
Future<CachedPost> getPost(String id) => (select(cachedPosts)..where((posts) => posts.id.equals(id))).getSingleOrNull();
8686
Future insertPost(Insertable<CachedPost> post) => into(cachedPosts).insert(post);
8787
Future updatePost(Insertable<CachedPost> post) => update(cachedPosts).replace(post);
8888
Future deletePost(String id) => (delete(cachedPosts)..where((posts) => posts.id.equals(id))).go();
@@ -95,7 +95,7 @@ class CachedImagesDao extends DatabaseAccessor<Cache> with _$CachedImagesDaoMixi
9595
// Called by the AppDatabase class
9696
CachedImagesDao(this.db) : super(db);
9797

98-
Future<CachedImage> getImage(String url) => (select(cachedImages)..where((image) => image.url.equals(url))).getSingle();
98+
Future<CachedImage> getImage(String url) => (select(cachedImages)..where((image) => image.url.equals(url))).getSingleOrNull();
9999
Future insertImage(Insertable<CachedImage> image) => into(cachedImages).insert(image);
100100
Future deleteImage(String url) => (delete(cachedImages)..where((image) => image.url.equals(url))).go();
101101
}

lib/habr_storage/habr_storage.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class HabrStorage {
7474
Future<bool> addArticleInCache(String id) {
7575
return article(id)
7676
.then((postOrError) =>
77-
postOrError.asyncMap((post) => _cacheArticle(post)))
77+
postOrError.mapAsync((post) => _cacheArticle(post)))
7878
.then((cachedPost) => cachedPost.isRight);
7979
}
8080

@@ -94,7 +94,7 @@ class HabrStorage {
9494
Future<Either<AppError, Comments>> comments(String articleId) async {
9595
return api
9696
.comments(articleId)
97-
.then((value) => value.asyncMap(_checkCachedCommentsAuthors));
97+
.then((value) => value.mapAsync(_checkCachedCommentsAuthors));
9898
}
9999

100100
Future<Comments> _checkCachedCommentsAuthors(Comments comments) async {
@@ -150,7 +150,7 @@ class HabrStorage {
150150

151151
if (author.avatar.isNotDefault) {
152152
final maybeSavedImage = await imgStore.saveImage(author.avatar.url);
153-
avatarUrl = maybeSavedImage.unite((left) => null, (right) => right);
153+
avatarUrl = maybeSavedImage.fold((left) => null, (right) => right);
154154
}
155155

156156
await cache.cachedAuthorDao.insertAuthor(CachedAuthor(

lib/pages/search.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class _SearchPageState extends State<SearchPage> {
4141
@override
4242
Widget build(BuildContext context) {
4343
return Scaffold(
44-
resizeToAvoidBottomPadding: false,
44+
resizeToAvoidBottomInset: false,
4545
appBar: AppBar(
4646
title: Text(AppLocalizations.of(context).search),
4747
actions: [],

lib/pages/user.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class _UserPageState extends State<UserPage> {
168168
Text('@' + info.alias, style: TextStyle(color: theme.primaryColor)),
169169
if (info.fullName != null && info.fullName.isNotEmpty)
170170
Text("a.k.a. ${info.fullName}"),
171-
Text(info.speciality == null || info.speciality?.isEmpty
171+
Text(info.speciality == null || info.speciality.isEmpty
172172
? localization.user
173173
: info.speciality),
174174
if (info.about != null) Text(info.about),

lib/stores/article_store.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ abstract class ArticlesStorageBase with Store {
6262
Future loadFirstPage() async {
6363
firstLoading = LoadingState.inProgress;
6464
final firstPage = await loadPage(1);
65-
firstLoading = firstPage.unite<LoadingState>((left) {
65+
firstLoading = firstPage.fold<LoadingState>((left) {
6666
lastError = left;
6767
return LoadingState.isCorrupted;
6868
}, (right) {
@@ -76,7 +76,7 @@ abstract class ArticlesStorageBase with Store {
7676

7777
Future<PostPreviews> loadPosts(int page) async {
7878
final postOrError = await loadPage(page);
79-
return postOrError.unite<PostPreviews>((err) {
79+
return postOrError.fold<PostPreviews>((err) {
8080
// TODO: informing user
8181
return PostPreviews(previews: [], maxCountPages: -1);
8282
}, (posts) => posts);
@@ -100,7 +100,7 @@ abstract class ArticlesStorageBase with Store {
100100
void removePreview(String id) {
101101
previews.removeWhere((element) => element.id == id);
102102
_postIds.remove(id);
103-
previews = List()..addAll(previews);
103+
previews = List.from(previews);
104104
}
105105

106106
@action

lib/utils/workers/image_loader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ImageHttpLoader implements ImageLoader {
3131

3232
static Future<bool> _loadImage(_ArgObj args) async {
3333
try {
34-
final response = await http.get(args.url);
34+
final response = await http.get(Uri.parse(args.url));
3535

3636
if (checkHttpStatus(response).isLeft) {
3737
return false;

lib/widgets/load_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class LoadBuilder<Left, Right> extends StatelessWidget {
2727
case ConnectionState.done:
2828
if (snapshot.hasError)
2929
return onErrorBuilder(context, snapshot.error);
30-
return snapshot.data.unite<Widget>(
30+
return snapshot.data.fold<Widget>(
3131
(err) => (onLeftBuilder ?? onErrorBuilder)(context, err),
3232
(data) => onRightBuilder(context, data));
3333
default:

0 commit comments

Comments
 (0)