Support for gists #46

Closed
opened 2025-10-31 17:04:30 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @shreyas1599 on GitHub (Apr 23, 2020).

Add user's gists in the profile section.

Originally created by @shreyas1599 on GitHub (Apr 23, 2020). Add user's gists in the profile section.
Author
Owner

@shreyas1599 commented on GitHub (May 6, 2020):

@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.

@shreyas1599 commented on GitHub (May 6, 2020): @pd4d10 I could use some help. Consider the json output for getting [gists](https://api.github.com/users/shreyas1599/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 `fileNames`dynamic 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.
Author
Owner

@pd4d10 commented on GitHub (May 6, 2020):

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

@pd4d10 commented on GitHub (May 6, 2020): What's the error message (or error stack)?
Author
Owner

@shreyas1599 commented on GitHub (May 6, 2020):

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,
            );
          }),
        );
@shreyas1599 commented on GitHub (May 6, 2020): `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, ); }), ); ```
Author
Owner

@pd4d10 commented on GitHub (May 6, 2020):

How about using files.values()?

@pd4d10 commented on GitHub (May 6, 2020): How about using `files.values()`?
Author
Owner

@pd4d10 commented on GitHub (May 6, 2020):

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

@pd4d10 commented on GitHub (May 6, 2020): Or `files.entries()` if you want the key too
Author
Owner

@shreyas1599 commented on GitHub (May 6, 2020):

Doesn't work. Still getting the same error.

@shreyas1599 commented on GitHub (May 6, 2020): Doesn't work. Still getting the same error.
Author
Owner

@pd4d10 commented on GitHub (May 6, 2020):

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

@pd4d10 commented on GitHub (May 6, 2020): Oh, my mistake. `values` and `entries` are getters, not methods.
Author
Owner

@pd4d10 commented on GitHub (May 6, 2020):

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

@pd4d10 commented on GitHub (May 6, 2020): Perhaps you could submit a WIP pull request so I could help to check it.
Author
Owner

@shreyas1599 commented on GitHub (May 6, 2020):

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?

@shreyas1599 commented on GitHub (May 6, 2020): > 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?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/git-touch#46