pd4d10 / git-touch

An open-source app for GitHub, GitLab, Bitbucket, Gitea, and Gitee(码云), built with Flutter
Apache License 2.0
1.56k stars 137 forks source link

Support for gists #66

Closed shreyas1599 closed 4 years ago

shreyas1599 commented 4 years ago

Add user's gists in the profile section.

shreyas1599 commented 4 years ago

@pd4d10 I could use some help. Consider the json output for getting gists.

Files is another json and not a list. I'm having trouble serializing this. The Spinlocklabs github.dart declares it as a list which is wrong and results in an error. I've opened an issue there. This is what I've done for now.

class GithubGistsItem {
  String id;
  String description;
  bool public;
  Map<String, GistFiles> files;
  GithubEventUser owner;
  List<dynamic> get fileNames {
    var filenames = [];
    files.forEach((String key, GistFiles value) {
      filenames.add(value);
    });
    return filenames;
  }

  DateTime createdAt;
  DateTime updatedAt;

  GithubGistsItem();
  factory GithubGistsItem.fromJson(Map<String, dynamic> json) =>
      _$GithubGistsItemFromJson(json);
} 

But making fileNamesdynamic is creating problems everywhere and I'm not sure if this is the right way to serialize it. For instance, I am unable to use the ObjectTree widget. I have created another widget file and solved the problem but I think re-using the ObjectTree widget is a better way to go. The error is something to do with fileNames being dynamic. Any help is appreciated. Thanks.

pd4d10 commented 4 years ago

What's the error message (or error stack)?

shreyas1599 commented 4 years ago

type 'MappedListIterable<dynamic, dynamic>' is not a subtype of type 'Iterable<ObjectTreeItem>'

This is what I tried to do:

return ObjectTree(  
          items: payload.fileNames.map((v) {
            return ObjectTreeItem(  
              url: '',
              type: v.type,
              name: v.filename,
              downloadUrl: v.rawUrl,
            );
          }),
        );
pd4d10 commented 4 years ago

How about using files.values()?

pd4d10 commented 4 years ago

Or files.entries() if you want the key too

shreyas1599 commented 4 years ago

Doesn't work. Still getting the same error.

pd4d10 commented 4 years ago

Oh, my mistake. values and entries are getters, not methods.

pd4d10 commented 4 years ago

Perhaps you could submit a WIP pull request so I could help to check it.

shreyas1599 commented 4 years ago

Oh, my mistake. values and entries are getters, not methods.

I used them as getters only. Does it make a difference if it's a getter and not a method for this case?