1
0
mirror of https://github.com/flutter/samples.git synced 2026-07-15 05:21:30 +00:00

Upgrading samples to flutter_lints, part 1 of n (#804)

This commit is contained in:
Brett Morgan
2021-06-05 12:24:28 +10:00
committed by GitHub
parent 14921d0c06
commit 936d1fdaae
230 changed files with 2361 additions and 2444 deletions

View File

@@ -7,7 +7,6 @@ import 'dart:typed_data';
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:pedantic/pedantic.dart';
import 'api_error.dart';
@@ -21,30 +20,28 @@ final _unsplashBaseUrl = Uri.parse('https://api.unsplash.com/');
/// requests to the Unsplash API.
class Unsplash {
Unsplash({
@required String accessKey,
http.BaseClient httpClient,
}) : assert(accessKey != null, 'accessKey must not be null'),
_accessKey = accessKey,
required String accessKey,
http.BaseClient? httpClient,
}) : _accessKey = accessKey,
_client = httpClient ?? http.Client();
final String _accessKey;
final http.Client _client;
final _log = Logger('Unsplash');
Future<SearchPhotosResponse> searchPhotos({
@required String query,
Future<SearchPhotosResponse?> searchPhotos({
required String query,
num page = 1,
num perPage = 10,
List<num> collections = const [],
SearchPhotosOrientation orientation,
SearchPhotosOrientation? orientation,
}) async {
final searchPhotosUrl = _unsplashBaseUrl
.replace(path: '/search/photos', queryParameters: <String, String>{
'query': query,
if (page != 1) 'page': '$page',
if (perPage != 10) 'per_page': '$perPage',
if (collections != null && collections.isNotEmpty)
'collections': '${collections.join(',')}',
if (collections.isNotEmpty) 'collections': collections.join(','),
if (orientation == SearchPhotosOrientation.landscape)
'orientation': 'landscape',
if (orientation == SearchPhotosOrientation.portrait)
@@ -72,8 +69,8 @@ class Unsplash {
if (body is Map &&
body['errors'] is List &&
body['errors'].isNotEmpty as bool) {
final apiError = ApiError.fromJson(response.body);
throw UnsplashException(apiError.errors.join(', '));
final apiError = ApiError.fromJson(response.body)!;
throw UnsplashException(apiError.errors!.join(', '));
}
return SearchPhotosResponse.fromJson(
@@ -85,14 +82,14 @@ class Unsplash {
// For detail on how downloading photos from Unsplash, please see
// https://help.unsplash.com/en/articles/2511258-guideline-triggering-a-download
_log.info('GET ${photo.urls.full}');
final futureBytes = http.readBytes(Uri.parse(photo.urls.full), headers: {
_log.info('GET ${photo.urls!.full}');
final futureBytes = http.readBytes(Uri.parse(photo.urls!.full!), headers: {
'Accept-Version': 'v1',
'Authorization': 'Client-ID $_accessKey',
});
_log.info('GET ${photo.links.downloadLocation}');
unawaited(http.get(Uri.parse(photo.links.downloadLocation), headers: {
_log.info('GET ${photo.links!.downloadLocation}');
unawaited(http.get(Uri.parse(photo.links!.downloadLocation!), headers: {
'Accept-Version': 'v1',
'Authorization': 'Client-ID $_accessKey',
}));
@@ -110,7 +107,7 @@ enum SearchPhotosOrientation {
class UnsplashException implements Exception {
UnsplashException([this.message]);
final String message;
final String? message;
@override
String toString() {