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

TypeConverter sample code with possible error #439

Closed
cassioseffrin opened this issue Dec 3, 2020 · 3 comments
Closed

TypeConverter sample code with possible error #439

cassioseffrin opened this issue Dec 3, 2020 · 3 comments

Comments

@cassioseffrin
Copy link
Contributor

When the database final attribute has null value the DateTimeConverter will throws an error when it's convert a null value.

So I have made a correction with try catch to avoid it. May you could update the example on README.md.

class DateTimeConverter extends TypeConverter<DateTime, int> {
  @override
  DateTime decode(int databaseValue) {
    try {
      return DateTime.fromMillisecondsSinceEpoch(databaseValue);
    } catch (e) {
      return null;
    }
  }

  @override
  int encode(DateTime value) {
    try {
      return value.millisecondsSinceEpoch;
    } catch (e) {
      return null;
    }
  }
}
@cassioseffrin
Copy link
Contributor Author

The code above was my fix to documentation, it will be nice to update the docs to help the community. As I got no response from team I am closing it.

@vitusortner
Copy link
Collaborator

@cassioseffrin sorry for the late reply. Feel free to open a PR to improve the project's documentation.

@cassioseffrin
Copy link
Contributor Author

@vitusortner I have made the PR, please check it here #442

Thks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants