diff --git a/analysis_options.yaml b/analysis_options.yaml index e38e74c..7090ee1 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -2,7 +2,7 @@ include: package:pedantic/analysis_options.yaml linter: rules: - # - camel_case_types + - camel_case_types analyzer: errors: diff --git a/lib/components/adaptive_page_layout.dart b/lib/components/adaptive_page_layout.dart index 70c4064..5802528 100644 --- a/lib/components/adaptive_page_layout.dart +++ b/lib/components/adaptive_page_layout.dart @@ -23,11 +23,13 @@ class AdaptivePageLayout extends StatelessWidget { @override Widget build(BuildContext context) { return OrientationBuilder(builder: (context, orientation) { - if (orientation == Orientation.portrait || - columnMode(context)) if (primaryPage == FocusPage.FIRST) - return firstScaffold; - else - return secondScaffold; + if (orientation == Orientation.portrait || columnMode(context)) { + if (primaryPage == FocusPage.FIRST) { + return firstScaffold; + } else { + return secondScaffold; + } + } return Row( children: [ Container( diff --git a/lib/components/chat_settings_popup_menu.dart b/lib/components/chat_settings_popup_menu.dart index 6b6cd4d..a53e3d9 100644 --- a/lib/components/chat_settings_popup_menu.dart +++ b/lib/components/chat_settings_popup_menu.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:famedlysdk/famedlysdk.dart'; import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/views/chat_details.dart'; @@ -6,16 +8,37 @@ import 'package:flutter/material.dart'; import 'matrix.dart'; -class ChatSettingsPopupMenu extends StatelessWidget { +class ChatSettingsPopupMenu extends StatefulWidget { final Room room; final bool displayChatDetails; const ChatSettingsPopupMenu(this.room, this.displayChatDetails, {Key key}) : super(key: key); + @override + _ChatSettingsPopupMenuState createState() => _ChatSettingsPopupMenuState(); +} + +class _ChatSettingsPopupMenuState extends State { + StreamSubscription notificationChangeSub; + + @override + void dispose() { + notificationChangeSub?.cancel(); + super.dispose(); + } + @override Widget build(BuildContext context) { + notificationChangeSub ??= Matrix.of(context) + .client + .onUserEvent + .stream + .where((u) => u.type == 'account_data' && u.eventType == "m.push_rules") + .listen( + (u) => setState(() => null), + ); List> items = >[ - room.pushRuleState == PushRuleState.notify + widget.room.pushRuleState == PushRuleState.notify ? const PopupMenuItem( value: "mute", child: Text('Mute chat'), @@ -29,7 +52,7 @@ class ChatSettingsPopupMenu extends StatelessWidget { child: Text('Leave'), ), ]; - if (displayChatDetails) + if (widget.displayChatDetails) { items.insert( 0, const PopupMenuItem( @@ -37,28 +60,30 @@ class ChatSettingsPopupMenu extends StatelessWidget { child: Text('Chat details'), ), ); + } return PopupMenuButton( onSelected: (String choice) async { switch (choice) { case "leave": - await Matrix.of(context).tryRequestWithLoadingDialog(room.leave()); - Navigator.of(context).pushAndRemoveUntil( + await Matrix.of(context) + .tryRequestWithLoadingDialog(widget.room.leave()); + await Navigator.of(context).pushAndRemoveUntil( AppRoute.defaultRoute(context, ChatListView()), (Route r) => false); break; case "mute": await Matrix.of(context).tryRequestWithLoadingDialog( - room.setPushRuleState(PushRuleState.mentions_only)); + widget.room.setPushRuleState(PushRuleState.mentions_only)); break; case "unmute": await Matrix.of(context).tryRequestWithLoadingDialog( - room.setPushRuleState(PushRuleState.notify)); + widget.room.setPushRuleState(PushRuleState.notify)); break; case "details": - Navigator.of(context).push( + await Navigator.of(context).push( AppRoute.defaultRoute( context, - ChatDetails(room), + ChatDetails(widget.room), ), ); break; diff --git a/lib/components/dialogs/new_group_dialog.dart b/lib/components/dialogs/new_group_dialog.dart index 87059de..5299e69 100644 --- a/lib/components/dialogs/new_group_dialog.dart +++ b/lib/components/dialogs/new_group_dialog.dart @@ -14,11 +14,12 @@ class NewGroupDialog extends StatelessWidget { matrix.client.createRoom(params: params), ); Navigator.of(context).pop(); - if (roomID != null) - Navigator.push( + if (roomID != null) { + await Navigator.push( context, MaterialPageRoute(builder: (context) => Chat(roomID)), ); + } } @override diff --git a/lib/components/dialogs/new_private_chat_dialog.dart b/lib/components/dialogs/new_private_chat_dialog.dart index 977ffda..34765d1 100644 --- a/lib/components/dialogs/new_private_chat_dialog.dart +++ b/lib/components/dialogs/new_private_chat_dialog.dart @@ -18,11 +18,12 @@ class NewPrivateChatDialog extends StatelessWidget { await matrix.tryRequestWithLoadingDialog(user.startDirectChat()); Navigator.of(context).pop(); - if (roomID != null) - Navigator.push( + if (roomID != null) { + await Navigator.push( context, MaterialPageRoute(builder: (context) => Chat(roomID)), ); + } } @override diff --git a/lib/components/list_items/chat_list_item.dart b/lib/components/list_items/chat_list_item.dart index 960a5a1..12d9111 100644 --- a/lib/components/list_items/chat_list_item.dart +++ b/lib/components/list_items/chat_list_item.dart @@ -22,16 +22,17 @@ class ChatListItem extends StatelessWidget { title: Text(room.displayname), subtitle: MessageContent(room.lastEvent, textOnly: true), onTap: () { - if (activeChat) + if (activeChat) { Navigator.pushReplacement( context, AppRoute.defaultRoute(context, Chat(room.id)), ); - else + } else { Navigator.push( context, AppRoute.defaultRoute(context, Chat(room.id)), ); + } }, onLongPress: () {}, trailing: Container( diff --git a/lib/components/list_items/message.dart b/lib/components/list_items/message.dart index 453e078..cf87515 100644 --- a/lib/components/list_items/message.dart +++ b/lib/components/list_items/message.dart @@ -31,13 +31,14 @@ class Message extends StatelessWidget { color = event.status == -1 ? Colors.redAccent : Color(0xFF5625BA); } List> popupMenuList = []; - if (event.canRedact && !event.redacted && event.status > 1) + if (event.canRedact && !event.redacted && event.status > 1) { popupMenuList.add( const PopupMenuItem( value: "remove", child: Text('Remove message'), ), ); + } if (ownMessage && event.status == -1) { popupMenuList.add( const PopupMenuItem( @@ -59,16 +60,16 @@ class Message extends StatelessWidget { onSelected: (String choice) async { switch (choice) { case "remove": - showDialog( + await showDialog( context: context, builder: (BuildContext context) => RedactMessageDialog(event), ); break; case "resend": - event.sendAgain(); + await event.sendAgain(); break; case "delete": - event.remove(); + await event.remove(); break; } }, @@ -113,10 +114,11 @@ class Message extends StatelessWidget { ), ), ]; - if (ownMessage) + if (ownMessage) { rowChildren.add(Avatar(event.sender.avatarUrl)); - else + } else { rowChildren.insert(0, Avatar(event.sender.avatarUrl)); + } return Padding( padding: const EdgeInsets.all(8.0), child: Row( diff --git a/lib/components/list_items/participant_list_item.dart b/lib/components/list_items/participant_list_item.dart index 692e34d..cf614a7 100644 --- a/lib/components/list_items/participant_list_item.dart +++ b/lib/components/list_items/participant_list_item.dart @@ -15,23 +15,23 @@ class ParticipantListItem extends StatelessWidget { final MatrixState matrix = Matrix.of(context); switch (action) { case "ban": - matrix.tryRequestWithLoadingDialog(user.ban()); + await matrix.tryRequestWithLoadingDialog(user.ban()); break; case "unban": - matrix.tryRequestWithLoadingDialog(user.unban()); + await matrix.tryRequestWithLoadingDialog(user.unban()); break; case "kick": - matrix.tryRequestWithLoadingDialog(user.kick()); + await matrix.tryRequestWithLoadingDialog(user.kick()); break; case "admin": - matrix.tryRequestWithLoadingDialog(user.setPower(100)); + await matrix.tryRequestWithLoadingDialog(user.setPower(100)); break; case "user": - matrix.tryRequestWithLoadingDialog(user.setPower(100)); + await matrix.tryRequestWithLoadingDialog(user.setPower(100)); break; case "message": final String roomId = await user.startDirectChat(); - Navigator.of(context).pushAndRemoveUntil( + await Navigator.of(context).pushAndRemoveUntil( AppRoute.defaultRoute( context, Chat(roomId), @@ -55,30 +55,35 @@ class ParticipantListItem extends StatelessWidget { List> items = >[]; if (user.canChangePowerLevel && user.room.ownPowerLevel == 100 && - user.powerLevel != 100) + user.powerLevel != 100) { items.add( PopupMenuItem(child: Text("Make an admin"), value: "admin"), ); - if (user.canChangePowerLevel && user.powerLevel != 0) + } + if (user.canChangePowerLevel && user.powerLevel != 0) { items.add( PopupMenuItem(child: Text("Revoke all permissions"), value: "user"), ); - if (user.canKick) + } + if (user.canKick) { items.add( PopupMenuItem(child: Text("Kick from group"), value: "kick"), ); - if (user.canBan && user.membership != Membership.ban) + } + if (user.canBan && user.membership != Membership.ban) { items.add( PopupMenuItem(child: Text("Ban from group"), value: "ban"), ); - else if (user.canBan && user.membership == Membership.ban) + } else if (user.canBan && user.membership == Membership.ban) { items.add( PopupMenuItem(child: Text("Remove exile"), value: "unban"), ); - if (user.id != Matrix.of(context).client.userID) + } + if (user.id != Matrix.of(context).client.userID) { items.add( PopupMenuItem(child: Text("Send a message"), value: "message"), ); + } return PopupMenuButton( onSelected: (action) => participantAction(context, action), itemBuilder: (c) => items, diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index 0477792..5d5b225 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -80,7 +80,7 @@ class MatrixState extends State { final LocalStorage storage = LocalStorage('LocalStorage'); await storage.ready; - storage.deleteItem(widget.clientName); + await storage.deleteItem(widget.clientName); } BuildContext _loadingDialogContext; @@ -128,10 +128,11 @@ class MatrixState extends State { void initState() { if (widget.client == null) { client = Client(widget.clientName, debug: false); - if (!kIsWeb) + if (!kIsWeb) { client.store = Store(client); - else + } else { loadAccount(); + } } else { client = widget.client; } diff --git a/lib/components/message_content.dart b/lib/components/message_content.dart index 2769293..e723a23 100644 --- a/lib/components/message_content.dart +++ b/lib/components/message_content.dart @@ -14,7 +14,7 @@ class MessageContent extends StatelessWidget { @override Widget build(BuildContext context) { final int maxLines = textOnly ? 1 : null; - if (textOnly) + if (textOnly) { return Text( event.getBody(), style: TextStyle( @@ -23,6 +23,7 @@ class MessageContent extends StatelessWidget { ), maxLines: maxLines, ); + } switch (event.type) { case EventTypes.Audio: case EventTypes.Image: diff --git a/lib/main.dart b/lib/main.dart index 1daa2e4..f8133b7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,13 +1,19 @@ import 'package:famedlysdk/famedlysdk.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'components/matrix.dart'; import 'views/chat_list.dart'; import 'views/login.dart'; -void main() => runApp(MyApp()); +void main() { + SystemChrome.setSystemUIOverlayStyle( + SystemUiOverlayStyle(statusBarColor: Colors.white), + ); + runApp(App()); +} -class MyApp extends StatelessWidget { +class App extends StatelessWidget { @override Widget build(BuildContext context) { return Matrix( @@ -41,12 +47,13 @@ class MyApp extends StatelessWidget { builder: (BuildContext context) => StreamBuilder( stream: Matrix.of(context).client.onLoginStateChanged.stream, builder: (context, snapshot) { - if (!snapshot.hasData) + if (!snapshot.hasData) { return Scaffold( body: Center( child: CircularProgressIndicator(), ), ); + } if (Matrix.of(context).client.isLogged()) return ChatListView(); return LoginPage(); }, diff --git a/lib/utils/sqflite_store.dart b/lib/utils/sqflite_store.dart index bd7af53..b92ac53 100644 --- a/lib/utils/sqflite_store.dart +++ b/lib/utils/sqflite_store.dart @@ -53,9 +53,10 @@ class Store extends StoreAPI { onCreate: (Database db, int version) async { await createTables(db); }, onUpgrade: (Database db, int oldVersion, int newVersion) async { - if (client.debug) + if (client.debug) { print( "[Store] Migrate databse from version $oldVersion to $newVersion"); + } if (oldVersion != newVersion) { schemes.forEach((String name, String scheme) async { if (name != "Clients") await db.execute("DROP TABLE IF EXISTS $name"); @@ -84,10 +85,12 @@ class Store extends StoreAPI { ? null : clientList["prev_batch"], ); - if (client.debug) + if (client.debug) { print("[Store] Restore client credentials of ${client.userID}"); - } else + } + } else { client.onLoginStateChanged.add(LoginState.loggedOut); + } } Future createTables(Database db) async { @@ -155,11 +158,11 @@ class Store extends StoreAPI { Future storeRoomUpdate(RoomUpdate roomUpdate) { if (txn == null) return null; // Insert the chat into the database if not exists - if (roomUpdate.membership != Membership.leave) + if (roomUpdate.membership != Membership.leave) { txn.rawInsert( "INSERT OR IGNORE INTO Rooms " + "VALUES(?, ?, 0, 0, '', 0, 0, '') ", [roomUpdate.id, roomUpdate.membership.toString().split('.').last]); - else { + } else { txn.rawDelete("DELETE FROM Rooms WHERE room_id=? ", [roomUpdate.id]); return null; } @@ -202,17 +205,18 @@ class Store extends StoreAPI { /// [transaction]. Future storeUserEventUpdate(UserUpdate userUpdate) { if (txn == null) return null; - if (userUpdate.type == "account_data") + if (userUpdate.type == "account_data") { txn.rawInsert("INSERT OR REPLACE INTO AccountData VALUES(?, ?)", [ userUpdate.eventType, json.encode(userUpdate.content["content"]), ]); - else if (userUpdate.type == "presence") + } else if (userUpdate.type == "presence") { txn.rawInsert("INSERT OR REPLACE INTO Presences VALUES(?, ?, ?)", [ userUpdate.eventType, userUpdate.content["sender"], json.encode(userUpdate.content["content"]), ]); + } return null; } @@ -272,14 +276,14 @@ class Store extends StoreAPI { // Save the event in the database if ((status == 1 || status == -1) && eventContent["unsigned"] is Map && - eventContent["unsigned"]["transaction_id"] is String) + eventContent["unsigned"]["transaction_id"] is String) { txn.rawUpdate( "UPDATE Events SET status=?, event_id=? WHERE event_id=?", [ status, eventContent["event_id"], eventContent["unsigned"]["transaction_id"] ]); - else + } else { txn.rawInsert( "INSERT OR REPLACE INTO Events VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [ @@ -294,13 +298,15 @@ class Store extends StoreAPI { eventContent["state_key"], status ]); + } // Is there a transaction id? Then delete the event with this id. if (status != -1 && eventUpdate.content.containsKey("unsigned") && - eventUpdate.content["unsigned"]["transaction_id"] is String) + eventUpdate.content["unsigned"]["transaction_id"] is String) { txn.rawDelete("DELETE FROM Events WHERE event_id=?", [eventUpdate.content["unsigned"]["transaction_id"]]); + } } if (type == "history") return null; @@ -321,12 +327,13 @@ class Store extends StoreAPI { eventContent["type"], json.encode(eventContent["content"]), ]); - } else + } else { txn.rawInsert("INSERT OR REPLACE INTO RoomAccountData VALUES(?, ?, ?)", [ eventContent["type"], chatId, json.encode(eventContent["content"]), ]); + } return null; } @@ -347,8 +354,9 @@ class Store extends StoreAPI { "SELECT * FROM RoomStates WHERE state_key LIKE '@%:%' AND state_key!=? AND room_id!=? GROUP BY state_key ORDER BY state_key", [client.userID, exceptRoomID]); List userList = []; - for (int i = 0; i < res.length; i++) + for (int i = 0; i < res.length; i++) { userList.add(Event.fromJson(res[i], Room(id: "", client: client)).asUser); + } return userList; } @@ -382,8 +390,9 @@ class Store extends StoreAPI { List eventList = []; - for (num i = 0; i < eventRes.length; i++) + for (num i = 0; i < eventRes.length; i++) { eventList.add(Event.fromJson(eventRes[i], room)); + } return eventList; } @@ -444,7 +453,7 @@ class Store extends StoreAPI { List> res = await _db.rawQuery( "SELECT * FROM Events WHERE event_id=? AND room_id=?", [eventID, room.id]); - if (res.length == 0) return null; + if (res.isEmpty) return null; return Event.fromJson(res[0], room); } @@ -452,9 +461,10 @@ class Store extends StoreAPI { Map newAccountData = {}; List> rawAccountData = await _db.rawQuery("SELECT * FROM AccountData"); - for (int i = 0; i < rawAccountData.length; i++) + for (int i = 0; i < rawAccountData.length; i++) { newAccountData[rawAccountData[i]["type"]] = AccountData.fromJson(rawAccountData[i]); + } return newAccountData; } @@ -502,7 +512,7 @@ class Store extends StoreAPI { assert(roomId != ""); List> res = await _db .rawQuery("SELECT * FROM NotificationsCache WHERE chat_id=?", [roomId]); - if (res.length == 0) return null; + if (res.isEmpty) return null; return res; } diff --git a/lib/views/chat.dart b/lib/views/chat.dart index 0261f48..970ca0b 100644 --- a/lib/views/chat.dart +++ b/lib/views/chat.dart @@ -26,18 +26,17 @@ class _ChatState extends State { Timeline timeline; - final ScrollController _scrollController = new ScrollController(); + final ScrollController _scrollController = ScrollController(); @override void initState() { _scrollController.addListener(() async { if (_scrollController.position.pixels == - _scrollController.position.maxScrollExtent) { - if (timeline.events.length > 0 && - timeline.events[timeline.events.length - 1].type != - EventTypes.RoomCreate) { - await timeline.requestHistory(historyCount: 100); - } + _scrollController.position.maxScrollExtent && + timeline.events.isNotEmpty && + timeline.events[timeline.events.length - 1].type != + EventTypes.RoomCreate) { + await timeline.requestHistory(historyCount: 100); } }); @@ -71,7 +70,7 @@ class _ChatState extends State { } File file = await FilePicker.getFile(); if (file == null) return; - Matrix.of(context).tryRequestWithLoadingDialog( + await Matrix.of(context).tryRequestWithLoadingDialog( room.sendFileEvent( MatrixFile(bytes: await file.readAsBytes(), path: file.path), ), @@ -88,7 +87,7 @@ class _ChatState extends State { maxWidth: 1600, maxHeight: 1600); if (file == null) return; - Matrix.of(context).tryRequestWithLoadingDialog( + await Matrix.of(context).tryRequestWithLoadingDialog( room.sendImageEvent( MatrixFile(bytes: await file.readAsBytes(), path: file.path), ), @@ -105,7 +104,7 @@ class _ChatState extends State { maxWidth: 1600, maxHeight: 1600); if (file == null) return; - Matrix.of(context).tryRequestWithLoadingDialog( + await Matrix.of(context).tryRequestWithLoadingDialog( room.sendImageEvent( MatrixFile(bytes: await file.readAsBytes(), path: file.path), ), @@ -136,15 +135,17 @@ class _ChatState extends State { child: FutureBuilder( future: getTimeline(), builder: (BuildContext context, snapshot) { - if (!snapshot.hasData) + if (!snapshot.hasData) { return Center( child: CircularProgressIndicator(), ); + } if (room.notificationCount != null && room.notificationCount > 0 && timeline != null && - timeline.events.length > 0) + timeline.events.isNotEmpty) { room.sendReadReceipt(timeline.events[0].eventId); + } return ListView.builder( reverse: true, itemCount: timeline.events.length, @@ -175,10 +176,11 @@ class _ChatState extends State { : PopupMenuButton( icon: Icon(Icons.add), onSelected: (String choice) async { - if (choice == "file") + if (choice == "file") { sendFileAction(context); - else if (choice == "image") + } else if (choice == "image") { sendImageAction(context); + } if (choice == "camera") openCameraAction(context); }, itemBuilder: (BuildContext context) => diff --git a/lib/views/chat_details.dart b/lib/views/chat_details.dart index dc6587e..e2e79e9 100644 --- a/lib/views/chat_details.dart +++ b/lib/views/chat_details.dart @@ -31,7 +31,7 @@ class _ChatDetailsState extends State { await matrix.tryRequestWithLoadingDialog( widget.room.setName(displayname), ); - if (success != null && success.length == 0) { + if (success != null && success.isEmpty) { Toast.show( "Displayname has been changed", context, @@ -57,7 +57,7 @@ class _ChatDetailsState extends State { ), ), ); - if (success != null && success.length == 0) { + if (success != null && success.isEmpty) { Toast.show( "Avatar has been changed", context, diff --git a/lib/views/chat_list.dart b/lib/views/chat_list.dart index 962c9a5..41d0475 100644 --- a/lib/views/chat_list.dart +++ b/lib/views/chat_list.dart @@ -39,8 +39,9 @@ class _ChatListState extends State { Future waitForFirstSync(BuildContext context) async { Client client = Matrix.of(context).client; - if (client.prevBatch?.isEmpty ?? true) + if (client.prevBatch?.isEmpty ?? true) { await client.onFirstSync.stream.first; + } sub ??= client.onSync.stream.listen((s) => setState(() => null)); return true; } @@ -121,10 +122,11 @@ class _ChatListState extends State { activeChat: widget.activeChat == rooms[i].id, ), ); - } else + } else { return Center( child: CircularProgressIndicator(), ); + } }, ), ); diff --git a/lib/views/invitation_selection.dart b/lib/views/invitation_selection.dart index c0f10ce..6af6b6a 100644 --- a/lib/views/invitation_selection.dart +++ b/lib/views/invitation_selection.dart @@ -20,8 +20,9 @@ class InvitationSelection extends StatelessWidget { List roomUsers = client.rooms[i].getParticipants(); for (int j = 0; j < roomUsers.length; j++) { if (userMap[roomUsers[j].id] != true && - participants.indexWhere((u) => u.id == roomUsers[j].id) == -1) + participants.indexWhere((u) => u.id == roomUsers[j].id) == -1) { contacts.add(roomUsers[j]); + } userMap[roomUsers[j].id] = true; } } @@ -32,12 +33,13 @@ class InvitationSelection extends StatelessWidget { final success = await Matrix.of(context).tryRequestWithLoadingDialog( room.invite(id), ); - if (success != false) + if (success != false) { Toast.show( "Contact has been invited to the group.", context, duration: Toast.LENGTH_LONG, ); + } } @override @@ -53,10 +55,11 @@ class InvitationSelection extends StatelessWidget { body: FutureBuilder>( future: getContacts(context), builder: (BuildContext context, snapshot) { - if (!snapshot.hasData) + if (!snapshot.hasData) { return Center( child: CircularProgressIndicator(), ); + } List contacts = snapshot.data; return ListView.builder( itemCount: contacts.length, diff --git a/lib/views/login.dart b/lib/views/login.dart index bcfc151..43eab17 100644 --- a/lib/views/login.dart +++ b/lib/views/login.dart @@ -35,13 +35,15 @@ class _LoginPageState extends State { } serverError = null; - if (usernameController.text.isEmpty || passwordController.text.isEmpty) + if (usernameController.text.isEmpty || passwordController.text.isEmpty) { return; + } String homeserver = serverController.text; if (homeserver.isEmpty) homeserver = defaultHomeserver; - if (!homeserver.startsWith("https://")) + if (!homeserver.startsWith("https://")) { homeserver = "https://" + homeserver; + } try { matrix.showLoadingDialog(context); @@ -64,7 +66,7 @@ class _LoginPageState extends State { setState(() => passwordError = exception.toString()); return matrix.hideLoadingDialog(); } - Matrix.of(context).saveAccount(); + await Matrix.of(context).saveAccount(); matrix.hideLoadingDialog(); } diff --git a/lib/views/settings.dart b/lib/views/settings.dart index 033aeff..ec16a90 100644 --- a/lib/views/settings.dart +++ b/lib/views/settings.dart @@ -33,7 +33,7 @@ class _SettingsState extends State { dynamic profile; void logoutAction(BuildContext context) async { MatrixState matrix = Matrix.of(context); - Navigator.of(context).pushAndRemoveUntil( + await Navigator.of(context).pushAndRemoveUntil( AppRoute.defaultRoute(context, LoginPage()), (r) => false); await matrix.tryRequestWithLoadingDialog(matrix.client.logout()); matrix.clean(); @@ -49,7 +49,7 @@ class _SettingsState extends State { data: {"displayname": displayname}, ), ); - if (success != null && success.length == 0) { + if (success != null && success.isEmpty) { Toast.show( "Displayname has been changed", context, @@ -79,7 +79,7 @@ class _SettingsState extends State { ), ), ); - if (success != null && success.length == 0) { + if (success != null && success.isEmpty) { Toast.show( "Avatar has been changed", context, diff --git a/test/widget_test.dart b/test/widget_test.dart index ba00aa5..d4fc17d 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -5,26 +5,13 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:fluffychat/main.dart'; void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { + testWidgets('Test if the app starts', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); + await tester.pumpWidget(App()); }); }