twitter_kit 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

twitter_kit #

Project to make it easier to access the Twitter API. Referring to the Twitter kit for Android. Web is not supported due to Cross-Domain issues.

Usage #

  import 'package:twitter_kit/twitter_kit.dart';

  final Twitter twitter = Twitter(consumerKey, consumerSecret);
  await _twitter.initialize();
  // get current session
  final currentSession = await twitter.currentSession;
  // is session active
  final isSessionActive = await twitter.isSessionActive;
  // login
  final isLogin = await twitter.login();
  // logout
  await twitter.logout();
  // use rest api
  final StatusesService statusesService = twitter.statusesService;
  await statusesService.show(1242645624106807297).then((response) {
    if (response.isSuccessful) {
      final Tweet tweet = response.body;
      print(tweet.toJson());
    } else {
      print(response.error);
    }
  });

TODO #

  • Adding the media api
  • Adding the search api
  • Adding the APIs not included in twitter-kit-android

0.2.0 #

  • Fix logout process
  • Add twitter login for iOS

0.1.0 #

  • Add List service
  • Add Favorite service
  • Add configuration service
  • Add collection service
  • Add account service

0.0.6 #

  • Add other statuses api

0.0.5 #

  • Remove code that doesn't work

0.0.4 #

  • Add twitter login. ※Android only
  • Add update status.

0.0.3 #

  • Fix export library.

0.0.2 #

  • Fix models.

0.0.1 #

  • Initial release.

example/lib/main.dart

import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:twitter_kit/twitter_kit.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO Your key.
    final twitter = Twitter("", "", logging: true);
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: FutureBuilder(
            future: twitter.initialize(),
            builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
              if (snapshot.hasData) {
                return Body(twitter, snapshot.data);
              } else {
                return Container();
              }
            },
          ),
        ),
      ),
    );
  }
}

class Body extends StatefulWidget {
  Body(this._twitter, this.isSessionActive);

  final Twitter _twitter;
  final bool isSessionActive;

  @override
  _BodyState createState() => _BodyState();
}

class _BodyState extends State<Body> {
  bool _isSessionActive;
  Tweet _tweet;

  @override
  void initState() {
    _isSessionActive = widget.isSessionActive;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    if (_isSessionActive) {
      if (_tweet == null) {
        _requestShowTweet();
      }
      return InkWell(
        onTap: () async {
          await widget._twitter.logout();
          setState(() {
            _isSessionActive = false;
          });
        },
        child: Text(_tweet != null ? jsonEncode(_tweet.toJson()) : "ready"),
      );
    } else {
      return RaisedButton(
          child: const Text('Sign In With Twitter.'),
          onPressed: () async {
            final twitterLoginStatus = await widget._twitter.login();
            if (twitterLoginStatus) {
              setState(() {
                _isSessionActive = true;
              });
            }
          });
    }
  }

  Future<void> _requestShowTweet() async {
    widget._twitter.statusesService.show(1242645624106807297).then((response) {
      if (response.isSuccessful) {
        setState(() {
          _tweet = response.body;
        });
      } else {
        print(response.error);
      }
    });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  twitter_kit: ^0.2.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:twitter_kit/twitter_kit.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
33
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

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

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
chopper ^3.0.2 3.0.2
flutter 0.0.0
json_annotation ^3.0.1 3.0.1
oauth1 ^1.0.4 1.0.4
Transitive dependencies
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.5
http 0.12.1
http_parser 3.1.4
logging 0.11.4
meta 1.1.8
path 1.7.0
pedantic 1.9.0
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
build_runner ^1.8.0
chopper_generator ^3.0.4
flutter_test
json_serializable ^3.3.0