Skip to content

Commit

Permalink
v1.1.0 (#5)
Browse files Browse the repository at this point in the history
* Support for Dart 2.0. Also a test case for logout.

* Updated Travis file to do the build with Dart 2.0.

* Updated sample to use the logout method.

* Updated changelog, readme and pubspec to reflect the new changes.
  • Loading branch information
roughike committed Mar 24, 2018
1 parent 245dd1a commit c7ee951
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ addons:
- fonts-droid

before_script:
- git clone https://github.com/flutter/flutter.git -b dev --depth 1
- git clone https://github.com/flutter/flutter.git -b master --depth 1
- ./flutter/bin/flutter doctor
- gem install coveralls-lcov

script:
- ./flutter/bin/flutter test --coverage
- ./flutter/bin/flutter test --preview-dart-2 --coverage

after_success:
- coveralls-lcov coverage/lcov.info
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0

* Dart 2 support! There should not be any breaking changes. Please do file issues if you have problems.

## 1.0.1

* Fixed `onActivityResult` override that was potentially preventing other plugins from receiving `Activity` results.
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ A Flutter plugin for using the native TwitterKit SDKs on Android and iOS.

This plugin uses [the new Gradle 4.1 and Android Studio 3.0 project setup](https://github.com/flutter/flutter/wiki/Updating-Flutter-projects-to-Gradle-4.1-and-Android-Studio-Gradle-plugin-3.0.1).

## Dart support

* Dart 1: 1.0.x.
* Dart 2: 1.1.0 and up.

## Installation

See the [installation instructions on pub](https://pub.dartlang.org/packages/flutter_twitter_login#-installing-tab-). No platform-specific configuration is needed!
Expand Down
1 change: 1 addition & 0 deletions example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions example/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
56 changes: 34 additions & 22 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,35 @@ class _MyAppState extends State<MyApp> {

String _message = 'Logged out.';

void _login() async {
final TwitterLoginResult result = await twitterLogin.authorize();
String newMessage;

switch (result.status) {
case TwitterLoginStatus.loggedIn:
newMessage = 'Logged in! username: ${result.session.username}';
break;
case TwitterLoginStatus.cancelledByUser:
newMessage = 'Login cancelled by user.';
break;
case TwitterLoginStatus.error:
newMessage = 'Login error: ${result.errorMessage}';
break;
}

setState(() {
_message = newMessage;
});
}

void _logout() async {
await twitterLogin.logOut();

setState(() {
_message = 'Logged out.';
});
}

@override
Widget build(BuildContext context) {
return new MaterialApp(
Expand All @@ -31,28 +60,11 @@ class _MyAppState extends State<MyApp> {
new Text(_message),
new RaisedButton(
child: new Text('Log in'),
onPressed: () async {
final TwitterLoginResult result =
await twitterLogin.authorize();
String newMessage;

switch (result.status) {
case TwitterLoginStatus.loggedIn:
newMessage =
'Logged in! username: ${result.session.username}';
break;
case TwitterLoginStatus.cancelledByUser:
newMessage = 'Login cancelled by user.';
break;
case TwitterLoginStatus.error:
newMessage = 'Login error: ${result.errorMessage}';
break;
}

setState(() {
_message = newMessage;
});
},
onPressed: _login,
),
new RaisedButton(
child: new Text('Log out'),
onPressed: _logout,
),
],
),
Expand Down
14 changes: 8 additions & 6 deletions lib/flutter_twitter_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ class TwitterLogin {
///
/// If the user is not logged in, this returns null.
Future<TwitterSession> get currentSession async {
final Map<String, dynamic> session =
final Map<dynamic, dynamic> session =
await channel.invokeMethod('getCurrentSession', _keys);

if (session == null) {
return null;
}

return new TwitterSession.fromMap(session);
return new TwitterSession.fromMap(session.cast<String, dynamic>());
}

/// Logs the user in.
Expand Down Expand Up @@ -101,14 +101,14 @@ class TwitterLogin {
///
/// See the [TwitterLoginResult] class for more documentation.
Future<TwitterLoginResult> authorize() async {
final Map<String, dynamic> result =
final Map<dynamic, dynamic> result =
await channel.invokeMethod('authorize', _keys);

return new TwitterLoginResult._(result);
return new TwitterLoginResult._(result.cast<String, dynamic>());
}

/// Logs the currently logged in user out.
Future<Null> logOut() async => channel.invokeMethod('logOut', _keys);
Future<void> logOut() async => channel.invokeMethod('logOut', _keys);
}

/// The result when a Twitter login flow has completed.
Expand Down Expand Up @@ -136,7 +136,9 @@ class TwitterLoginResult {
TwitterLoginResult._(Map<String, dynamic> map)
: status = _parseStatus(map['status'], map['errorMessage']),
session = map['session'] != null
? new TwitterSession.fromMap(map['session'])
? new TwitterSession.fromMap(
map['session'].cast<String, dynamic>(),
)
: null,
errorMessage = map['errorMessage'];

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_twitter_login
description: A Flutter plugin for allowing users to authenticate with native Android &amp; iOS Twitter login SDKs.
version: 1.0.1
version: 1.1.0
author: Iiro Krankka <iiro.krankka@gmail.com>
homepage: https://github.com/roughike/flutter_twitter_login

Expand All @@ -18,4 +18,4 @@ flutter:
pluginClass: TwitterLoginPlugin

environment:
sdk: ">=1.8.0 <2.0.0"
sdk: ">=2.0.0-dev.28.0 <3.0.0"
13 changes: 13 additions & 0 deletions test/flutter_twitter_login_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ void main() {
expect(result.status, TwitterLoginStatus.error);
});

test('logout', () async {
setMethodCallResponse(null);

await sut.logOut();

expect(log, [
isMethodCall(
'logOut',
arguments: kTokenAndSecretArguments,
)
]);
});

test('access token equality test', () {
final TwitterSession first = new TwitterSession.fromMap(kSessionMap);
final TwitterSession second = new TwitterSession.fromMap(kSessionMap);
Expand Down

0 comments on commit c7ee951

Please sign in to comment.