Commit 3a841fd0 authored by George's avatar George

format code using flutter format

parent ab215fa8
......@@ -146,19 +146,19 @@ class Settings {
Settings(
{this.title,
this.description,
this.logo,
this.icon,
this.coverImage,
this.facebook,
this.twitter,
this.lang,
this.timezone,
this.ghostHead,
this.ghostFoot,
this.navigation,
this.codeinjectionHead,
this.codeinjectionFoot});
this.description,
this.logo,
this.icon,
this.coverImage,
this.facebook,
this.twitter,
this.lang,
this.timezone,
this.ghostHead,
this.ghostFoot,
this.navigation,
this.codeinjectionHead,
this.codeinjectionFoot});
factory Settings.fromJson(Map<String, dynamic> json) {
return Settings(
......@@ -175,8 +175,8 @@ class Settings {
ghostFoot: json['ghost_foot'],
navigation: json['navigation'] != null
? json['navigation']
.map<NavigationItem>((item) => NavigationItem.fromJson(item))
.toList()
.map<NavigationItem>((item) => NavigationItem.fromJson(item))
.toList()
: null,
codeinjectionHead: json['codeinjection_head'],
codeinjectionFoot: json['codeinjection_foot'],
......@@ -233,36 +233,36 @@ class PostPage {
PostPage(
{this.id,
this.uuid,
this.title,
this.slug,
this.html,
this.commentId,
this.featureImage,
this.featured,
this.page,
this.metaTitle,
this.metaDescription,
this.createdAt,
this.updatedAt,
this.publishedAt,
this.customExcerpt,
this.codeinjectionHead,
this.codeinjectionFoot,
this.ogImage,
this.ogTitle,
this.ogDescription,
this.twitterImage,
this.twitterTitle,
this.twitterDescription,
this.customTemplate,
this.canonicalUrl,
this.tags,
this.authors,
this.primaryAuthor,
this.primaryTag,
this.url,
this.excerpt});
this.uuid,
this.title,
this.slug,
this.html,
this.commentId,
this.featureImage,
this.featured,
this.page,
this.metaTitle,
this.metaDescription,
this.createdAt,
this.updatedAt,
this.publishedAt,
this.customExcerpt,
this.codeinjectionHead,
this.codeinjectionFoot,
this.ogImage,
this.ogTitle,
this.ogDescription,
this.twitterImage,
this.twitterTitle,
this.twitterDescription,
this.customTemplate,
this.canonicalUrl,
this.tags,
this.authors,
this.primaryAuthor,
this.primaryTag,
this.url,
this.excerpt});
factory PostPage.fromJson(Map<String, dynamic> json) {
return PostPage(
......@@ -296,8 +296,8 @@ class PostPage {
: null,
authors: json['authors'] != null
? json['authors']
.map<Author>((authorJson) => Author.fromJson(authorJson))
.toList()
.map<Author>((authorJson) => Author.fromJson(authorJson))
.toList()
: null,
primaryAuthor: json['primary_author'] != null
? Author.fromJson(json['primary_author'])
......@@ -325,15 +325,15 @@ class Tag {
Tag(
{this.id,
this.name,
this.slug,
this.description,
this.featureImage,
this.visibility,
this.metaTitle,
this.metaDescription,
this.url,
this.count});
this.name,
this.slug,
this.description,
this.featureImage,
this.visibility,
this.metaTitle,
this.metaDescription,
this.url,
this.count});
factory Tag.fromJson(Map<String, dynamic> json) {
return Tag(
......@@ -346,9 +346,7 @@ class Tag {
metaTitle: json['meta_title'],
metaDescription: json['meta_description'],
url: json['url'],
count: json['count'] != null
? Count.fromJson(json['count'])
: null,
count: json['count'] != null ? Count.fromJson(json['count']) : null,
);
}
}
......@@ -371,19 +369,19 @@ class Author {
Author(
{this.id,
this.name,
this.slug,
this.profileImage,
this.coverImage,
this.bio,
this.website,
this.location,
this.facebook,
this.twitter,
this.metaTitle,
this.metaDescription,
this.url,
this.count});
this.name,
this.slug,
this.profileImage,
this.coverImage,
this.bio,
this.website,
this.location,
this.facebook,
this.twitter,
this.metaTitle,
this.metaDescription,
this.url,
this.count});
factory Author.fromJson(Map<String, dynamic> json) {
return Author(
......@@ -400,9 +398,7 @@ class Author {
metaTitle: json['meta_title'],
metaDescription: json['meta_description'],
url: json['url'],
count: json['count'] != null
? Count.fromJson(json['count'])
: null,
count: json['count'] != null ? Count.fromJson(json['count']) : null,
);
}
}
......@@ -452,6 +448,4 @@ class Count {
posts: json['posts'],
);
}
}
......@@ -23,18 +23,14 @@ class FilterExpression {
final String operator;
final String value;
FilterExpression({
@required this.property,
this.operator = '',
@required this.value
}) : assert(property != null, "Property must not be null"),
FilterExpression(
{@required this.property, this.operator = '', @required this.value})
: assert(property != null, "Property must not be null"),
assert(operator != null, "Operator must not be null"),
assert(value != null, "Value must not be null");
}
class GhostContentAPIClient {
Client client = Client();
final String url;
......@@ -48,18 +44,22 @@ class GhostContentAPIClient {
@required this.version,
@required this.contentAPIKey,
this.ghostPath = 'ghost',
}) : assert(url != null, "URL must not be null"),
}) : assert(url != null, "URL must not be null"),
assert(url.startsWith("https://"), "URL must start with https://"),
assert(!url.endsWith("/"), "URL must not end with /"),
assert(!ghostPath.startsWith("/") &&
!ghostPath.endsWith("/"), "Ghost Path cannot start or end with /"),
assert(!ghostPath.startsWith("/") && !ghostPath.endsWith("/"),
"Ghost Path cannot start or end with /"),
// todo asset key regex
assert(version != null && _supportedVersions.contains(version));
Future<PostsResponse> getPosts({List<PostPageInclude> includes, List<FilterExpression> filters, int limit = 15, int page = 1,}) async {
String endpoint = '$url/$ghostPath/api/$version/content/posts?key=$contentAPIKey&limit=$limit&page=$page';
Future<PostsResponse> getPosts({
List<PostPageInclude> includes,
List<FilterExpression> filters,
int limit = 15,
int page = 1,
}) async {
String endpoint =
'$url/$ghostPath/api/$version/content/posts?key=$contentAPIKey&limit=$limit&page=$page';
endpoint = _appendPostPageIncludes(endpoint, includes);
endpoint = _appendFilters(endpoint, filters);
......@@ -73,8 +73,10 @@ class GhostContentAPIClient {
throw Exception('Failed to get posts');
}
Future<PostResponse> getPostById(String id, {List<PostPageInclude> includes}) async {
String endpoint = '$url/$ghostPath/api/$version/content/posts/$id/?key=$contentAPIKey';
Future<PostResponse> getPostById(String id,
{List<PostPageInclude> includes}) async {
String endpoint =
'$url/$ghostPath/api/$version/content/posts/$id/?key=$contentAPIKey';
endpoint = _appendPostPageIncludes(endpoint, includes);
final response = await client.get(endpoint);
......@@ -87,8 +89,10 @@ class GhostContentAPIClient {
throw Exception('Failed to get post');
}
Future<PostResponse> getPostBySlug(String slug, {List<PostPageInclude> includes}) async {
String endpoint = '$url/$ghostPath/api/$version/content/posts/slug/$slug/?key=$contentAPIKey';
Future<PostResponse> getPostBySlug(String slug,
{List<PostPageInclude> includes}) async {
String endpoint =
'$url/$ghostPath/api/$version/content/posts/slug/$slug/?key=$contentAPIKey';
endpoint = _appendPostPageIncludes(endpoint, includes);
final response = await client.get(endpoint);
......@@ -102,7 +106,8 @@ class GhostContentAPIClient {
}
Future<AuthorsResponse> getAuthors({List<AuthorInclude> includes}) async {
String endpoint = '$url/$ghostPath/api/$version/content/authors?key=$contentAPIKey';
String endpoint =
'$url/$ghostPath/api/$version/content/authors?key=$contentAPIKey';
endpoint = _appendAuthorIncludes(endpoint, includes);
final response = await client.get(endpoint);
......@@ -115,8 +120,10 @@ class GhostContentAPIClient {
throw Exception('Failed to get authors');
}
Future<AuthorResponse> getAuthorById(String id, {List<AuthorInclude> includes}) async {
String endpoint = '$url/$ghostPath/api/$version/content/authors/$id/?key=$contentAPIKey';
Future<AuthorResponse> getAuthorById(String id,
{List<AuthorInclude> includes}) async {
String endpoint =
'$url/$ghostPath/api/$version/content/authors/$id/?key=$contentAPIKey';
endpoint = _appendAuthorIncludes(endpoint, includes);
final response = await client.get(endpoint);
......@@ -129,8 +136,10 @@ class GhostContentAPIClient {
throw Exception('Failed to get author');
}
Future<AuthorResponse> getAuthorBySlug(String slug, {List<AuthorInclude> includes}) async {
String endpoint = '$url/$ghostPath/api/$version/content/authors/slug/$slug/?key=$contentAPIKey';
Future<AuthorResponse> getAuthorBySlug(String slug,
{List<AuthorInclude> includes}) async {
String endpoint =
'$url/$ghostPath/api/$version/content/authors/slug/$slug/?key=$contentAPIKey';
endpoint = _appendAuthorIncludes(endpoint, includes);
final response = await client.get(endpoint);
......@@ -144,7 +153,8 @@ class GhostContentAPIClient {
}
Future<TagsResponse> getTags({List<TagInclude> includes}) async {
String endpoint = '$url/$ghostPath/api/$version/content/tags?key=$contentAPIKey';
String endpoint =
'$url/$ghostPath/api/$version/content/tags?key=$contentAPIKey';
endpoint = _appendTagIncludes(endpoint, includes);
final response = await client.get(endpoint);
......@@ -158,7 +168,8 @@ class GhostContentAPIClient {
}
Future<TagResponse> getTagById(String id, {List<TagInclude> includes}) async {
String endpoint = '$url/$ghostPath/api/$version/content/tags/$id/?key=$contentAPIKey';
String endpoint =
'$url/$ghostPath/api/$version/content/tags/$id/?key=$contentAPIKey';
endpoint = _appendTagIncludes(endpoint, includes);
final response = await client.get(endpoint);
......@@ -171,8 +182,10 @@ class GhostContentAPIClient {
throw Exception('Failed to get tag');
}
Future<TagResponse> getTagBySlug(String slug, {List<TagInclude> includes}) async {
String endpoint = '$url/$ghostPath/api/$version/content/tags/slug/$slug/?key=$contentAPIKey';
Future<TagResponse> getTagBySlug(String slug,
{List<TagInclude> includes}) async {
String endpoint =
'$url/$ghostPath/api/$version/content/tags/slug/$slug/?key=$contentAPIKey';
endpoint = _appendTagIncludes(endpoint, includes);
final response = await client.get(endpoint);
......@@ -186,7 +199,8 @@ class GhostContentAPIClient {
}
Future<PagesResponse> getPages({List<PostPageInclude> includes}) async {
String endpoint = '$url/$ghostPath/api/$version/content/pages?key=$contentAPIKey';
String endpoint =
'$url/$ghostPath/api/$version/content/pages?key=$contentAPIKey';
endpoint = _appendPostPageIncludes(endpoint, includes);
final response = await client.get(endpoint);
......@@ -199,8 +213,10 @@ class GhostContentAPIClient {
throw Exception('Failed to get pages');
}
Future<PageResponse> getPageById(String id, {List<PostPageInclude> includes}) async {
String endpoint = '$url/$ghostPath/api/$version/content/pages/$id/?key=$contentAPIKey';
Future<PageResponse> getPageById(String id,
{List<PostPageInclude> includes}) async {
String endpoint =
'$url/$ghostPath/api/$version/content/pages/$id/?key=$contentAPIKey';
endpoint = _appendPostPageIncludes(endpoint, includes);
final response = await client.get(endpoint);
......@@ -213,8 +229,10 @@ class GhostContentAPIClient {
throw Exception('Failed to get page');
}
Future<PageResponse> getPageBySlug(String slug, {List<PostPageInclude> includes}) async {
String endpoint = '$url/$ghostPath/api/$version/content/pages/slug/$slug/?key=$contentAPIKey';
Future<PageResponse> getPageBySlug(String slug,
{List<PostPageInclude> includes}) async {
String endpoint =
'$url/$ghostPath/api/$version/content/pages/slug/$slug/?key=$contentAPIKey';
endpoint = _appendPostPageIncludes(endpoint, includes);
final response = await client.get(endpoint);
......@@ -228,7 +246,8 @@ class GhostContentAPIClient {
}
Future<SettingsResponse> getSettings() async {
String endpoint = '$url/$ghostPath/api/$version/content/settings?key=$contentAPIKey';
String endpoint =
'$url/$ghostPath/api/$version/content/settings?key=$contentAPIKey';
final response = await client.get(endpoint);
......@@ -240,10 +259,16 @@ class GhostContentAPIClient {
throw Exception('Failed to get settings');
}
String _appendPostPageIncludes(String endpoint, List<PostPageInclude> includes) {
String _appendPostPageIncludes(
String endpoint, List<PostPageInclude> includes) {
if (includes != null && includes.length > 0) {
endpoint += '&include=';
endpoint += includes.map((include) => include.toString().toLowerCase().replaceAll('postpageinclude.', '')).join(',');
endpoint += includes
.map((include) => include
.toString()
.toLowerCase()
.replaceAll('postpageinclude.', ''))
.join(',');
}
return endpoint;
}
......@@ -268,10 +293,10 @@ class GhostContentAPIClient {
if (filters != null) {
for (int i = 0; i < filters.length; ++i) {
FilterExpression filter = filters[i];
endpoint += '&filter=' + filter.property + ':' + filter.operator + filter.value;
endpoint +=
'&filter=' + filter.property + ':' + filter.operator + filter.value;
}
}
return endpoint;
}
}
......@@ -2,7 +2,6 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_ghost_content_api/src/widgets/ghost_content_api_client.dart';
class GhostContentAPIProvider extends InheritedWidget {
final GhostContentAPIClient client;
final Widget child;
......@@ -12,12 +11,13 @@ class GhostContentAPIProvider extends InheritedWidget {
});
static GhostContentAPIClient of(BuildContext context) {
return (context.inheritFromWidgetOfExactType(GhostContentAPIProvider) as GhostContentAPIProvider).client;
return (context.inheritFromWidgetOfExactType(GhostContentAPIProvider)
as GhostContentAPIProvider)
.client;
}
@override
bool updateShouldNotify(InheritedWidget oldWidget) {
return true;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment