0 purchases
splitwise api
SplitWise API for Dart #
A wrapper based on SplitWise
Feel free to open a PR or Issue
Uses OAuth 1
Data Classes Not Included
Based on null-safety
Steps #
Get the consumerKey and consumerSecret from Splitwise Register App
Check the example.dart located in example/example.dart
Project Structure #
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- example
| '-- example.dart
|-- lib
| |-- splitwise_api.dart
| '-- src
| '-- util
| |-- auth
| | '-- splitwise_main.dart
| '-- helper
| '-- TokensHelper.dart
'-- pubspec.yaml
copied to clipboard
Usage
Import the package
dependencies:
splitwise_api: ^2.0.3
copied to clipboard
Import in the file
import 'package:splitwise_api/splitwise_api.dart';
copied to clipboard
Setup SharedPreferences or any other system to save the token and tokenSecret to keep user logged in.
For Example :-
import 'package:shared_preferences/shared_preferences.dart';
class SplitWiseHelper {
saveTokens(TokensHelper tokens) async {
final prefs = await SharedPreferences.getInstance();
prefs.setStringList('tokens',[tokens.token,tokens.tokenSecret]);
}
getTokens() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getString('tokens');
}
}
copied to clipboard
Now Use the Wrapper and save the tokens.
ForExample :-
import 'package:splitwise_api/splitwise_api.dart';
void main() async {
SplitWiseService splitWiseService =
SplitWiseService.initialize(_consumerKey, _consumerSecret);
/// SplitWiseHelper is for saving and retrieving from shared storage
SplitWiseHelper splitWiseHelper = SplitWiseHelper();
if (splitWiseHelper.getTokens() == null) {
var authURL = splitWiseService.validateClient();
print(authURL);
//This Will print the token and also return them save them to Shared Prefs
TokensHelper tokens = await splitWiseService.validateClient(
verifier: 'theTokenYouGetAfterAuthorization');
await splitWiseHelper.saveTokens(tokens);
splitWiseService.validateClient(tokens: tokens);
} else {
splitWiseService.validateClient(
tokens: /* tokens from saved */);
print(await splitWiseService.getCurrentUser());
}
}
copied to clipboard
Hit like if it helped
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.