Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to null safety dart 2.0 #50

Merged
merged 1 commit into from
Apr 25, 2021
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ doc/api/

.idea
.dart_tool

.vscode/
7 changes: 4 additions & 3 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ void main() async {
var client = http.Client();

// RSS feed
var response = await client
.get('https://developer.apple.com/news/releases/rss/releases.rss');
var response = await client.get(
Uri(path: 'https://developer.apple.com/news/releases/rss/releases.rss'));
var channel = RssFeed.parse(response.body);
print(channel);

// Atom feed
response = await client.get('https://www.theverge.com/rss/index.xml');
response =
await client.get(Uri(path: 'https://www.theverge.com/rss/index.xml'));
var feed = AtomFeed.parse(response.body);
print(feed);

Expand Down
6 changes: 3 additions & 3 deletions lib/domain/atom_category.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:xml/xml.dart';

class AtomCategory {
final String term;
final String scheme;
final String label;
final String? term;
final String? scheme;
final String? label;

AtomCategory(this.term, this.scheme, this.label);

Expand Down
26 changes: 13 additions & 13 deletions lib/domain/atom_feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import 'package:webfeed/util/xml.dart';
import 'package:xml/xml.dart';

class AtomFeed {
final String id;
final String title;
final DateTime updated;
final List<AtomItem> items;
final String? id;
final String? title;
final DateTime? updated;
final List<AtomItem>? items;

final List<AtomLink> links;
final List<AtomPerson> authors;
final List<AtomPerson> contributors;
final List<AtomCategory> categories;
final AtomGenerator generator;
final String icon;
final String logo;
final String rights;
final String subtitle;
final List<AtomLink>? links;
final List<AtomPerson>? authors;
final List<AtomPerson>? contributors;
final List<AtomCategory>? categories;
final AtomGenerator? generator;
final String? icon;
final String? logo;
final String? rights;
final String? subtitle;

AtomFeed({
this.id,
Expand Down
12 changes: 5 additions & 7 deletions lib/domain/atom_generator.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import 'package:xml/xml.dart';

class AtomGenerator {
final String uri;
final String version;
final String value;
final String? uri;
final String? version;
final String? value;

AtomGenerator(this.uri, this.version, this.value);

factory AtomGenerator.parse(XmlElement element) {
if (element == null) {
return null;
}
static parse(XmlElement? element) {
if (element == null) return null;
var uri = element.getAttribute('uri');
var version = element.getAttribute('version');
var value = element.text;
Expand Down
26 changes: 13 additions & 13 deletions lib/domain/atom_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import 'package:webfeed/util/xml.dart';
import 'package:xml/xml.dart';

class AtomItem {
final String id;
final String title;
final DateTime updated;
final String? id;
final String? title;
final DateTime? updated;

final List<AtomPerson> authors;
final List<AtomLink> links;
final List<AtomCategory> categories;
final List<AtomPerson> contributors;
final AtomSource source;
final String published;
final String content;
final String summary;
final String rights;
final Media media;
final List<AtomPerson>? authors;
final List<AtomLink>? links;
final List<AtomCategory>? categories;
final List<AtomPerson>? contributors;
final AtomSource? source;
final String? published;
final String? content;
final String? summary;
final String? rights;
final Media? media;

AtomItem({
this.id,
Expand Down
12 changes: 6 additions & 6 deletions lib/domain/atom_link.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:xml/xml.dart';

class AtomLink {
final String href;
final String rel;
final String type;
final String hreflang;
final String title;
final String? href;
final String? rel;
final String? type;
final String? hreflang;
final String? title;
final int length;

AtomLink(
Expand All @@ -25,7 +25,7 @@ class AtomLink {
var hreflang = element.getAttribute('hreflang');
var length = 0;
if (element.getAttribute('length') != null) {
length = int.parse(element.getAttribute('length'));
length = int.parse(element.getAttribute('length')!);
}
return AtomLink(href, rel, type, hreflang, title, length);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/domain/atom_person.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:webfeed/util/xml.dart';
import 'package:xml/xml.dart';

class AtomPerson {
final String name;
final String uri;
final String email;
final String? name;
final String? uri;
final String? email;

AtomPerson({this.name, this.uri, this.email});

Expand Down
12 changes: 5 additions & 7 deletions lib/domain/atom_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ import 'package:webfeed/util/xml.dart';
import 'package:xml/xml.dart';

class AtomSource {
final String id;
final String title;
final String updated;
final String? id;
final String? title;
final String? updated;

AtomSource({
this.id,
this.title,
this.updated,
});

factory AtomSource.parse(XmlElement element) {
if (element == null) {
return null;
}
static parse(XmlElement? element) {
if (element == null) return null;
return AtomSource(
id: findFirstElement(element, 'id')?.text,
title: findFirstElement(element, 'title')?.text,
Expand Down
36 changes: 18 additions & 18 deletions lib/domain/dublin_core/dublin_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import 'package:webfeed/util/xml.dart';
import 'package:xml/xml.dart';

class DublinCore {
final String title;
final String description;
final String creator;
final String subject;
final String publisher;
final String contributor;
final DateTime date;
final DateTime created;
final DateTime modified;
final String type;
final String format;
final String identifier;
final String source;
final String language;
final String relation;
final String coverage;
final String rights;
final String? title;
final String? description;
final String? creator;
final String? subject;
final String? publisher;
final String? contributor;
final DateTime? date;
final DateTime? created;
final DateTime? modified;
final String? type;
final String? format;
final String? identifier;
final String? source;
final String? language;
final String? relation;
final String? coverage;
final String? rights;

DublinCore({
this.title,
Expand All @@ -41,7 +41,7 @@ class DublinCore {
this.rights,
});

factory DublinCore.parse(XmlElement element) {
static parse(XmlElement? element) {
if (element == null) {
return null;
}
Expand Down
44 changes: 22 additions & 22 deletions lib/domain/itunes/itunes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import 'package:webfeed/util/xml.dart';
import 'package:xml/xml.dart';

class Itunes {
final String author;
final String summary;
final bool explicit;
final String title;
final String subtitle;
final ItunesOwner owner;
final List<String> keywords;
final ItunesImage image;
final List<ItunesCategory> categories;
final ItunesType type;
final String newFeedUrl;
final bool block;
final bool complete;
final int episode;
final int season;
final Duration duration;
final ItunesEpisodeType episodeType;
final String? author;
final String? summary;
final bool? explicit;
final String? title;
final String? subtitle;
final ItunesOwner? owner;
final List<String>? keywords;
final ItunesImage? image;
final List<ItunesCategory?>? categories;
final ItunesType? type;
final String? newFeedUrl;
final bool? block;
final bool? complete;
final int? episode;
final int? season;
final Duration? duration;
final ItunesEpisodeType? episodeType;

Itunes({
this.author,
Expand All @@ -45,7 +45,7 @@ class Itunes {
this.episodeType,
});

factory Itunes.parse(XmlElement element) {
static parse(XmlElement? element) {
if (element == null) {
return null;
}
Expand All @@ -61,12 +61,12 @@ class Itunes {
owner: ItunesOwner.parse(findFirstElement(element, 'itunes:owner')),
keywords: findFirstElement(element, 'itunes:keywords')
?.text
?.split(',')
?.map((keyword) => keyword.trim())
?.toList() ??
.split(',')
.map((keyword) => keyword.trim())
.toList() ??
[],
image: ItunesImage.parse(findFirstElement(element, 'itunes:image')),
categories: findElements(element, 'itunes:category')
categories: findElements(element, 'itunes:category')!
.map((e) => ItunesCategory.parse(e))
.toList(),
type: newItunesType(findFirstElement(element, 'itunes:type')),
Expand Down
18 changes: 8 additions & 10 deletions lib/domain/itunes/itunes_category.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import 'package:xml/xml.dart';

class ItunesCategory {
final String category;
final List<String> subCategories;
final String? category;
final List<String?>? subCategories;

ItunesCategory({this.category, this.subCategories});

factory ItunesCategory.parse(XmlElement element) {
static ItunesCategory? parse(XmlElement? element) {
if (element == null) return null;
return ItunesCategory(
category: element.getAttribute('text')?.trim(),
subCategories: element
.findElements('itunes:category')
?.map((e) => e.getAttribute('text')?.trim())
?.toList() ??
[],
);
category: element.getAttribute('text')?.trim(),
subCategories: element
.findElements('itunes:category')
.map((e) => e.getAttribute('text')?.trim())
.toList());
}
}
2 changes: 1 addition & 1 deletion lib/domain/itunes/itunes_episode_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:xml/xml.dart';

enum ItunesEpisodeType { full, trailer, bonus, unknown }

ItunesEpisodeType newItunesEpisodeType(XmlElement element) {
ItunesEpisodeType newItunesEpisodeType(XmlElement? element) {
switch (element?.text) {
case 'full':
return ItunesEpisodeType.full;
Expand Down
9 changes: 6 additions & 3 deletions lib/domain/itunes/itunes_image.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import 'package:xml/xml.dart';

class ItunesImage {
final String href;
final String? href;

ItunesImage({this.href});

factory ItunesImage.parse(XmlElement element) {
static parse(XmlElement? element) {
ItunesImage? result;
if (element == null) return null;
return ItunesImage(
result = ItunesImage(
href: element.getAttribute('href')?.trim(),
);

return result;
}
}
11 changes: 5 additions & 6 deletions lib/domain/itunes/itunes_owner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import 'package:webfeed/util/xml.dart';
import 'package:xml/xml.dart';

class ItunesOwner {
final String name;
final String email;
final String? name;
final String? email;

ItunesOwner({this.name, this.email});

factory ItunesOwner.parse(XmlElement element) {
if (element == null) return null;
factory ItunesOwner.parse(XmlElement? element) {
return ItunesOwner(
name: findFirstElement(element, 'itunes:name')?.text?.trim(),
email: findFirstElement(element, 'itunes:email')?.text?.trim(),
name: findFirstElement(element, 'itunes:name')?.text.trim(),
email: findFirstElement(element, 'itunes:email')?.text.trim(),
);
}
}
2 changes: 1 addition & 1 deletion lib/domain/itunes/itunes_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:xml/xml.dart';

enum ItunesType { episodic, serial, unknown }

ItunesType newItunesType(XmlElement element) {
ItunesType newItunesType(XmlElement? element) {
switch (element?.text) {
case 'episodic':
return ItunesType.episodic;
Expand Down
Loading