reddit 0.6.0

  • Installing
  • Versions
  • 72

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 packages get

Alternatively, your editor might support pub get or flutter packages 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';
Version Uploaded Documentation Archive
0.6.0 Dec 7, 2018 Go to the documentation of reddit 0.6.0 Download reddit 0.6.0 archive
0.5.0 May 18, 2018 Go to the documentation of reddit 0.5.0 Download reddit 0.5.0 archive
0.4.0+1 Mar 15, 2018 Go to the documentation of reddit 0.4.0+1 Download reddit 0.4.0+1 archive
0.4.0 Jan 22, 2017 Go to the documentation of reddit 0.4.0 Download reddit 0.4.0 archive
0.3.3 Dec 18, 2015 Go to the documentation of reddit 0.3.3 Download reddit 0.3.3 archive
0.3.2 May 14, 2015 Go to the documentation of reddit 0.3.2 Download reddit 0.3.2 archive
0.3.1 Apr 1, 2015 Go to the documentation of reddit 0.3.1 Download reddit 0.3.1 archive
0.3.0 Apr 1, 2015 Go to the documentation of reddit 0.3.0 Download reddit 0.3.0 archive
0.2.0 Apr 1, 2015 Go to the documentation of reddit 0.2.0 Download reddit 0.2.0 archive
0.1.0+1 Mar 31, 2015 Go to the documentation of reddit 0.1.0+1 Download reddit 0.1.0+1 archive

All 11 versions...

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 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.13


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:reddit/reddit.dart.

Health suggestions

Fix lib/src/query.dart. (-1 points)

Analysis of lib/src/query.dart reported 2 hints:

line 67 col 14: 'NoSuchMethodError' is deprecated and shouldn't be used.

line 70 col 47: Use isNotEmpty instead of length

Format lib/src/listing.dart.

Run dartfmt to format lib/src/listing.dart.

Maintenance suggestions

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.

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+1
logging >=0.11.0 <0.12.0 0.11.3+2
oauth2 >=1.0.1 <2.0.0 1.2.3
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
meta 1.1.7
path 1.6.2
source_span 1.5.4
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test ^1.5.1+1