Compare commits

...

2 Commits

Author SHA1 Message Date
Rongjian Zhang c30895ab1e style: dart fix apply 2022-10-30 14:52:36 +08:00
Rongjian Zhang 504ee9c863 refactor: use freezed 2022-10-30 14:41:12 +08:00
9 changed files with 349 additions and 64 deletions

View File

@ -32,14 +32,19 @@ linter:
prefer_final_locals: true
use_super_parameters: true
use_key_in_widget_constructors: false # waiting for auto fix: https://github.com/dart-lang/sdk/issues/50056
avoid_print: false # TODO:
# TODO:
avoid_print: false
use_build_context_synchronously: false
non_constant_identifier_names: false
analyzer:
errors:
todo: ignore
fixme: ignore
exclude:
- "**/*.gql.dart"
- "**/*.g.dart"
invalid_annotation_target: ignore # https://github.com/rrousselGit/freezed#disabling-invalid_annotation_target-warning-and-warning-in-generates-files
# TODO:
unused_element: false
override_on_non_overriding_member: false
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

View File

@ -1,44 +1,22 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'account.freezed.dart';
part 'account.g.dart';
@JsonSerializable(includeIfNull: false)
class Account {
// For Bitbucket
// equals(Account a) {
// final uri = Uri.parse(domain);
// final uriA = Uri.parse(a.domain);
// // Treat domains as the same if they have the same hosts and ports
// return a.platform == platform &&
// a.login == login &&
// a.gitlabId == gitlabId &&
// uri.host == uriA.host &&
// uri.port == uriA.port;
// }
Account({
required this.platform,
required this.domain,
required this.token,
required this.login,
required this.avatarUrl,
this.gitlabId,
this.appPassword,
this.accountId,
});
@freezed
class Account with _$Account {
@JsonSerializable(includeIfNull: false)
factory Account({
required String platform,
required String domain,
required String token,
required String login,
required String avatarUrl,
int? gitlabId, // For GitLab
String? appPassword, // For Bitbucket
String? accountId, // For Bitbucket
}) = _Account;
factory Account.fromJson(Map<String, dynamic> json) =>
_$AccountFromJson(json);
String platform;
String domain;
String token;
String login;
String avatarUrl;
int? gitlabId; // For GitLab
String? appPassword; // For Bitbucket
String? accountId;
Map<String, dynamic> toJson() => _$AccountToJson(this);
}

View File

@ -0,0 +1,300 @@
// 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
part of 'account.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(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');
Account _$AccountFromJson(Map<String, dynamic> json) {
return _Account.fromJson(json);
}
/// @nodoc
mixin _$Account {
String get platform => throw _privateConstructorUsedError;
String get domain => throw _privateConstructorUsedError;
String get token => throw _privateConstructorUsedError;
String get login => throw _privateConstructorUsedError;
String get avatarUrl => throw _privateConstructorUsedError;
int? get gitlabId => throw _privateConstructorUsedError; // For GitLab
String? get appPassword =>
throw _privateConstructorUsedError; // For Bitbucket
String? get accountId => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$AccountCopyWith<Account> get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $AccountCopyWith<$Res> {
factory $AccountCopyWith(Account value, $Res Function(Account) then) =
_$AccountCopyWithImpl<$Res, Account>;
@useResult
$Res call(
{String platform,
String domain,
String token,
String login,
String avatarUrl,
int? gitlabId,
String? appPassword,
String? accountId});
}
/// @nodoc
class _$AccountCopyWithImpl<$Res, $Val extends Account>
implements $AccountCopyWith<$Res> {
_$AccountCopyWithImpl(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? platform = null,
Object? domain = null,
Object? token = null,
Object? login = null,
Object? avatarUrl = null,
Object? gitlabId = freezed,
Object? appPassword = freezed,
Object? accountId = freezed,
}) {
return _then(_value.copyWith(
platform: null == platform
? _value.platform
: platform // ignore: cast_nullable_to_non_nullable
as String,
domain: null == domain
? _value.domain
: domain // ignore: cast_nullable_to_non_nullable
as String,
token: null == token
? _value.token
: token // ignore: cast_nullable_to_non_nullable
as String,
login: null == login
? _value.login
: login // ignore: cast_nullable_to_non_nullable
as String,
avatarUrl: null == avatarUrl
? _value.avatarUrl
: avatarUrl // ignore: cast_nullable_to_non_nullable
as String,
gitlabId: freezed == gitlabId
? _value.gitlabId
: gitlabId // ignore: cast_nullable_to_non_nullable
as int?,
appPassword: freezed == appPassword
? _value.appPassword
: appPassword // ignore: cast_nullable_to_non_nullable
as String?,
accountId: freezed == accountId
? _value.accountId
: accountId // ignore: cast_nullable_to_non_nullable
as String?,
) as $Val);
}
}
/// @nodoc
abstract class _$$_AccountCopyWith<$Res> implements $AccountCopyWith<$Res> {
factory _$$_AccountCopyWith(
_$_Account value, $Res Function(_$_Account) then) =
__$$_AccountCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{String platform,
String domain,
String token,
String login,
String avatarUrl,
int? gitlabId,
String? appPassword,
String? accountId});
}
/// @nodoc
class __$$_AccountCopyWithImpl<$Res>
extends _$AccountCopyWithImpl<$Res, _$_Account>
implements _$$_AccountCopyWith<$Res> {
__$$_AccountCopyWithImpl(_$_Account _value, $Res Function(_$_Account) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? platform = null,
Object? domain = null,
Object? token = null,
Object? login = null,
Object? avatarUrl = null,
Object? gitlabId = freezed,
Object? appPassword = freezed,
Object? accountId = freezed,
}) {
return _then(_$_Account(
platform: null == platform
? _value.platform
: platform // ignore: cast_nullable_to_non_nullable
as String,
domain: null == domain
? _value.domain
: domain // ignore: cast_nullable_to_non_nullable
as String,
token: null == token
? _value.token
: token // ignore: cast_nullable_to_non_nullable
as String,
login: null == login
? _value.login
: login // ignore: cast_nullable_to_non_nullable
as String,
avatarUrl: null == avatarUrl
? _value.avatarUrl
: avatarUrl // ignore: cast_nullable_to_non_nullable
as String,
gitlabId: freezed == gitlabId
? _value.gitlabId
: gitlabId // ignore: cast_nullable_to_non_nullable
as int?,
appPassword: freezed == appPassword
? _value.appPassword
: appPassword // ignore: cast_nullable_to_non_nullable
as String?,
accountId: freezed == accountId
? _value.accountId
: accountId // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
@JsonSerializable(includeIfNull: false)
class _$_Account implements _Account {
_$_Account(
{required this.platform,
required this.domain,
required this.token,
required this.login,
required this.avatarUrl,
this.gitlabId,
this.appPassword,
this.accountId});
factory _$_Account.fromJson(Map<String, dynamic> json) =>
_$$_AccountFromJson(json);
@override
final String platform;
@override
final String domain;
@override
final String token;
@override
final String login;
@override
final String avatarUrl;
@override
final int? gitlabId;
// For GitLab
@override
final String? appPassword;
// For Bitbucket
@override
final String? accountId;
@override
String toString() {
return 'Account(platform: $platform, domain: $domain, token: $token, login: $login, avatarUrl: $avatarUrl, gitlabId: $gitlabId, appPassword: $appPassword, accountId: $accountId)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_Account &&
(identical(other.platform, platform) ||
other.platform == platform) &&
(identical(other.domain, domain) || other.domain == domain) &&
(identical(other.token, token) || other.token == token) &&
(identical(other.login, login) || other.login == login) &&
(identical(other.avatarUrl, avatarUrl) ||
other.avatarUrl == avatarUrl) &&
(identical(other.gitlabId, gitlabId) ||
other.gitlabId == gitlabId) &&
(identical(other.appPassword, appPassword) ||
other.appPassword == appPassword) &&
(identical(other.accountId, accountId) ||
other.accountId == accountId));
}
@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, platform, domain, token, login,
avatarUrl, gitlabId, appPassword, accountId);
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_AccountCopyWith<_$_Account> get copyWith =>
__$$_AccountCopyWithImpl<_$_Account>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$_AccountToJson(
this,
);
}
}
abstract class _Account implements Account {
factory _Account(
{required final String platform,
required final String domain,
required final String token,
required final String login,
required final String avatarUrl,
final int? gitlabId,
final String? appPassword,
final String? accountId}) = _$_Account;
factory _Account.fromJson(Map<String, dynamic> json) = _$_Account.fromJson;
@override
String get platform;
@override
String get domain;
@override
String get token;
@override
String get login;
@override
String get avatarUrl;
@override
int? get gitlabId;
@override // For GitLab
String? get appPassword;
@override // For Bitbucket
String? get accountId;
@override
@JsonKey(ignore: true)
_$$_AccountCopyWith<_$_Account> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@ -6,7 +6,7 @@ part of 'account.dart';
// JsonSerializableGenerator
// **************************************************************************
Account _$AccountFromJson(Map<String, dynamic> json) => Account(
_$_Account _$$_AccountFromJson(Map<String, dynamic> json) => _$_Account(
platform: json['platform'] as String,
domain: json['domain'] as String,
token: json['token'] as String,
@ -17,7 +17,7 @@ Account _$AccountFromJson(Map<String, dynamic> json) => Account(
accountId: json['accountId'] as String?,
);
Map<String, dynamic> _$AccountToJson(Account instance) {
Map<String, dynamic> _$$_AccountToJson(_$_Account instance) {
final val = <String, dynamic>{
'platform': instance.platform,
'domain': instance.domain,

View File

@ -1,14 +0,0 @@
# # Defines a default set of lint rules enforced for
# # projects at Google. For details and rationale,
# # see https://github.com/dart-lang/pedantic#enabled-lints.
# include: package:pedantic/analysis_options.yaml
# # For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# # Uncomment to specify additional rules.
# # linter:
# # rules:
# # - camel_case_types
# analyzer:
# # exclude:
# # - path/to/excluded/files/**

View File

@ -4,15 +4,15 @@ void main() async {
final trending = GithubTrending();
// get trending repositories
var repos = await trending.getTrendingRepositories();
final repos = await trending.getTrendingRepositories();
print(repos[0].name);
// specify time period
var weeklyRepos = await trending.getTrendingRepositories(since: 'weekly');
final weeklyRepos = await trending.getTrendingRepositories(since: 'weekly');
print(weeklyRepos[0].name);
// specify language
var dartRepos = await trending.getTrendingRepositories(language: 'dart');
final dartRepos = await trending.getTrendingRepositories(language: 'dart');
print(dartRepos[0].language); // Dart
print(dartRepos[0].languageColor); // #00B4AB
}

View File

@ -4,9 +4,9 @@ part 'model.g.dart';
@JsonSerializable()
class GithubTrendingRepository {
GithubTrendingRepository();
factory GithubTrendingRepository.fromJson(Map<String, dynamic> json) =>
_$GithubTrendingRepositoryFromJson(json);
GithubTrendingRepository();
String? author;
String? name;
String? avatar;
@ -22,9 +22,9 @@ class GithubTrendingRepository {
@JsonSerializable()
class GithubTrendingRepositoryBuiltBy {
GithubTrendingRepositoryBuiltBy();
factory GithubTrendingRepositoryBuiltBy.fromJson(Map<String, dynamic> json) =>
_$GithubTrendingRepositoryBuiltByFromJson(json);
GithubTrendingRepositoryBuiltBy();
String? href;
String? avatar;
String? username;
@ -32,9 +32,9 @@ class GithubTrendingRepositoryBuiltBy {
@JsonSerializable()
class GithubTrendingDeveloper {
GithubTrendingDeveloper();
factory GithubTrendingDeveloper.fromJson(Map<String, dynamic> json) =>
_$GithubTrendingDeveloperFromJson(json);
GithubTrendingDeveloper();
String? username;
String? name;
String? type;
@ -45,10 +45,10 @@ class GithubTrendingDeveloper {
@JsonSerializable()
class GithubTrendingDeveloperRepository {
GithubTrendingDeveloperRepository();
factory GithubTrendingDeveloperRepository.fromJson(
Map<String, dynamic> json) =>
_$GithubTrendingDeveloperRepositoryFromJson(json);
GithubTrendingDeveloperRepository();
String? name;
String? description;
String? url;

View File

@ -322,6 +322,20 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
freezed:
dependency: "direct dev"
description:
name: freezed
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
freezed_annotation:
dependency: "direct main"
description:
name: freezed_annotation
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
from_css_color:
dependency: "direct main"
description:

View File

@ -76,6 +76,7 @@ dependencies:
from_css_color: ^2.0.0
maps_launcher: ^2.0.1
path: ^1.8.2
freezed_annotation: ^2.2.0
dev_dependencies:
build_runner: ^2.3.0
@ -83,6 +84,7 @@ dev_dependencies:
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter
freezed: ^2.2.0
json_serializable: ^6.5.1
# For information on the generic Dart part of this file, see the