Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

make compatible with sdk 2.12 #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions super_enum/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ enum _MoviesResponse {
NoNetwork,

/// UnexpectedException State of the MovieResponse
@Data(fields: [DataField<Exception>('exception')])
@Data(fields: [DataField<Object>('exception')])
UnexpectedException
}

class MoviesFetcher {
http.Client client = http.Client();
final _baseUrl = "http://api.themoviedb.org/3/movie";

final String apiKey;

MoviesFetcher({@required this.apiKey});
MoviesFetcher({required this.apiKey});

Future<MoviesResponse> fetchMovies() async {
try {
final response = await client.get('$_baseUrl/popular?api_key=$apiKey');
final response =
await client.get(Uri(scheme: 'http', host: 'api.themoviedb.org', path: '/3/movie/popular', queryParameters: {'api_key': apiKey}));
if (response.statusCode == 200) {
final movies = Movies.fromJson(json.decode(response.body));
return MoviesResponse.success(movies: movies);
Expand All @@ -59,13 +59,12 @@ void main() async {
);

final _moviesResponse = await _moviesFetcher.fetchMovies();

_moviesResponse.when(
success: (data) => print('Total Movies: ${data.movies.totalPages}'),
unauthorized: () => print('Invalid ApiKey'),
noNetwork: () => print(
onSuccess: (data) => print('Total Movies: ${data.movies.totalPages}'),
onUnauthorized: () => print('Invalid ApiKey'),
onNoNetwork: () => print(
'No Internet, Please check your internet connection',
),
unexpectedException: (error) => print(error.exception),
onUnexpectedException: (error) => print(error.exception),
);
}
113 changes: 49 additions & 64 deletions super_enum/example/main.super.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions super_enum/example/movies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ class Movies extends Equatable {
final int page;
final int totalResults;
final int totalPages;
final List<Movie> results;
final List<Movie>? results;

const Movies({this.page, this.totalResults, this.totalPages, this.results});
const Movies({required this.page, required this.totalResults, required this.totalPages, this.results});

factory Movies.fromJson(Map<String, dynamic> json) => Movies(
page: json['page'],
totalResults: json['total_results'],
totalPages: json['total_pages'],
results: (json['results'] as List)
results: (json['results'] as List?)
?.map((v) => Movie.fromJson(v))
?.toList() ??
.toList() ??
[],
);

Expand All @@ -24,7 +24,7 @@ class Movies extends Equatable {
data['total_results'] = this.totalResults;
data['total_pages'] = this.totalPages;
if (this.results != null) {
data['results'] = this.results.map((v) => v.toJson()).toList();
data['results'] = this.results!.map((v) => v.toJson()).toList();
}
return data;
}
Expand All @@ -39,20 +39,20 @@ class Movies extends Equatable {
}

class Movie extends Equatable {
final int voteCount;
final int id;
final bool video;
final voteAverage;
final String title;
final double popularity;
final String posterPath;
final String originalLanguage;
final String originalTitle;
final List<int> genreIds;
final String backdropPath;
final bool adult;
final String overview;
final String releaseDate;
final int? voteCount;
final int? id;
final bool? video;
final dynamic voteAverage;
final String? title;
final double? popularity;
final String? posterPath;
final String? originalLanguage;
final String? originalTitle;
final List<int>? genreIds;
final String? backdropPath;
final bool? adult;
final String? overview;
final String? releaseDate;

Movie(
{this.voteCount,
Expand Down
4 changes: 2 additions & 2 deletions super_enum/lib/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ObjectClass {
class Data {
final List<DataField> fields;

const Data({@required this.fields});
const Data({required this.fields});
}

/// Mark the generated type as generic.
Expand Down Expand Up @@ -78,5 +78,5 @@ class UseClass {
final Type type;
final String name;

const UseClass(this.type, {this.name});
const UseClass(this.type, {required this.name});
}
11 changes: 5 additions & 6 deletions super_enum/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
name: super_enum
description: Create super-powered enums similar to sealed classes in Kotlin.
version: 0.5.0
version: 0.6.0
homepage: https://github.com/xsahil03x/super_enum

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
meta: ^1.2.3
equatable: ^1.2.5
equatable: ^2.0.0

# Adding dev dependencies
# just for showcasing an example
dev_dependencies:
http: ^0.12.0+2
build_runner: ^1.7.1
http: ^0.13.0
build_runner: ^2.0.0
super_enum_generator:
path: ../super_enum_generator

Loading