Skip to content

Commit

Permalink
Merge pull request #12 from via-guy/nnbd
Browse files Browse the repository at this point in the history
Upgrade to nullability
  • Loading branch information
mariazebrowska authored Jun 22, 2021
2 parents dc4f25e + 59c471f commit c951f87
Show file tree
Hide file tree
Showing 26 changed files with 648 additions and 617 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

- uses: subosito/flutter-action@v1
with:
flutter-version: 1.20.2
flutter-version: 2.2.0

- name: build
run: |
Expand All @@ -42,7 +42,7 @@ jobs:
- name: test
run: |
flutter pub run test_coverage --no-badge
flutter test --coverage
flutter pub run remove_from_coverage -f coverage/lcov.info -r ".g.dart$" -r ".freezed.dart$"
- name: publish (dry-run)
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.0

* Upgrade to nullability
* Unescape newline characters #11

## 0.1.4

* Remove unescaping from download command #10
Expand Down
3 changes: 3 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: flutter_lokalise_example

environment:
sdk: ">=2.12.0 <3.0.0"

dev_dependencies:
flutter_lokalise:
path: ..
Expand Down
25 changes: 10 additions & 15 deletions lib/src/arb_converter/json_to_arb_converter.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import 'package:meta/meta.dart';
import 'package:quiver/check.dart';

class JsonToArbConverter {
Map<String, Object> toArb({
@required Map<String, Object> json,
@required String locale,
Map<String, dynamic> toArb({
required Map<String, dynamic> json,
required String locale,
}) {
checkNotNull(json);
checkNotNull(locale);

final arbMap = <String, Object>{};
final arbMap = <String, dynamic>{};
arbMap["@@locale"] = locale;
final flattenedKeyMap = json.entries.fold(
<String, Object>{},
(Map<String, Object> accumulator, entry) => accumulator..addFlattenedEntry(entry),
<String, dynamic>{},
(Map<String, dynamic> accumulator, entry) =>
accumulator..addFlattenedEntry(entry),
);
arbMap.addAll(flattenedKeyMap);
return arbMap;
}
}

extension _MapExtension on Map<String, Object> {
void addFlattenedEntry(MapEntry<String, Object> entry) {
extension _MapExtension<K, V> on Map<K, V> {
void addFlattenedEntry(MapEntry<K, V> entry) {
final value = entry.value;
if (value is Map<String, Object>) {
if (value is Map<K, V>) {
value.entries.forEach((it) => addFlattenedEntry(it));
} else {
this[entry.key] = entry.value;
Expand Down
4 changes: 3 additions & 1 deletion lib/src/client/downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'dart:io';
class Downloader {
Future<List<int>> download(String url) async {
final httpClient = HttpClient();
final response = await httpClient.getUrl(Uri.parse(url)).then((request) => request.close());
final response = await httpClient
.getUrl(Uri.parse(url))
.then((request) => request.close());
return await response.fold([], (List<int> accumulator, List<int> next) {
return accumulator..addAll(next);
});
Expand Down
28 changes: 18 additions & 10 deletions lib/src/client/files_download_request_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@ part 'files_download_request_body.freezed.dart';
part 'files_download_request_body.g.dart';

@freezed
abstract class FilesDownloadRequestBody implements _$FilesDownloadRequestBody {
class FilesDownloadRequestBody with _$FilesDownloadRequestBody {
factory FilesDownloadRequestBody({
@required String format,
@nullable @JsonKey(name: "original_filenames") @Default(false) bool originalFilenames,
@nullable @JsonKey(name: "all_platforms") @Default(true) bool allPlatforms,
@nullable @JsonKey(name: "plural_format") @Default("icu") String pluralFormat,
@nullable @JsonKey(name: "placeholder_format") @Default("icu") String placeholderFormat,
@nullable @JsonKey(name: "include_tags") Iterable<String> includeTags,
@nullable @JsonKey(name: "include_comments") @Default(true) bool includeComments,
@nullable @JsonKey(name: "include_description") @Default(true) bool includeDescription,
@nullable @JsonKey(name: "json_unescaped_slashes") @Default(true) bool jsonUnescapedSlashes,
required String format,
@JsonKey(name: "original_filenames")
@Default(false)
bool? originalFilenames,
@JsonKey(name: "all_platforms") @Default(true) bool? allPlatforms,
@JsonKey(name: "plural_format") @Default("icu") String? pluralFormat,
@JsonKey(name: "placeholder_format")
@Default("icu")
String? placeholderFormat,
@JsonKey(name: "include_tags") Iterable<String>? includeTags,
@JsonKey(name: "include_comments") @Default(true) bool? includeComments,
@JsonKey(name: "include_description")
@Default(true)
bool? includeDescription,
@JsonKey(name: "json_unescaped_slashes")
@Default(true)
bool? jsonUnescapedSlashes,
}) = _FilesDownloadRequestBody;

factory FilesDownloadRequestBody.fromJson(Map<String, dynamic> json) =>
Expand Down
Loading

0 comments on commit c951f87

Please sign in to comment.