Merge branch 'better-notifications' into 'master'

Better notifications

See merge request ChristianPauly/fluffychat-flutter!14
This commit is contained in:
Christian Pauly 2020-01-08 13:19:16 +00:00
commit 5e3ad1c5d7
14 changed files with 296 additions and 25 deletions

View File

@ -6,6 +6,9 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="FluffyChat"

View File

@ -0,0 +1,28 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="80.21739"
android:viewportHeight="80.21739"
android:tint="#FFFFFF">
<group android:translateX="3.2086957"
android:translateY="3.2086957">
<path
android:pathData="M60.9,38.5c0.6,-0.1 1.1,-0.4 1.5,-0.8c1.6,-2.1 0.3,-4.7 -1.8,-5c-0.3,0 -0.6,-0.3 -0.6,-0.6c0,-0.1 0,-0.2 0,-0.2c0.3,-0.3 0.6,-0.7 1,-1.3c3.2,-4.3 4.7,-20.1 1.5,-21.3c-3.9,-1.3 -11.8,2.5 -15.2,6.9c-0.2,-0.1 -0.4,-0.4 -0.4,-0.7c0.1,-1.2 -0.5,-2.2 -1.4,-2.7c-1.8,-0.9 -3.5,0 -4.2,1.3c-0.2,0.3 -0.5,0.5 -0.8,0.4c-0.3,0 -0.6,-0.3 -0.6,-0.6c-0.2,-1 -0.8,-1.8 -1.7,-2.2c-1.9,-0.8 -3.9,0.3 -4.2,2.1c-0.1,0.3 -0.3,0.6 -0.6,0.6c-0.3,0.1 -0.6,-0.1 -0.8,-0.4C32,13.1 31,12.5 30,12.5c-1.6,0 -3,1.3 -3.1,2.9c0,0 0,0.1 0,0.1l0,0.1c0,0.3 -0.2,0.6 -0.4,0.7c0,0 -0.1,0 -0.1,0C23.1,12 15.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.1 1.9,-0.2c0.9,-0.4 1.5,-1.2 1.7,-2.2c0.2,-1 -0.1,-1.9 -0.8,-2.6c-0.2,-0.2 -0.3,-0.5 -0.2,-0.8c0.1,-0.3 0.4,-0.5 0.7,-0.5c0.7,0 1.5,-0.2 2,-0.8c1.7,-1.8 0.9,-4.2 -1,-5c-0.3,-0.1 -0.5,-0.4 -0.5,-0.8C60.3,38.8 60.6,38.5 60.9,38.5z"
android:fillColor="#4C3D91"/>
<path
android:pathData="M52.9,17.5c0.2,0.6 0.2,1.2 0,1.8c-0.1,0.3 0,0.6 0.2,0.8c0.2,0.2 0.5,0.3 0.8,0.2c0.4,-0.2 0.8,-0.2 1.2,-0.2c0.9,0 1.7,0.4 2.3,1.2c0.4,0.5 0.7,1.2 0.6,1.9c0,0.6 -0.2,1.1 -0.5,1.6c-0.2,0.2 -0.2,0.6 0,0.8c0.1,0.1 0.2,0.3 0.4,0.3c0.4,-0.1 0.8,-0.4 1.1,-0.8c1.8,-2.5 2.1,-10.4 0.3,-11c-1.8,-0.6 -4.9,0.6 -7.1,2.4C52.6,16.7 52.8,17 52.9,17.5z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M16.2,26c0.1,-0.1 0.2,-0.2 0.3,-0.3c0.2,-0.3 0.1,-0.6 0,-0.8c-0.5,-0.7 -0.6,-1.5 -0.5,-2.3c0.2,-1.1 1.1,-2 2.2,-2.3c0.6,-0.2 1.2,-0.1 1.8,0.1c0.3,0.1 0.6,0 0.8,-0.2c0.2,-0.2 0.3,-0.5 0.2,-0.8c-0.2,-0.6 -0.2,-1.2 0,-1.8c0.1,-0.4 0.3,-0.8 0.6,-1.1c-2.2,-1.8 -5.5,-3.1 -7.3,-2.5c-1.8,0.6 -1.5,8.5 0.3,11C15,25.6 15.5,25.9 16.2,26z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M24.9,38.3m-3.7,0a3.7,3.7 0,1 1,7.4 0a3.7,3.7 0,1 1,-7.4 0"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M40.7,38.3c0,2.1 -1.7,3.7 -3.7,3.7c-2.1,0 -3.7,-1.7 -3.7,-3.7S40.7,36.2 40.7,38.3z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M49,38.3m-3.7,0a3.7,3.7 0,1 1,7.4 0a3.7,3.7 0,1 1,-7.4 0"
android:fillColor="#FFFFFF"/>
</group>
</vector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 B

View File

@ -0,0 +1,28 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="80.21739"
android:viewportHeight="80.21739"
android:tint="#FFFFFF">
<group android:translateX="3.2086957"
android:translateY="3.2086957">
<path
android:pathData="M60.9,38.5c0.6,-0.1 1.1,-0.4 1.5,-0.8c1.6,-2.1 0.3,-4.7 -1.8,-5c-0.3,0 -0.6,-0.3 -0.6,-0.6c0,-0.1 0,-0.2 0,-0.2c0.3,-0.3 0.6,-0.7 1,-1.3c3.2,-4.3 4.7,-20.1 1.5,-21.3c-3.9,-1.3 -11.8,2.5 -15.2,6.9c-0.2,-0.1 -0.4,-0.4 -0.4,-0.7c0.1,-1.2 -0.5,-2.2 -1.4,-2.7c-1.8,-0.9 -3.5,0 -4.2,1.3c-0.2,0.3 -0.5,0.5 -0.8,0.4c-0.3,0 -0.6,-0.3 -0.6,-0.6c-0.2,-1 -0.8,-1.8 -1.7,-2.2c-1.9,-0.8 -3.9,0.3 -4.2,2.1c-0.1,0.3 -0.3,0.6 -0.6,0.6c-0.3,0.1 -0.6,-0.1 -0.8,-0.4C32,13.1 31,12.5 30,12.5c-1.6,0 -3,1.3 -3.1,2.9c0,0 0,0.1 0,0.1l0,0.1c0,0.3 -0.2,0.6 -0.4,0.7c0,0 -0.1,0 -0.1,0C23.1,12 15.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.1 1.9,-0.2c0.9,-0.4 1.5,-1.2 1.7,-2.2c0.2,-1 -0.1,-1.9 -0.8,-2.6c-0.2,-0.2 -0.3,-0.5 -0.2,-0.8c0.1,-0.3 0.4,-0.5 0.7,-0.5c0.7,0 1.5,-0.2 2,-0.8c1.7,-1.8 0.9,-4.2 -1,-5c-0.3,-0.1 -0.5,-0.4 -0.5,-0.8C60.3,38.8 60.6,38.5 60.9,38.5z"
android:fillColor="#4C3D91"/>
<path
android:pathData="M52.9,17.5c0.2,0.6 0.2,1.2 0,1.8c-0.1,0.3 0,0.6 0.2,0.8c0.2,0.2 0.5,0.3 0.8,0.2c0.4,-0.2 0.8,-0.2 1.2,-0.2c0.9,0 1.7,0.4 2.3,1.2c0.4,0.5 0.7,1.2 0.6,1.9c0,0.6 -0.2,1.1 -0.5,1.6c-0.2,0.2 -0.2,0.6 0,0.8c0.1,0.1 0.2,0.3 0.4,0.3c0.4,-0.1 0.8,-0.4 1.1,-0.8c1.8,-2.5 2.1,-10.4 0.3,-11c-1.8,-0.6 -4.9,0.6 -7.1,2.4C52.6,16.7 52.8,17 52.9,17.5z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M16.2,26c0.1,-0.1 0.2,-0.2 0.3,-0.3c0.2,-0.3 0.1,-0.6 0,-0.8c-0.5,-0.7 -0.6,-1.5 -0.5,-2.3c0.2,-1.1 1.1,-2 2.2,-2.3c0.6,-0.2 1.2,-0.1 1.8,0.1c0.3,0.1 0.6,0 0.8,-0.2c0.2,-0.2 0.3,-0.5 0.2,-0.8c-0.2,-0.6 -0.2,-1.2 0,-1.8c0.1,-0.4 0.3,-0.8 0.6,-1.1c-2.2,-1.8 -5.5,-3.1 -7.3,-2.5c-1.8,0.6 -1.5,8.5 0.3,11C15,25.6 15.5,25.9 16.2,26z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M24.9,38.3m-3.7,0a3.7,3.7 0,1 1,7.4 0a3.7,3.7 0,1 1,-7.4 0"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M40.7,38.3c0,2.1 -1.7,3.7 -3.7,3.7c-2.1,0 -3.7,-1.7 -3.7,-3.7S40.7,36.2 40.7,38.3z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M49,38.3m-3.7,0a3.7,3.7 0,1 1,7.4 0a3.7,3.7 0,1 1,-7.4 0"
android:fillColor="#FFFFFF"/>
</group>
</vector>

View File

@ -3,10 +3,14 @@ import 'dart:convert';
import 'dart:io';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/utils/sqflite_store.dart';
import 'package:fluffychat/views/chat.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:localstorage/localstorage.dart';
import 'package:path_provider/path_provider.dart';
import 'package:toast/toast.dart';
class Matrix extends StatefulWidget {
@ -35,6 +39,10 @@ class MatrixState extends State<Matrix> {
BuildContext context;
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
String activeRoomId;
/// Used to load the old account if there is no store available.
void loadAccount() async {
@ -129,10 +137,28 @@ class MatrixState extends State<Matrix> {
hideLoadingDialog() => Navigator.of(_loadingDialogContext)?.pop();
StreamSubscription onSetupFirebase;
Future<String> downloadAndSaveContent(MxContent content,
{int width, int height, ThumbnailMethod method}) async {
final bool thumbnail = width == null && height == null ? false : true;
final String tempDirectory = (await getTemporaryDirectory()).path;
final String prefix = thumbnail ? "thumbnail" : "";
File file = File('$tempDirectory/${prefix}_${content.mxc.split("/").last}');
void setupFirebase(LoginState login) async {
if (login != LoginState.logged) return;
if (!file.existsSync()) {
final url = thumbnail
? content.getThumbnail(client,
width: width, height: height, method: method)
: content.getDownloadLink(client);
var request = await HttpClient().getUrl(Uri.parse(url));
var response = await request.close();
var bytes = await consolidateHttpClientResponseBytes(response);
await file.writeAsBytes(bytes);
}
return file.path;
}
Future<void> setupFirebase() async {
if (Platform.isIOS) iOS_Permission();
final String token = await _firebaseMessaging.getToken();
@ -155,14 +181,157 @@ class MatrixState extends State<Matrix> {
format: "event_id_only",
);
Function goToRoom = (dynamic message) async {
try {
String roomId;
if (message is String) {
roomId = message;
} else if (message is Map) {
roomId = message["data"]["room_id"];
}
if (roomId?.isEmpty ?? true) throw ("Bad roomId");
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
Chat(roomId),
),
(r) => r.isFirst);
} catch (_) {
Toast.show("Failed to open chat...", context);
print(_);
}
};
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
var initializationSettingsAndroid =
AndroidInitializationSettings('notifications_icon');
var initializationSettingsIOS =
IOSInitializationSettings(onDidReceiveLocalNotification: (i, a, b, c) {
print("onDidReceiveLocalNotification: $i $a $b $c");
return null;
});
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
await _flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: goToRoom);
_firebaseMessaging.configure(
onResume: (Map<String, dynamic> message) async {
print('on resume $message');
},
onLaunch: (Map<String, dynamic> message) async {
print('on launch $message');
onMessage: (Map<String, dynamic> message) async {
try {
final String roomId = message["data"]["room_id"];
final String eventId = message["data"]["event_id"];
final int unread = json.decode(message["data"]["counts"])["unread"];
if ((roomId?.isEmpty ?? true) ||
(eventId?.isEmpty ?? true) ||
unread == 0) {
await _flutterLocalNotificationsPlugin.cancelAll();
return null;
}
if (activeRoomId == roomId) return null;
// Get the room
Room room = client.getRoomById(roomId);
if (room == null) {
await client.onRoomUpdate.stream
.where((u) => u.id == roomId)
.first
.timeout(Duration(seconds: 10));
room = client.getRoomById(roomId);
if (room == null) return null;
}
// Get the event
Event event = await client.store.getEventById(eventId, room);
if (event == null) {
final EventUpdate eventUpdate = await client.onEvent.stream
.where((u) => u.content["event_id"] == eventId)
.first
.timeout(Duration(seconds: 10));
event = Event.fromJson(eventUpdate.content, room);
if (room == null) return null;
}
// Count all unread events
int unreadEvents = 0;
client.rooms
.forEach((Room room) => unreadEvents += room.notificationCount);
// Calculate title
final String title = unread > 1
? "$unreadEvents unread messages in $unread chats"
: "$unreadEvents unread messages";
// Calculate the body
String body;
switch (event.messageType) {
case MessageTypes.Image:
body = "${event.sender.calcDisplayname()} sent a picture";
break;
case MessageTypes.File:
body = "${event.sender.calcDisplayname()} sent a file";
break;
case MessageTypes.Audio:
body = "${event.sender.calcDisplayname()} sent an audio";
break;
case MessageTypes.Video:
body = "${event.sender.calcDisplayname()} sent a video";
break;
default:
body = "${event.sender.calcDisplayname()}: ${event.getBody()}";
break;
}
// The person object for the android message style notification
final person = Person(
name: room.displayname,
icon: room.avatar.mxc.isEmpty
? null
: await downloadAndSaveContent(
room.avatar,
width: 126,
height: 126,
),
iconSource: IconSource.FilePath,
);
// Show notification
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'fluffychat_push',
'FluffyChat push channel',
'Push notifications for FluffyChat',
style: AndroidNotificationStyle.Messaging,
styleInformation: MessagingStyleInformation(
person,
conversationTitle: title,
messages: [
Message(
body,
event.time,
person,
)
],
),
importance: Importance.Max,
priority: Priority.High,
ticker: 'New message in FluffyChat');
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await _flutterLocalNotificationsPlugin.show(
0, room.displayname, body, platformChannelSpecifics,
payload: roomId);
} catch (exception) {
print("[Push] Error while processing notification: " +
exception.toString());
}
return null;
},
onResume: goToRoom,
// Currently fires unexpectetly... https://github.com/FirebaseExtended/flutterfire/issues/1060
//onLaunch: goToRoom,
);
print("[Push] Firebase initialized");
return;
}
void iOS_Permission() {
@ -174,25 +343,31 @@ class MatrixState extends State<Matrix> {
});
}
void _initWithStore() async {
Future<LoginState> initLoginState = client.onLoginStateChanged.stream.first;
client.store = Store(client);
if (await initLoginState == LoginState.logged) {
await setupFirebase();
}
}
@override
void initState() {
if (widget.client == null) {
client = Client(widget.clientName, debug: false);
if (!kIsWeb) {
client.store = Store(client);
_initWithStore();
} else {
loadAccount();
}
} else {
client = widget.client;
}
onSetupFirebase ??= client.onLoginStateChanged.stream.listen(setupFirebase);
super.initState();
}
@override
void dispose() {
onSetupFirebase?.cancel();
super.dispose();
}

View File

@ -47,8 +47,8 @@ class App extends StatelessWidget {
),
),
home: Builder(
builder: (BuildContext context) => StreamBuilder<LoginState>(
stream: Matrix.of(context).client.onLoginStateChanged.stream,
builder: (BuildContext context) => FutureBuilder<LoginState>(
future: Matrix.of(context).client.onLoginStateChanged.stream.first,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Scaffold(

View File

@ -27,6 +27,8 @@ class _ChatState extends State<Chat> {
Timeline timeline;
MatrixState matrix;
String seenByText = "";
final ScrollController _scrollController = ScrollController();
@ -81,6 +83,7 @@ class _ChatState extends State<Chat> {
@override
void dispose() {
timeline?.sub?.cancel();
matrix.activeRoomId = "";
super.dispose();
}
@ -98,7 +101,7 @@ class _ChatState extends State<Chat> {
}
File file = await FilePicker.getFile();
if (file == null) return;
await Matrix.of(context).tryRequestWithLoadingDialog(
await matrix.tryRequestWithLoadingDialog(
room.sendFileEvent(
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
),
@ -115,7 +118,7 @@ class _ChatState extends State<Chat> {
maxWidth: 1600,
maxHeight: 1600);
if (file == null) return;
await Matrix.of(context).tryRequestWithLoadingDialog(
await matrix.tryRequestWithLoadingDialog(
room.sendImageEvent(
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
),
@ -132,7 +135,7 @@ class _ChatState extends State<Chat> {
maxWidth: 1600,
maxHeight: 1600);
if (file == null) return;
await Matrix.of(context).tryRequestWithLoadingDialog(
await matrix.tryRequestWithLoadingDialog(
room.sendImageEvent(
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
),
@ -141,16 +144,18 @@ class _ChatState extends State<Chat> {
@override
Widget build(BuildContext context) {
Client client = Matrix.of(context).client;
matrix = Matrix.of(context);
Client client = matrix.client;
room ??= client.getRoomById(widget.id);
if (room == null) {
return Center(
child: Text("You are no longer participating in this chat"),
);
}
matrix.activeRoomId = widget.id;
if (room.membership == Membership.invite) {
Matrix.of(context).tryRequestWithLoadingDialog(room.join());
matrix.tryRequestWithLoadingDialog(room.join());
}
String typingText = "";

View File

@ -2,8 +2,11 @@ import 'dart:math';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:flutter/material.dart';
import 'chat_list.dart';
const String defaultHomeserver = "https://matrix.org";
class LoginPage extends StatefulWidget {
@ -47,6 +50,7 @@ class _LoginPageState extends State<LoginPage> {
}
try {
print("[Login] Check server...");
setState(() => loading = true);
if (!await matrix.client.checkServer(homeserver)) {
setState(() => serverError = "Homeserver is not compatible.");
@ -58,6 +62,7 @@ class _LoginPageState extends State<LoginPage> {
return setState(() => loading = false);
}
try {
print("[Login] Try to login...");
await matrix.client
.login(usernameController.text, passwordController.text);
} on MatrixException catch (exception) {
@ -67,8 +72,21 @@ class _LoginPageState extends State<LoginPage> {
setState(() => passwordError = exception.toString());
return setState(() => loading = false);
}
try {
print("[Login] Setup Firebase...");
await matrix.setupFirebase();
} catch (exception) {
print("[Login] Failed to setup Firebase. Logout now...");
await matrix.client.logout();
matrix.clean();
setState(() => passwordError = exception.toString());
return setState(() => loading = false);
}
print("[Login] Store account and go to ChatListView");
await Matrix.of(context).saveAccount();
setState(() => loading = false);
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(context, ChatListView()), (r) => false);
}
@override

View File

@ -4,7 +4,9 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/content_banner.dart';
import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat_list.dart';
import 'package:fluffychat/views/login.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
@ -31,10 +33,11 @@ class _SettingsState extends State<Settings> {
Future<dynamic> profileFuture;
dynamic profile;
void logoutAction(BuildContext context) async {
await Navigator.of(context).popUntil((r) => r.isFirst);
MatrixState matrix = Matrix.of(context);
await matrix.tryRequestWithErrorToast(matrix.client.logout());
await matrix.tryRequestWithLoadingDialog(matrix.client.logout());
matrix.clean();
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(context, LoginPage()), (r) => false);
}
void setDisplaynameAction(BuildContext context, String displayname) async {
@ -94,7 +97,9 @@ class _SettingsState extends State<Settings> {
Widget build(BuildContext context) {
final Client client = Matrix.of(context).client;
profileFuture ??= client.getProfileFromUserId(client.userID);
profileFuture.then((p) => setState(() => profile = p));
profileFuture.then((p) {
if (mounted) setState(() => profile = p);
});
return Scaffold(
appBar: AppBar(
title: Text("Settings"),

View File

@ -82,8 +82,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "45744331ead079443e0dcb280a86867af2e21ccf"
resolved-ref: "45744331ead079443e0dcb280a86867af2e21ccf"
ref: "5a3f88e979fc85cb876dbfecffd8230c9698f864"
resolved-ref: "5a3f88e979fc85cb876dbfecffd8230c9698f864"
url: "https://gitlab.com/famedly/famedlysdk.git"
source: git
version: "0.0.1"
@ -120,6 +120,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.4"
flutter_local_notifications:
dependency: "direct main"
description:
name: flutter_local_notifications
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.1+2"
flutter_speed_dial:
dependency: "direct main"
description:
@ -215,7 +222,7 @@ packages:
source: hosted
version: "1.6.4"
path_provider:
dependency: transitive
dependency: "direct main"
description:
name: path_provider
url: "https://pub.dartlang.org"

View File

@ -27,7 +27,7 @@ dependencies:
famedlysdk:
git:
url: https://gitlab.com/famedly/famedlysdk.git
ref: 45744331ead079443e0dcb280a86867af2e21ccf
ref: 5a3f88e979fc85cb876dbfecffd8230c9698f864
localstorage: ^3.0.1+4
bubble: ^1.1.9+1
@ -39,7 +39,9 @@ dependencies:
sqflite: ^1.2.0
cached_network_image: ^2.0.0
firebase_messaging: ^6.0.9
flutter_local_notifications: ^0.9.1+2
link_text: ^0.1.1
path_provider: ^1.5.1
dev_dependencies:
flutter_test: