qiscus_sdk 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 55

qiscus_sdk #

Qiscus Chat SDK plugin for iOS and Android

Getting Started #

This a plugin for qiscus core chat sdk for android and iOS

##Android

  • Only support 1-on-1 chat room currently
  • support local databases
  • support fcm notification, see example folder for how to implement

iOS #

On progresss

0.1.0 #

  • initial release
  • support 1-on-1 chat room
  • support push notification
  • support mqtt event connection
  • support read and delivered event
  • support database local store for messages

example/lib/main.dart

import 'dart:async';
import 'dart:developer' as dev;

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:qiscus_sdk/qiscus_sdk.dart';
import 'package:qiscus_sdk_example/chat_page.dart';
import 'package:qiscus_sdk_example/locator.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  setupLocator().then((bool value) {
    runApp(MyApp());
  });
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  int roomId;
  int unread = 0;
  String username = "";
  QiscusAccount qiscusAccount;

  ///edwin
  //String ACCESS_TOKEN =
  //    "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImM0MjkwZjNmZDNhZDgzZjBmNzFkYTJhZTk4YWVkYzY3Njk3NDViMTFjNmM2Yzg1MzM3NzY1NDdmMWJhOTFjZjFhZDVjNjkyZDkwZjlkM2M5In0.eyJhdWQiOiI1ZDgyMThmMmY0OGMzZDZiOTQ2NDUxNDIiLCJqdGkiOiJjNDI5MGYzZmQzYWQ4M2YwZjcxZGEyYWU5OGFlZGM2NzY5NzQ1YjExYzZjNmM4NTMzNzc2NTQ3ZjFiYTkxY2YxYWQ1YzY5MmQ5MGY5ZDNjOSIsImlhdCI6MTU4NzE5MjM0MiwibmJmIjoxNTg3MTkyMzQyLCJleHAiOjE2MTg3MjgzNDIsInN1YiI6IjVkYTNmN2U2ZjQ4YzNkMTc1NjQ5Mzg4YiIsInNjb3BlcyI6W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lNmJhNjY1ZWNmM2NmZWUzYWEwZTcyM2FiMjJhNzFjNDQ1Y2VmYzUwYjliNDVkM2FlNmVkMjlkMDI2Y2QzODU0MGE4Mzc0MmU0NSIsImlhdCI6MTU4NzM1Njc5MCwibmJmIjoxNTg3MzU2NzkwLCJleHAiOjE2MTg4OTI3OTAsInN1YiI6IjVlMmZjYjM2ZjQ4YzNkMzQzNTdhODI0ZCIsInNjb3BlcyI6WyJmcmVlIl19.DT_SafqSDeHh2K-mryliREgMQZvydCA0J8pASbu9aE3YBpfROpTTWa1LBgw5GnaZctbXXhrW79TUqHBD0TiH2ORneFinaVRNS0rJ_qk9425cLSu9hxvUXZSh7sH_vC0JWHDcnEsYiyvwJPnUsDc7Ju0xK8ByeDmXTLwWP9nRbqO2_-XlBEZOqYMRmerVWXcCxtO8Kg-LGZmZ5JnUYPaNgatdr_PVJVS5txwR8r77zjErZq1609LqjP6Szb4X56WZMbo_hQvzUI_sTWh_Eh4MLbQTDZO_L5SUU_1K2M4_lMUUqPOtqYw9Rm7xXsnv0Sk6ChcjhD4zXdBZ7wSJFcVVvlxmynSqBJl1YQgbdCytV94iTHU9eLCfW-T_UqILAj6BNNfxL3EuDZtJJnbbfU9XT0abnyqg8ncPzFeH0ecOzhIpg0ovsvRSLJxgTa00v2EpvvSE0l7rjmjdpYmP1ZzocrSQr17rMIajI8p0jYGNIX5ajjhDDZY92gvHZ5hm18u1u8D6meLeorK843d808ez_V5Z8hFlkkC0mB_0YKpts1tMoDh9g-Ngs0qTvIEFZVHYt4kUmc_jTZWNX32ikayHmWejRhoa8KkfyYu-B66A2pq_pegR5E89kajJmyifPnCL_BIsFHDT79BCDYbT79n23OA-y9EpyrHfzo4uMQCSmlw";

  @override
  void initState() {
    super.initState();
    init();
  }

  Future<void> init() async {
    try {
      qiscusAccount = await ChatSdk.getQiscusAccount();
      setState(() {
        username = qiscusAccount.username;
      });
    } on Exception catch (e) {
      /// add logic if user hasn't login here
      /// example : loginWithJWT with REST API access token
      print(e.toString());
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Builder(
        builder: (context) => Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: ListView(
            children: [
              Column(
                children: <Widget>[
                  Center(
                    child: Text('User log on: $username\n'),
                  ),
                  RaisedButton(
                    child: Text('Logout'),
                    onPressed: () async {
                      await ChatSdk.clearUser();
                      setState(() {
                        username = '';
                      });
                    },
                  ),
                  RaisedButton(
                    child: Text('Login  Darwin'),
                    onPressed: () async {
                      qiscusAccount = await ChatSdk.login(
                          userId: "darwinwu134", userKey: "dndndn", username: "Darwin 134");
                      print("acc:${qiscusAccount.toJson()}");
                      setState(() {
                        username = qiscusAccount.username;
                      });
                    },
                  ),
                  RaisedButton(
                    child: Text('Login  Edwin'),
                    onPressed: () async {
                      qiscusAccount = await loginWithJwt();
                      print("acc:${qiscusAccount.toJson()}");
                      setState(() {
                        username = qiscusAccount.username;
                      });
                    },
                  ),
                  RaisedButton(
                    child: Text('Update Pret'),
                    onPressed: () async {
                      ChatSdk.updateUser(
                          username: "Mr. Darwin X",
                          avatarUrl:
                              "https://d1edrlpyc25xu0.cloudfront.net/kiwari-prod/image/upload/75r6s_jOHa/1507541871-avatar-mine.png",
                          extras: {'key': "konci bos"});
                    },
                  ),
                  RaisedButton(
                    child: Text('all Users'),
                    onPressed: () async {
                      ChatSdk.getAllUsers(searchUsername: 'darwin');
                    },
                  ),
                  RaisedButton(
                    child: Text('Chat User Chandra'),
                    onPressed: () async {
                      final chatRoom = await ChatSdk.chatUser(userId: '5dba91daf48c3d33bb41a6f5');
                      print("chatRoom Id : ${chatRoom.id}");
                      roomId = chatRoom.id;
                      // if wanna test offline mode remove the comment below
                      //roomId = 11315282;

                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (context) => ChatPage(
                            roomId: roomId,
                            roomName: 'Chandra',
                            senderAccount: qiscusAccount,
                          ),
                        ),
                      );
                    },
                  ),
                  RaisedButton(
                    child: Text('Chat User Edwin'),
                    onPressed: () async {
                      final chatRoom = await ChatSdk.chatUser(
                          userId: '5da3f7e6f48c3d175649388b', extras: {'esss': "assad"});
                      print("chatRoom Id : ${chatRoom.id}");
                      roomId = chatRoom.id;
                      // if wanna test offline mode remove the comment below
                      //roomId = 11315282;

                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (context) => ChatPage(
                            roomId: roomId,
                            roomName: 'Edwin  Fadilah',
                            senderAccount: qiscusAccount,
                          ),
                        ),
                      );
                    },
                  ),
                  RaisedButton(
                    child: Text('Chat User Darwin'),
                    onPressed: () async {
                      final chatRoom = await ChatSdk.chatUser(userId: 'darwinwu134');
                      print("chatRoom Id : ${chatRoom.id}");
                      roomId = chatRoom.id;

                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (context) => ChatPage(
                            roomId: roomId,
                            roomName: 'Darwin wu',
                            senderAccount: qiscusAccount,
                          ),
                        ),
                      );
                    },
                  ),
                  RaisedButton(
                    child: Text('Chat with Messages'),
                    onPressed: () async {
                      final chatRoom = await ChatSdk.getChatRoomWithMessages(roomId);
                      print("chat with messages : $chatRoom");
                    },
                  ),
                  RaisedButton(
                    child: Text('get local chat room'),
                    onPressed: () async {
                      final chatRoom = await ChatSdk.getLocalChatRoom(11315282);
                      print("local chat room : $chatRoom");
                    },
                  ),
                  RaisedButton(
                    child: Text('get local chat room by RoomIds'),
                    onPressed: () async {
                      final chatRoom = await ChatSdk.getLocalChatRoomByIds([11315282]);
                      print("local chat room ids : $chatRoom");
                    },
                  ),
                  RaisedButton(
                    child: Text('get All chat rooms'),
                    onPressed: () async {
                      List<QiscusChatRoom> chatRoom =
                          await ChatSdk.getAllChatRooms(showEmpty: true);
                      dev.log(" all chat room : $chatRoom");
                      dev.log(" all chat room : ${chatRoom[0].lastComment.time.toLocal()}");
                      dev.log(" all chat room : ${DateTime.now().timeZoneOffset}");
                    },
                  ),
                  RaisedButton(
                    child: Text('get Local chat rooms with Limit, offset'),
                    onPressed: () async {
                      List<QiscusChatRoom> chatRoom =
                          await ChatSdk.getLocalChatRooms(limit: 100, offset: 0);
                      dev.log("local all chat room limit offset: $chatRoom");
                    },
                  ),
                  RaisedButton(
                    child: Text('get Local chat rooms with Limit '),
                    onPressed: () async {
                      List<QiscusChatRoom> chatRoom = await ChatSdk.getLocalChatRooms();
                      dev.log("local all chat room  limit: $chatRoom");
                    },
                  ),
                  RaisedButton(
                    child: Text('Refresh unread count '),
                    onPressed: () async {
                      int temp = await ChatSdk.getTotalUnreadCount();

                      setState(() {
                        unread = temp;
                      });
                    },
                  ),
                  Text("uread : $unread"),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

  Future<QiscusAccount> loginWithJwt() {
    return ChatSdk.loginWithJWT((String nonce) async {
      Dio dio = Dio();
      BaseOptions baseOptions = new BaseOptions();
      Map<String, dynamic> headerJson = {
        'Authorization': "Bearer $ACCESS_TOKEN",
        'Content-Type': 'application/json',
        'Accept': 'application/json',
      };
      baseOptions.connectTimeout = 30000;
      baseOptions.receiveTimeout = 30000;
      baseOptions.headers = headerJson;
      dio.options = baseOptions;
      print("before dio");
      var response = await dio.get(
        "https://dev2.myislami.com/api/v1/consultation/chats/jwt",
        queryParameters: {'nonce': nonce},
      );
      String jwt = response.data['result']['jwt'];

      print("nonce: $nonce, jwt: $jwt");

      return jwt;
    });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  qiscus_sdk: ^0.1.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:qiscus_sdk/qiscus_sdk.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
21
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
72
Overall:
Weighted score of the above. [more]
55
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform ios

Because:

  • package:qiscus_sdk/qiscus_sdk.dart that declares support for platforms: android

Package does not support Flutter platform linux

Because:

  • package:qiscus_sdk/qiscus_sdk.dart that declares support for platforms: android

Package does not support Flutter platform macos

Because:

  • package:qiscus_sdk/qiscus_sdk.dart that declares support for platforms: android

Package does not support Flutter platform web

Because:

  • package:qiscus_sdk/qiscus_sdk.dart that declares support for platforms: android

Package does not support Flutter platform windows

Because:

  • package:qiscus_sdk/qiscus_sdk.dart that declares support for platforms: android

Package not compatible with SDK dart

Because:

  • qiscus_sdk that is a package requiring null.

Health suggestions

Fix lib/src/chat_sdk.dart. (-1.49 points)

Analysis of lib/src/chat_sdk.dart reported 3 hints:

line 273 col 23: This function has a return type of 'Future

line 273 col 23: The declaration '_setNotificationListener' isn't referenced.

line 654 col 23: This function has a return type of 'Future

Format lib/src/model/qiscus_account.dart.

Run flutter format to format lib/src/model/qiscus_account.dart.

Format lib/src/model/qiscus_chat_room.dart.

Run flutter format to format lib/src/model/qiscus_chat_room.dart.

Format lib/src/model/qiscus_comment.dart.

Run flutter format to format lib/src/model/qiscus_comment.dart.

Format lib/src/model/qiscus_room_member.dart.

Run flutter format to format lib/src/model/qiscus_room_member.dart.

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 (rxdart).

The package description is too short. (-18 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
data_connection_checker ^0.3.4 0.3.4
equatable ^1.1.1 1.2.2
flutter 0.0.0
json_annotation ^3.0.1 3.0.1
rxdart ^0.23.1 0.23.1 0.24.1
tuple ^1.0.3 1.0.3
uuid ^2.0.4 2.2.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
crypto 2.1.5
matcher 0.12.8
meta 1.1.8 1.2.2
path 1.7.0
quiver 2.1.3
sky_engine 0.0.99
stack_trace 1.9.5
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
build_runner ^1.8.0
flutter_test
json_serializable ^3.2.5