From 43d29a2ab3909a12e5d3a024319db3a2e7d333b9 Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Wed, 22 Nov 2023 18:13:37 +0900 Subject: [PATCH 01/13] =?UTF-8?q?freezed=20=E3=81=BE=E3=82=8F=E3=82=8A?= =?UTF-8?q?=E3=81=AE=E4=BE=9D=E5=AD=98=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pubspec.lock | 352 +++++++++++++++++++++++++++++++++++++++++++++++++++ pubspec.yaml | 5 + 2 files changed, 357 insertions(+) diff --git a/pubspec.lock b/pubspec.lock index 58e1a02..3774cb0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,22 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: eb376e9acf6938204f90eb3b1f00b578640d3188b4c8a8ec054f9f479af8d051 + url: "https://pub.dev" + source: hosted + version: "64.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: "69f54f967773f6c26c7dcb13e93d7ccee8b17a641689da39e878d5cf13b06893" + url: "https://pub.dev" + source: hosted + version: "6.2.0" args: dependency: transitive description: @@ -25,6 +41,70 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" + build: + dependency: transitive + description: + name: build + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + build_config: + dependency: transitive + description: + name: build_config + sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 + url: "https://pub.dev" + source: hosted + version: "1.1.1" + build_daemon: + dependency: transitive + description: + name: build_daemon + sha256: "0343061a33da9c5810b2d6cee51945127d8f4c060b7fbdd9d54917f0a3feaaa1" + url: "https://pub.dev" + source: hosted + version: "4.0.1" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + sha256: "64e12b0521812d1684b1917bc80945625391cb9bdd4312536b1d69dcb6133ed8" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + build_runner: + dependency: "direct dev" + description: + name: build_runner + sha256: "10c6bcdbf9d049a0b666702cf1cee4ddfdc38f02a19d35ae392863b47519848b" + url: "https://pub.dev" + source: hosted + version: "2.4.6" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + sha256: c9e32d21dd6626b5c163d48b037ce906bbe428bc23ab77bcd77bb21e593b6185 + url: "https://pub.dev" + source: hosted + version: "7.2.11" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: "723b4021e903217dfc445ec4cf5b42e27975aece1fc4ebbc1ca6329c2d9fb54e" + url: "https://pub.dev" + source: hosted + version: "8.7.0" characters: dependency: transitive description: @@ -33,6 +113,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff + url: "https://pub.dev" + source: hosted + version: "2.0.3" clock: dependency: transitive description: @@ -41,6 +129,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.1" + code_builder: + dependency: transitive + description: + name: code_builder + sha256: b2151ce26a06171005b379ecff6e08d34c470180ffe16b8e14b6d52be292b55f + url: "https://pub.dev" + source: hosted + version: "4.8.0" collection: dependency: transitive description: @@ -49,6 +145,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.18.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + crypto: + dependency: transitive + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "40ae61a5d43feea6d24bd22c0537a6629db858963b99b4bc1c3db80676f32368" + url: "https://pub.dev" + source: hosted + version: "2.3.4" fake_async: dependency: transitive description: @@ -57,6 +177,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.1" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -75,6 +211,102 @@ packages: description: flutter source: sdk version: "0.0.0" + freezed: + dependency: "direct dev" + description: + name: freezed + sha256: "21bf2825311de65501d22e563e3d7605dff57fb5e6da982db785ae5372ff018a" + url: "https://pub.dev" + source: hosted + version: "2.4.5" + freezed_annotation: + dependency: "direct main" + description: + name: freezed_annotation + sha256: c3fd9336eb55a38cc1bbd79ab17573113a8deccd0ecbbf926cca3c62803b5c2d + url: "https://pub.dev" + source: hosted + version: "2.4.1" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + graphs: + dependency: transitive + description: + name: graphs + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 + url: "https://pub.dev" + source: hosted + version: "2.3.1" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: transitive + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + json_annotation: + dependency: "direct main" + description: + name: json_annotation + sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 + url: "https://pub.dev" + source: hosted + version: "4.8.1" + json_serializable: + dependency: "direct dev" + description: + name: json_serializable + sha256: aa1f5a8912615733e0fdc7a02af03308933c93235bdc8d50d0b0c8a8ccb0b969 + url: "https://pub.dev" + source: hosted + version: "6.7.1" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" matcher: dependency: transitive description: @@ -99,6 +331,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" + mime: + dependency: transitive + description: + name: mime + sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + url: "https://pub.dev" + source: hosted + version: "1.0.4" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" path: dependency: transitive description: @@ -123,11 +371,67 @@ packages: url: "https://pub.dev" source: hosted version: "6.0.1" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367 + url: "https://pub.dev" + source: hosted + version: "1.2.3" + shelf: + dependency: transitive + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" + source_gen: + dependency: transitive + description: + name: source_gen + sha256: fc0da689e5302edb6177fdd964efcb7f58912f43c28c2047a808f5bfff643d16 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + source_helper: + dependency: transitive + description: + name: source_helper + sha256: "6adebc0006c37dd63fe05bca0a929b99f06402fc95aa35bf36d67f5c06de01fd" + url: "https://pub.dev" + source: hosted + version: "1.3.4" source_span: dependency: transitive description: @@ -152,6 +456,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.2" + stream_transform: + dependency: transitive + description: + name: stream_transform + sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f" + url: "https://pub.dev" + source: hosted + version: "2.1.0" string_scanner: dependency: transitive description: @@ -176,6 +488,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.1" + timing: + dependency: transitive + description: + name: timing + sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" vector_graphics: dependency: transitive description: @@ -208,6 +536,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" web: dependency: transitive description: @@ -216,6 +552,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.3.0" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b + url: "https://pub.dev" + source: hosted + version: "2.4.0" xml: dependency: transitive description: @@ -224,6 +568,14 @@ packages: url: "https://pub.dev" source: hosted version: "6.4.2" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" yumemi_lints: dependency: "direct dev" description: diff --git a/pubspec.yaml b/pubspec.yaml index a85c256..af91316 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,6 +10,8 @@ dependencies: flutter: sdk: flutter flutter_svg: ^2.0.9 + freezed_annotation: ^2.4.1 + json_annotation: ^4.8.1 yumemi_weather: git: url: https://github.com/yumemi-inc/flutter-training-template.git @@ -18,8 +20,11 @@ dependencies: dev_dependencies: + build_runner: ^2.4.6 flutter_test: sdk: flutter + freezed: ^2.4.5 + json_serializable: ^6.7.1 yumemi_lints: ^1.1.0 flutter: From 3db994ab5d08b8c4394ecc4766ba08a271a6fe1c Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Wed, 22 Nov 2023 19:11:47 +0900 Subject: [PATCH 02/13] =?UTF-8?q?json=5Fserializable=20=E7=94=A8=E3=81=AB?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=83=BB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analysis_options.yaml | 5 +++++ build.yaml | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 build.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml index 75c2a9d..c809da5 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,2 +1,7 @@ # https://pub.dev/packages/yumemi_lints include: package:yumemi_lints/flutter/3.16.0/recommended.yaml + +analyzer: + errors: + # https://pub.dev/packages/freezed#install + invalid_annotation_target: ignore diff --git a/build.yaml b/build.yaml new file mode 100644 index 0000000..e8b8bc0 --- /dev/null +++ b/build.yaml @@ -0,0 +1,9 @@ +targets: + $default: + builders: + # https://github.com/google/json_serializable.dart/tree/master/json_serializable#build-configuration + json_serializable: + options: + field_rename: snake + # json のデシリアライズ時に発生する Exception を CheckedFromJsonException にまとめる + checked: true From 6832014c6c56be52707c0d18b93debab921b8a60 Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Wed, 22 Nov 2023 19:24:17 +0900 Subject: [PATCH 03/13] =?UTF-8?q?forecast.dart,=20weather.dart=20=E3=82=92?= =?UTF-8?q?=20model=20=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF=E3=83=88?= =?UTF-8?q?=E3=83=AA=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/forecast_view.dart | 2 +- lib/main_screen.dart | 2 +- lib/{ => model}/forecast.dart | 2 +- lib/{ => model}/weather.dart | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename lib/{ => model}/forecast.dart (91%) rename lib/{ => model}/weather.dart (100%) diff --git a/lib/forecast_view.dart b/lib/forecast_view.dart index b44d8f5..c0b8d93 100644 --- a/lib/forecast_view.dart +++ b/lib/forecast_view.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; -import 'package:flutter_training/forecast.dart'; +import 'package:flutter_training/model/forecast.dart'; class ForecastView extends StatelessWidget { const ForecastView({ diff --git a/lib/main_screen.dart b/lib/main_screen.dart index 5c28b8b..40a2575 100644 --- a/lib/main_screen.dart +++ b/lib/main_screen.dart @@ -2,8 +2,8 @@ import 'dart:async'; import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:flutter_training/forecast.dart'; import 'package:flutter_training/forecast_view.dart'; +import 'package:flutter_training/model/forecast.dart'; import 'package:flutter_training/yumemi_weather_error.dart'; import 'package:yumemi_weather/yumemi_weather.dart'; diff --git a/lib/forecast.dart b/lib/model/forecast.dart similarity index 91% rename from lib/forecast.dart rename to lib/model/forecast.dart index 8e30d01..f62c3bb 100644 --- a/lib/forecast.dart +++ b/lib/model/forecast.dart @@ -1,6 +1,6 @@ import 'dart:convert'; -import 'package:flutter_training/weather.dart'; +import 'package:flutter_training/model/weather.dart'; class Forecast { const Forecast({ diff --git a/lib/weather.dart b/lib/model/weather.dart similarity index 100% rename from lib/weather.dart rename to lib/model/weather.dart From 9542c0e6c56109850a59d4597697214e72d5cad6 Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Mon, 27 Nov 2023 12:45:39 +0900 Subject: [PATCH 04/13] =?UTF-8?q?Forecast=20=E3=81=AE=E3=82=B7=E3=83=AA?= =?UTF-8?q?=E3=82=A2=E3=83=A9=E3=82=A4=E3=82=BA=E3=82=92=20freezed=20?= =?UTF-8?q?=E3=82=92=E7=94=A8=E3=81=84=E3=81=A6=E8=A8=98=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main_screen.dart | 3 +- lib/model/forecast.dart | 37 +++--- lib/model/forecast.freezed.dart | 200 ++++++++++++++++++++++++++++++++ lib/model/forecast.g.dart | 40 +++++++ 4 files changed, 262 insertions(+), 18 deletions(-) create mode 100644 lib/model/forecast.freezed.dart create mode 100644 lib/model/forecast.g.dart diff --git a/lib/main_screen.dart b/lib/main_screen.dart index 40a2575..f8a7abc 100644 --- a/lib/main_screen.dart +++ b/lib/main_screen.dart @@ -27,7 +27,8 @@ class _MainScreenState extends State { final Forecast newForecast; try { - newForecast = Forecast.from(_yumemiWeather.fetchWeather(requestString)); + final responseString = _yumemiWeather.fetchWeather(requestString); + newForecast = Forecast.fromJsonString(responseString); } on YumemiWeatherError catch (e) { unawaited(_showErrorDialog(e.toMessage())); return; diff --git a/lib/model/forecast.dart b/lib/model/forecast.dart index f62c3bb..5e59ac4 100644 --- a/lib/model/forecast.dart +++ b/lib/model/forecast.dart @@ -1,25 +1,28 @@ import 'dart:convert'; import 'package:flutter_training/model/weather.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; -class Forecast { - const Forecast({ - required this.weather, - required this.maxTemperature, - required this.minTemperature, - }); +part 'forecast.freezed.dart'; +part 'forecast.g.dart'; - factory Forecast.from(String jsonString) { - final decoded = jsonDecode(jsonString) as Map; +@freezed +class Forecast with _$Forecast { + const factory Forecast({ + @JsonKey(name: 'weather_condition') required Weather weather, + required int maxTemperature, + required int minTemperature, + }) = _Forecast; - return Forecast( - weather: Weather.from(decoded['weather_condition'] as String), - minTemperature: decoded['min_temperature'] as int, - maxTemperature: decoded['max_temperature'] as int, - ); - } + factory Forecast.fromJson(Map json) => + _$ForecastFromJson(json); + + factory Forecast.fromJsonString(String json) { + final decoded = jsonDecode(json) as Map?; + if (decoded == null) { + throw Exception('Invalid format: $json.'); + } - final Weather weather; - final int maxTemperature; - final int minTemperature; + return Forecast.fromJson(decoded); + } } diff --git a/lib/model/forecast.freezed.dart b/lib/model/forecast.freezed.dart new file mode 100644 index 0000000..05c1189 --- /dev/null +++ b/lib/model/forecast.freezed.dart @@ -0,0 +1,200 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'forecast.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +Forecast _$ForecastFromJson(Map json) { + return _Forecast.fromJson(json); +} + +/// @nodoc +mixin _$Forecast { + @JsonKey(name: 'weather_condition') + Weather get weather => throw _privateConstructorUsedError; + int get maxTemperature => throw _privateConstructorUsedError; + int get minTemperature => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ForecastCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ForecastCopyWith<$Res> { + factory $ForecastCopyWith(Forecast value, $Res Function(Forecast) then) = + _$ForecastCopyWithImpl<$Res, Forecast>; + @useResult + $Res call( + {@JsonKey(name: 'weather_condition') Weather weather, + int maxTemperature, + int minTemperature}); +} + +/// @nodoc +class _$ForecastCopyWithImpl<$Res, $Val extends Forecast> + implements $ForecastCopyWith<$Res> { + _$ForecastCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? weather = null, + Object? maxTemperature = null, + Object? minTemperature = null, + }) { + return _then(_value.copyWith( + weather: null == weather + ? _value.weather + : weather // ignore: cast_nullable_to_non_nullable + as Weather, + maxTemperature: null == maxTemperature + ? _value.maxTemperature + : maxTemperature // ignore: cast_nullable_to_non_nullable + as int, + minTemperature: null == minTemperature + ? _value.minTemperature + : minTemperature // ignore: cast_nullable_to_non_nullable + as int, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$ForecastImplCopyWith<$Res> + implements $ForecastCopyWith<$Res> { + factory _$$ForecastImplCopyWith( + _$ForecastImpl value, $Res Function(_$ForecastImpl) then) = + __$$ForecastImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'weather_condition') Weather weather, + int maxTemperature, + int minTemperature}); +} + +/// @nodoc +class __$$ForecastImplCopyWithImpl<$Res> + extends _$ForecastCopyWithImpl<$Res, _$ForecastImpl> + implements _$$ForecastImplCopyWith<$Res> { + __$$ForecastImplCopyWithImpl( + _$ForecastImpl _value, $Res Function(_$ForecastImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? weather = null, + Object? maxTemperature = null, + Object? minTemperature = null, + }) { + return _then(_$ForecastImpl( + weather: null == weather + ? _value.weather + : weather // ignore: cast_nullable_to_non_nullable + as Weather, + maxTemperature: null == maxTemperature + ? _value.maxTemperature + : maxTemperature // ignore: cast_nullable_to_non_nullable + as int, + minTemperature: null == minTemperature + ? _value.minTemperature + : minTemperature // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$ForecastImpl implements _Forecast { + const _$ForecastImpl( + {@JsonKey(name: 'weather_condition') required this.weather, + required this.maxTemperature, + required this.minTemperature}); + + factory _$ForecastImpl.fromJson(Map json) => + _$$ForecastImplFromJson(json); + + @override + @JsonKey(name: 'weather_condition') + final Weather weather; + @override + final int maxTemperature; + @override + final int minTemperature; + + @override + String toString() { + return 'Forecast(weather: $weather, maxTemperature: $maxTemperature, minTemperature: $minTemperature)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ForecastImpl && + (identical(other.weather, weather) || other.weather == weather) && + (identical(other.maxTemperature, maxTemperature) || + other.maxTemperature == maxTemperature) && + (identical(other.minTemperature, minTemperature) || + other.minTemperature == minTemperature)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => + Object.hash(runtimeType, weather, maxTemperature, minTemperature); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$ForecastImplCopyWith<_$ForecastImpl> get copyWith => + __$$ForecastImplCopyWithImpl<_$ForecastImpl>(this, _$identity); + + @override + Map toJson() { + return _$$ForecastImplToJson( + this, + ); + } +} + +abstract class _Forecast implements Forecast { + const factory _Forecast( + {@JsonKey(name: 'weather_condition') required final Weather weather, + required final int maxTemperature, + required final int minTemperature}) = _$ForecastImpl; + + factory _Forecast.fromJson(Map json) = + _$ForecastImpl.fromJson; + + @override + @JsonKey(name: 'weather_condition') + Weather get weather; + @override + int get maxTemperature; + @override + int get minTemperature; + @override + @JsonKey(ignore: true) + _$$ForecastImplCopyWith<_$ForecastImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/model/forecast.g.dart b/lib/model/forecast.g.dart new file mode 100644 index 0000000..0b324e4 --- /dev/null +++ b/lib/model/forecast.g.dart @@ -0,0 +1,40 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'forecast.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$ForecastImpl _$$ForecastImplFromJson(Map json) => + $checkedCreate( + r'_$ForecastImpl', + json, + ($checkedConvert) { + final val = _$ForecastImpl( + weather: $checkedConvert( + 'weather_condition', (v) => $enumDecode(_$WeatherEnumMap, v)), + maxTemperature: $checkedConvert('max_temperature', (v) => v as int), + minTemperature: $checkedConvert('min_temperature', (v) => v as int), + ); + return val; + }, + fieldKeyMap: const { + 'weather': 'weather_condition', + 'maxTemperature': 'max_temperature', + 'minTemperature': 'min_temperature' + }, + ); + +Map _$$ForecastImplToJson(_$ForecastImpl instance) => + { + 'weather_condition': _$WeatherEnumMap[instance.weather]!, + 'max_temperature': instance.maxTemperature, + 'min_temperature': instance.minTemperature, + }; + +const _$WeatherEnumMap = { + Weather.sunny: 'sunny', + Weather.cloudy: 'cloudy', + Weather.rainy: 'rainy', +}; From fac8296e33ba6c282b86189a0f7446ec6f315d0d Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Mon, 27 Nov 2023 16:52:58 +0900 Subject: [PATCH 05/13] =?UTF-8?q?intl=20=E3=81=AE=E4=BE=9D=E5=AD=98?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pubspec.lock | 8 ++++++++ pubspec.yaml | 1 + 2 files changed, 9 insertions(+) diff --git a/pubspec.lock b/pubspec.lock index 3774cb0..7e11a63 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -267,6 +267,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + intl: + dependency: "direct main" + description: + name: intl + sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" + url: "https://pub.dev" + source: hosted + version: "0.18.1" io: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index af91316..634c945 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: sdk: flutter flutter_svg: ^2.0.9 freezed_annotation: ^2.4.1 + intl: ^0.18.1 json_annotation: ^4.8.1 yumemi_weather: git: From 45fba59860cbc9683145355a22373a2d64f1e6f3 Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Mon, 27 Nov 2023 17:04:16 +0900 Subject: [PATCH 06/13] =?UTF-8?q?yumemi=5Fweather=20=E3=81=A7=E7=94=A8?= =?UTF-8?q?=E3=81=84=E3=82=89=E3=82=8C=E3=82=8B=E6=97=A5=E6=99=82=E5=BD=A2?= =?UTF-8?q?=E5=BC=8F=E3=81=AB=20DateTime=20=E3=82=92=E5=A4=89=E6=8F=9B?= =?UTF-8?q?=E3=81=99=E3=82=8B=20DateTimeConverter=20=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/date_time_converter.dart | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/date_time_converter.dart diff --git a/lib/date_time_converter.dart b/lib/date_time_converter.dart new file mode 100644 index 0000000..1c483c1 --- /dev/null +++ b/lib/date_time_converter.dart @@ -0,0 +1,53 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:intl/intl.dart'; + +/// yumemi_weather で用いられる日時形式に変換する JsonConverter +/// +/// 形式例 +/// - 2020-04-01T12:00:00+09:00 +/// 参照 +/// - https://yumemi-inc.github.io/flutter-training-template/file-___home_runner_work_flutter-training-template_flutter-training-template_packages_yumemi_weather_lib_src_yumemi_weather_base/YumemiWeather/fetchWeather.html +class DateTimeConverter implements JsonConverter { + const DateTimeConverter(); + + // DateTime#toIso8601String() はマイクロ秒まで出力されるため用いない + // タイムゾーンは intl では未実装のため自前で追加する + // see: https://api.flutter.dev/flutter/intl/DateFormat-class.html + static final DateFormat dateFormatter = DateFormat("yyyy-MM-dd'T'HH:mm:ss"); + + static final NumberFormat timeFormatter = NumberFormat('00'); + + @override + DateTime fromJson(String json) { + // DateFormat#parse() では UTC とローカルのタイムゾーン以外対応できない + // DateTime.parse() はタイムゾーンを考慮した上で UTC に変更する + return DateTime.parse(json).toLocal(); + } + + @override + String toJson(DateTime object) { + final dateTimeStr = dateFormatter.format(object); + final timeZoneStr = _toTimeZoneString(object.timeZoneOffset); + return '$dateTimeStr$timeZoneStr'; + } + + String _toTimeZoneString(Duration offset) { + final inMinutes = offset.inMinutes.abs(); + + if (inMinutes == 0) { + return 'Z'; + } + + final String sign; + if (offset.isNegative) { + sign = '-'; + } else { + sign = '+'; + } + + final hours = timeFormatter.format(inMinutes ~/ Duration.minutesPerHour); + final minutes = timeFormatter.format(inMinutes % Duration.minutesPerHour); + + return '$sign$hours:$minutes'; + } +} From 161152aa22c9dcfe1171a51bb2be0b6bbc068178 Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Mon, 27 Nov 2023 17:05:19 +0900 Subject: [PATCH 07/13] =?UTF-8?q?fetchWeather=20api=20=E3=81=AE=E3=83=AA?= =?UTF-8?q?=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E7=94=A8=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/model/fetch_weather_request.dart | 16 ++ lib/model/fetch_weather_request.freezed.dart | 175 +++++++++++++++++++ lib/model/fetch_weather_request.g.dart | 29 +++ 3 files changed, 220 insertions(+) create mode 100644 lib/model/fetch_weather_request.dart create mode 100644 lib/model/fetch_weather_request.freezed.dart create mode 100644 lib/model/fetch_weather_request.g.dart diff --git a/lib/model/fetch_weather_request.dart b/lib/model/fetch_weather_request.dart new file mode 100644 index 0000000..fdcff10 --- /dev/null +++ b/lib/model/fetch_weather_request.dart @@ -0,0 +1,16 @@ +import 'package:flutter_training/date_time_converter.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'fetch_weather_request.freezed.dart'; +part 'fetch_weather_request.g.dart'; + +@freezed +class FetchWeatherRequest with _$FetchWeatherRequest { + const factory FetchWeatherRequest({ + required String area, + @DateTimeConverter() required DateTime date, + }) = _FetchWeatherRequest; + + factory FetchWeatherRequest.fromJson(Map json) => + _$FetchWeatherRequestFromJson(json); +} diff --git a/lib/model/fetch_weather_request.freezed.dart b/lib/model/fetch_weather_request.freezed.dart new file mode 100644 index 0000000..9891f3c --- /dev/null +++ b/lib/model/fetch_weather_request.freezed.dart @@ -0,0 +1,175 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'fetch_weather_request.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +FetchWeatherRequest _$FetchWeatherRequestFromJson(Map json) { + return _FetchWeatherRequest.fromJson(json); +} + +/// @nodoc +mixin _$FetchWeatherRequest { + String get area => throw _privateConstructorUsedError; + @DateTimeConverter() + DateTime get date => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $FetchWeatherRequestCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $FetchWeatherRequestCopyWith<$Res> { + factory $FetchWeatherRequestCopyWith( + FetchWeatherRequest value, $Res Function(FetchWeatherRequest) then) = + _$FetchWeatherRequestCopyWithImpl<$Res, FetchWeatherRequest>; + @useResult + $Res call({String area, @DateTimeConverter() DateTime date}); +} + +/// @nodoc +class _$FetchWeatherRequestCopyWithImpl<$Res, $Val extends FetchWeatherRequest> + implements $FetchWeatherRequestCopyWith<$Res> { + _$FetchWeatherRequestCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? area = null, + Object? date = null, + }) { + return _then(_value.copyWith( + area: null == area + ? _value.area + : area // ignore: cast_nullable_to_non_nullable + as String, + date: null == date + ? _value.date + : date // ignore: cast_nullable_to_non_nullable + as DateTime, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$FetchWeatherRequestImplCopyWith<$Res> + implements $FetchWeatherRequestCopyWith<$Res> { + factory _$$FetchWeatherRequestImplCopyWith(_$FetchWeatherRequestImpl value, + $Res Function(_$FetchWeatherRequestImpl) then) = + __$$FetchWeatherRequestImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String area, @DateTimeConverter() DateTime date}); +} + +/// @nodoc +class __$$FetchWeatherRequestImplCopyWithImpl<$Res> + extends _$FetchWeatherRequestCopyWithImpl<$Res, _$FetchWeatherRequestImpl> + implements _$$FetchWeatherRequestImplCopyWith<$Res> { + __$$FetchWeatherRequestImplCopyWithImpl(_$FetchWeatherRequestImpl _value, + $Res Function(_$FetchWeatherRequestImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? area = null, + Object? date = null, + }) { + return _then(_$FetchWeatherRequestImpl( + area: null == area + ? _value.area + : area // ignore: cast_nullable_to_non_nullable + as String, + date: null == date + ? _value.date + : date // ignore: cast_nullable_to_non_nullable + as DateTime, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$FetchWeatherRequestImpl implements _FetchWeatherRequest { + const _$FetchWeatherRequestImpl( + {required this.area, @DateTimeConverter() required this.date}); + + factory _$FetchWeatherRequestImpl.fromJson(Map json) => + _$$FetchWeatherRequestImplFromJson(json); + + @override + final String area; + @override + @DateTimeConverter() + final DateTime date; + + @override + String toString() { + return 'FetchWeatherRequest(area: $area, date: $date)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$FetchWeatherRequestImpl && + (identical(other.area, area) || other.area == area) && + (identical(other.date, date) || other.date == date)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, area, date); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$FetchWeatherRequestImplCopyWith<_$FetchWeatherRequestImpl> get copyWith => + __$$FetchWeatherRequestImplCopyWithImpl<_$FetchWeatherRequestImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$FetchWeatherRequestImplToJson( + this, + ); + } +} + +abstract class _FetchWeatherRequest implements FetchWeatherRequest { + const factory _FetchWeatherRequest( + {required final String area, + @DateTimeConverter() required final DateTime date}) = + _$FetchWeatherRequestImpl; + + factory _FetchWeatherRequest.fromJson(Map json) = + _$FetchWeatherRequestImpl.fromJson; + + @override + String get area; + @override + @DateTimeConverter() + DateTime get date; + @override + @JsonKey(ignore: true) + _$$FetchWeatherRequestImplCopyWith<_$FetchWeatherRequestImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/model/fetch_weather_request.g.dart b/lib/model/fetch_weather_request.g.dart new file mode 100644 index 0000000..4f3752a --- /dev/null +++ b/lib/model/fetch_weather_request.g.dart @@ -0,0 +1,29 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'fetch_weather_request.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$FetchWeatherRequestImpl _$$FetchWeatherRequestImplFromJson( + Map json) => + $checkedCreate( + r'_$FetchWeatherRequestImpl', + json, + ($checkedConvert) { + final val = _$FetchWeatherRequestImpl( + area: $checkedConvert('area', (v) => v as String), + date: $checkedConvert( + 'date', (v) => const DateTimeConverter().fromJson(v as String)), + ); + return val; + }, + ); + +Map _$$FetchWeatherRequestImplToJson( + _$FetchWeatherRequestImpl instance) => + { + 'area': instance.area, + 'date': const DateTimeConverter().toJson(instance.date), + }; From 85363e4f15cc3078afd138bb055a20d941274702 Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Mon, 27 Nov 2023 17:32:38 +0900 Subject: [PATCH 08/13] =?UTF-8?q?MainScreen=20=E3=81=A7=E3=81=AE=E3=83=AA?= =?UTF-8?q?=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E3=81=AE=E5=AE=9A=E7=BE=A9?= =?UTF-8?q?=E3=81=A7=E3=80=81=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88?= =?UTF-8?q?=E7=94=A8=E3=82=AF=E3=83=A9=E3=82=B9=E3=82=92=E4=BD=BF=E3=81=86?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main_screen.dart | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/main_screen.dart b/lib/main_screen.dart index f8a7abc..5dd6765 100644 --- a/lib/main_screen.dart +++ b/lib/main_screen.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_training/forecast_view.dart'; +import 'package:flutter_training/model/fetch_weather_request.dart'; import 'package:flutter_training/model/forecast.dart'; import 'package:flutter_training/yumemi_weather_error.dart'; import 'package:yumemi_weather/yumemi_weather.dart'; @@ -19,11 +20,11 @@ class _MainScreenState extends State { Forecast? _forecast; void _fetchForecast() { - const request = { - 'area': 'tokyo', - 'date': '2023-11-22T00:00:00+09:00', - }; - final requestString = jsonEncode(request); + final request = FetchWeatherRequest( + area: 'tokyo', + date: DateTime.now(), + ); + final requestString = jsonEncode(request.toJson()); final Forecast newForecast; try { From e28d81e54993709111bccbee21af6ee36f9a44e8 Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Mon, 27 Nov 2023 17:49:17 +0900 Subject: [PATCH 09/13] =?UTF-8?q?=E8=87=AA=E5=8B=95=E7=94=9F=E6=88=90?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E6=A4=9C=E8=A8=BC?= =?UTF-8?q?=E5=AF=BE=E8=B1=A1=E3=81=8B=E3=82=89=E9=99=A4=E5=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analysis_options.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/analysis_options.yaml b/analysis_options.yaml index c809da5..c5a176b 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -2,6 +2,9 @@ include: package:yumemi_lints/flutter/3.16.0/recommended.yaml analyzer: + exclude: + - "**/*.g.dart" + - "**/*.freezed.dart" errors: # https://pub.dev/packages/freezed#install invalid_annotation_target: ignore From 11013e36c3a5f96b8e91c648b1a6bdba16c89873 Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Mon, 27 Nov 2023 18:37:23 +0900 Subject: [PATCH 10/13] =?UTF-8?q?json=20=E3=81=AE=20Map=20=E3=82=92=20Stri?= =?UTF-8?q?ng=20=E3=81=AB=E5=A4=89=E6=8F=9B=E3=81=99=E3=82=8B=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=20FetchWeatherRequest=20=E3=81=AB=E7=A7=BB?= =?UTF-8?q?=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main_screen.dart | 6 ++---- lib/model/fetch_weather_request.dart | 7 +++++++ lib/model/fetch_weather_request.freezed.dart | 8 +++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/main_screen.dart b/lib/main_screen.dart index 5dd6765..c31953a 100644 --- a/lib/main_screen.dart +++ b/lib/main_screen.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_training/forecast_view.dart'; @@ -20,11 +19,10 @@ class _MainScreenState extends State { Forecast? _forecast; void _fetchForecast() { - final request = FetchWeatherRequest( + final requestString = FetchWeatherRequest( area: 'tokyo', date: DateTime.now(), - ); - final requestString = jsonEncode(request.toJson()); + ).toJsonString(); final Forecast newForecast; try { diff --git a/lib/model/fetch_weather_request.dart b/lib/model/fetch_weather_request.dart index fdcff10..ef2d860 100644 --- a/lib/model/fetch_weather_request.dart +++ b/lib/model/fetch_weather_request.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:flutter_training/date_time_converter.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -11,6 +13,11 @@ class FetchWeatherRequest with _$FetchWeatherRequest { @DateTimeConverter() required DateTime date, }) = _FetchWeatherRequest; + // https://pub.dev/packages/freezed#adding-getters-and-methods-to-our-models + const FetchWeatherRequest._(); + factory FetchWeatherRequest.fromJson(Map json) => _$FetchWeatherRequestFromJson(json); + + String toJsonString() => jsonEncode(toJson()); } diff --git a/lib/model/fetch_weather_request.freezed.dart b/lib/model/fetch_weather_request.freezed.dart index 9891f3c..8a89320 100644 --- a/lib/model/fetch_weather_request.freezed.dart +++ b/lib/model/fetch_weather_request.freezed.dart @@ -108,9 +108,10 @@ class __$$FetchWeatherRequestImplCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$FetchWeatherRequestImpl implements _FetchWeatherRequest { +class _$FetchWeatherRequestImpl extends _FetchWeatherRequest { const _$FetchWeatherRequestImpl( - {required this.area, @DateTimeConverter() required this.date}); + {required this.area, @DateTimeConverter() required this.date}) + : super._(); factory _$FetchWeatherRequestImpl.fromJson(Map json) => _$$FetchWeatherRequestImplFromJson(json); @@ -154,11 +155,12 @@ class _$FetchWeatherRequestImpl implements _FetchWeatherRequest { } } -abstract class _FetchWeatherRequest implements FetchWeatherRequest { +abstract class _FetchWeatherRequest extends FetchWeatherRequest { const factory _FetchWeatherRequest( {required final String area, @DateTimeConverter() required final DateTime date}) = _$FetchWeatherRequestImpl; + const _FetchWeatherRequest._() : super._(); factory _FetchWeatherRequest.fromJson(Map json) = _$FetchWeatherRequestImpl.fromJson; From 901cf3dbd3c10f4f768927553593194d80f44e09 Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Tue, 28 Nov 2023 12:08:12 +0900 Subject: [PATCH 11/13] =?UTF-8?q?if=20=E6=96=87=E3=81=A7=E3=81=AE=E4=BB=A3?= =?UTF-8?q?=E5=85=A5=E3=82=92=E4=B8=89=E9=A0=85=E6=BC=94=E7=AE=97=E5=AD=90?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/date_time_converter.dart | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/date_time_converter.dart b/lib/date_time_converter.dart index 1c483c1..43a37c3 100644 --- a/lib/date_time_converter.dart +++ b/lib/date_time_converter.dart @@ -38,12 +38,7 @@ class DateTimeConverter implements JsonConverter { return 'Z'; } - final String sign; - if (offset.isNegative) { - sign = '-'; - } else { - sign = '+'; - } + final sign = offset.isNegative ? '-' : '+'; final hours = timeFormatter.format(inMinutes ~/ Duration.minutesPerHour); final minutes = timeFormatter.format(inMinutes % Duration.minutesPerHour); From 2b02177a8b79e6f66e078327cb790ff65fc00af4 Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Tue, 28 Nov 2023 12:18:50 +0900 Subject: [PATCH 12/13] =?UTF-8?q?=E8=87=AA=E5=8B=95=E7=94=9F=E6=88=90?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=8C=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=AF=BE=E8=B1=A1=E3=81=AB=E3=81=AA=E3=82=89=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit コンパイルエラーなども警告されなくなってしまうため --- analysis_options.yaml | 3 --- build.yaml | 5 +++++ lib/model/fetch_weather_request.g.dart | 2 ++ lib/model/forecast.g.dart | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index c5a176b..c809da5 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -2,9 +2,6 @@ include: package:yumemi_lints/flutter/3.16.0/recommended.yaml analyzer: - exclude: - - "**/*.g.dart" - - "**/*.freezed.dart" errors: # https://pub.dev/packages/freezed#install invalid_annotation_target: ignore diff --git a/build.yaml b/build.yaml index e8b8bc0..0ddbd6e 100644 --- a/build.yaml +++ b/build.yaml @@ -7,3 +7,8 @@ targets: field_rename: snake # json のデシリアライズ時に発生する Exception を CheckedFromJsonException にまとめる checked: true + # https://github.com/dart-lang/source_gen#ignore_for_file + source_gen:combining_builder: + options: + ignore_for_file: + - type=lint diff --git a/lib/model/fetch_weather_request.g.dart b/lib/model/fetch_weather_request.g.dart index 4f3752a..6cbfd37 100644 --- a/lib/model/fetch_weather_request.g.dart +++ b/lib/model/fetch_weather_request.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint + part of 'fetch_weather_request.dart'; // ************************************************************************** diff --git a/lib/model/forecast.g.dart b/lib/model/forecast.g.dart index 0b324e4..1fb1da9 100644 --- a/lib/model/forecast.g.dart +++ b/lib/model/forecast.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint + part of 'forecast.dart'; // ************************************************************************** From 40346cd223c389210bb873ed46fb8e069004366e Mon Sep 17 00:00:00 2001 From: Go Shibata Date: Tue, 28 Nov 2023 12:26:22 +0900 Subject: [PATCH 13/13] =?UTF-8?q?=E8=87=AA=E5=8B=95=E7=94=9F=E6=88=90?= =?UTF-8?q?=E3=81=AE=E5=AF=BE=E8=B1=A1=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=82=92=E5=88=B6=E9=99=90=E3=81=97=E3=81=A6=E9=AB=98=E9=80=9F?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.yaml b/build.yaml index 0ddbd6e..6e41797 100644 --- a/build.yaml +++ b/build.yaml @@ -1,8 +1,16 @@ targets: $default: builders: + freezed: + # https://github.com/dart-lang/build/blob/master/docs/faq.md#how-do-i-avoid-running-builders-on-unnecessary-inputs + generate_for: + include: + - lib/model/*.dart # https://github.com/google/json_serializable.dart/tree/master/json_serializable#build-configuration json_serializable: + generate_for: + include: + - lib/model/*.dart options: field_rename: snake # json のデシリアライズ時に発生する Exception を CheckedFromJsonException にまとめる