reddit 0.6.0

dart-reddit #

A Reddit library for Dart, inspired by reddit.js (API) and raw.js (Auth).

Documentation #

See the Dart documentation.

Usage #

Add the following to your pubspec.yaml:

  reddit: any

Creating a client #

The top class Reddit takes a Client as parameter. This client can be constructed using thehttp package.

// in Dart VM
Reddit reddit = new Reddit(new Client());
// in browser
Reddit reddit = new Reddit(new BrowserClient());

OAuth #

To enable OAuth, you will need an app identifier and a secret. Get them here.

OAuth is required for some of the public endpoints (those marked OAuth-only) and will be required for all endpoints starting August 3, 2015 (see this announcement).

There are two options: App-only and User authorization.

  • App-only auth
reddit.authSetup(identifier, secret);
// with user info
await reddit.authFinish(username: "sroose", password: "correct horse battery staple");
// or without
await reddit.authFinish();

Note that not providing (developer) user info will result in getting 503 Service Unavailable responses after a while.

  • User-enabled auth
reddit.authSetup(identifier, secret);
Uri authUrl = reddit.authUrl("");
// redirect user to authUrl and gather the response from the auth server
await reddit.authFinish(response: authServerResponse);
// or if you already extracted the auth code from the response
await reddit.authFinish(code: authCode);

Queries, filters and listings #

Most methods in the API construct a Query, which can be fetched to get a future with the results.

Most queries allow filtering. For the supported filters, we refer to the Reddit API docs or the documentation for this library.

// without filters
// filtered;

A lot of queries also are listings. Listings allow for browsing through content across multiple queries.

// using the regular fetch() method (not recommended)
reddit.sub("dartlang").top("day").fetch().then((result) {
  if (notEnough) {
    result.fetchMore().then((result) {
      if (stillNotEnough) {

// or using the dart:async API
reddit.sub("dartlang").top("month").listen((result) {
  if (notEnough) {

Browsing Reddit #

You can use the standard read-only API to browse Reddit.

// the front page;
// or subreddits

Some examples using filters:


Comments #

Fetching comments for a link:


Or a single comment:


Search through reddit:

reddit.sub("dartlang").search("reddit api").limit(5).sort("hot").fetch().then(print);

Subreddits #

Find subreddits:



reddit.recommendedSubreddits(["dartlang", "reddit"]).fetch().then(print);


Get information about a subreddit:


Users #

Get information about a user:


Get listings from users:



Get a list of multi's from a user:


Changelog #

0.5.0 #

  • Remove json_object dependency and use Map instead.
  • Remove mirrors dependency
  • Add ResultListing.results getter for the underlying stream.

0.4.0 (2017-01-22) #

  • Fix to restrict results to the subreddit

0.3.3 (2015-12-18) #

  • Upgraded dependencies to latest versions
  • Adapted to breaking changes in oauth2 v1.0.0
  • Added better support for multireddits

0.3.2 (2015-04-03) #

  • Updated RedditUri with official regex and extra test
  • Updated README
  • Constant constructor for Fullname
  • Improved exception handling in Query

0.3.1 (2015-04-02) #

  • Added FullnameType enum
  • Added and Fullname.type getters
  • Bugfix in FilterableQuery.filter

0.3.0 (2015-04-01) #

  • Added full OAuth2 support (app-only and user)
  • Changed auth interface
  • Expose RedditUri and Fullname classes

0.2.0 (2015-04-01) #

  • Added App-only OAuth support, inspired by raw.js

0.1.0 (2015-03-31) #

  • Initial version, inspired by reddit.js

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  reddit: ^0.6.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:reddit/reddit.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Fix lib/src/reddit.dart. (-15.67 points)

Analysis of lib/src/reddit.dart reported 34 hints, including:

line 13 col 32: Unnecessary new keyword.

line 18 col 10: Don't type annotate initializing formals.

line 19 col 14: Unnecessary new keyword.

line 24 col 32: Unnecessary new keyword.

line 26 col 39: Unnecessary new keyword.

Fix lib/src/user.dart. (-11.78 points)

Analysis of lib/src/user.dart reported 25 hints, including:

line 3 col 1: Prefer using /// for doc comments.

line 13 col 16: Don't type annotate initializing formals.

line 13 col 37: Don't type annotate initializing formals.

line 19 col 20: Unnecessary new keyword.

line 23 col 3: Prefer using /// for doc comments.

Fix lib/src/listing.dart. (-5.36 points)

Analysis of lib/src/listing.dart reported 11 hints, including:

line 3 col 1: Prefer using /// for doc comments.

line 8 col 48: Avoid const keyword.

line 22 col 19: Unnecessary new keyword.

line 27 col 13: Unnecessary new keyword.

line 30 col 16: Unnecessary new keyword.

Fix additional 6 files with analysis or formatting issues. (-23.06 points)

Additional issues in the following files:

  • lib/src/query.dart (11 hints)
  • lib/src/subreddit.dart (10 hints)
  • lib/src/listings.dart (8 hints)
  • lib/src/reddit_uri.dart (8 hints)
  • lib/src/fullname.dart (6 hints)
  • lib/src/multireddit.dart (4 hints)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (http).

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is getting outdated. (-18.36 points)

The package was last published 61 weeks ago.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and reddit.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
http >=0.11.1+3 <0.12.0 0.11.3+17 0.12.0+4
logging >=0.11.0 <0.12.0 0.11.4
oauth2 >=1.0.1 <2.0.0 1.5.0
Transitive dependencies
async 2.4.0
charcode 1.1.3
collection 1.14.12
http_parser 3.1.3
meta 1.1.8
path 1.6.4
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test ^1.5.1+1