feat: Switch to VRouter
This commit is contained in:
parent
ab4ea74d00
commit
c2fce64494
57 changed files with 678 additions and 617 deletions
|
|
@ -1,12 +1,13 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
import 'matrix.dart';
|
||||
|
||||
class ChatSettingsPopupMenu extends StatefulWidget {
|
||||
|
|
@ -68,7 +69,6 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
case 'leave':
|
||||
final confirmed = await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
title: L10n.of(context).areYouSure,
|
||||
okLabel: L10n.of(context).ok,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
|
|
@ -77,8 +77,7 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
final success = await showFutureLoadingDialog(
|
||||
context: context, future: () => widget.room.leave());
|
||||
if (success.error == null) {
|
||||
await AdaptivePageLayout.of(context)
|
||||
.pushNamedAndRemoveAllOthers('/');
|
||||
VRouter.of(context).push('/rooms');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -95,12 +94,7 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
widget.room.setPushRuleState(PushRuleState.notify));
|
||||
break;
|
||||
case 'details':
|
||||
if (!AdaptivePageLayout.of(context).columnMode(context) ||
|
||||
AdaptivePageLayout.of(context).viewDataStack.length < 3) {
|
||||
await AdaptivePageLayout.of(context)
|
||||
.pushNamed('/rooms/${widget.room.id}/details');
|
||||
}
|
||||
|
||||
VRouter.of(context).push('/rooms/${widget.room.id}/details');
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import 'package:famedlysdk/famedlysdk.dart';
|
|||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
import '../utils/matrix_sdk_extensions.dart/client_presence_extension.dart';
|
||||
import '../utils/matrix_sdk_extensions.dart/presence_extension.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
|
||||
class ContactsList extends StatefulWidget {
|
||||
final TextEditingController searchController;
|
||||
|
|
@ -102,9 +102,8 @@ class _ContactListTile extends StatelessWidget {
|
|||
fontWeight: FontWeight.bold,
|
||||
)
|
||||
: null),
|
||||
onTap: () => AdaptivePageLayout.of(context)
|
||||
.pushNamedAndRemoveUntilIsFirst(
|
||||
'/rooms/${Matrix.of(context).client.getDirectChatFromUserId(contact.senderId)}'),
|
||||
onTap: () => VRouter.of(context).push(
|
||||
'/rooms/${Matrix.of(context).client.getDirectChatFromUserId(contact.senderId)}'),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
import 'matrix.dart';
|
||||
|
||||
class EncryptionButton extends StatefulWidget {
|
||||
|
|
@ -21,14 +21,13 @@ class _EncryptionButtonState extends State<EncryptionButton> {
|
|||
|
||||
void _enableEncryptionAction() async {
|
||||
if (widget.room.encrypted) {
|
||||
await AdaptivePageLayout.of(context)
|
||||
.pushNamed('/rooms/${widget.room.id}/encryption');
|
||||
VRouter.of(context).push('/rooms/${widget.room.id}/encryption');
|
||||
return;
|
||||
}
|
||||
if (widget.room.joinRules == JoinRules.public) {
|
||||
await showOkAlertDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
|
||||
okLabel: L10n.of(context).ok,
|
||||
message: L10n.of(context).noEncryptionForPublicRooms,
|
||||
);
|
||||
|
|
@ -36,7 +35,7 @@ class _EncryptionButtonState extends State<EncryptionButton> {
|
|||
}
|
||||
if (await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
|
||||
title: L10n.of(context).enableEncryption,
|
||||
message: widget.room.client.encryptionEnabled
|
||||
? L10n.of(context).enableEncryptionWarning
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/sentry_controller.dart';
|
||||
|
|
@ -95,7 +94,7 @@ class _AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
_playAction();
|
||||
} catch (e, s) {
|
||||
Logs().v('Could not download audio file', e, s);
|
||||
AdaptivePageLayout.of(context).showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(e.toLocalizedString(context)),
|
||||
),
|
||||
|
|
@ -135,7 +134,7 @@ class _AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
onPlayerStateChanged ??= audioPlayer.onPlayerStateChanged
|
||||
.listen((_) => setState(() => null));
|
||||
onPlayerError ??= audioPlayer.onPlayerError.listen((e) {
|
||||
AdaptivePageLayout.of(context).showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(L10n.of(context).oopsSomethingWentWrong),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:famedlysdk/encryption/utils/key_verification.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/widgets/event_content/audio_player.dart';
|
||||
|
|
@ -27,7 +26,7 @@ class MessageContent extends StatelessWidget {
|
|||
|
||||
void _verifyOrRequestKey(BuildContext context) async {
|
||||
if (event.content['can_request_session'] != true) {
|
||||
AdaptivePageLayout.of(context).showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(
|
||||
event.type == EventTypes.Encrypted
|
||||
? L10n.of(context).needPantalaimonWarning
|
||||
|
|
@ -61,7 +60,7 @@ class MessageContent extends StatelessWidget {
|
|||
future: () => event.requestKey(),
|
||||
);
|
||||
if (success.error == null) {
|
||||
AdaptivePageLayout.of(context).showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(L10n.of(context).requestToReadOlderMessages)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
|
@ -6,8 +7,10 @@ class LoadingView extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (Matrix.of(context).loginState != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) =>
|
||||
AdaptivePageLayout.of(context).pushNamedAndRemoveAllOthers('/'));
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => context.vRouter.push(
|
||||
Matrix.of(context).loginState == LoginState.logged
|
||||
? '/rooms'
|
||||
: '/home'));
|
||||
}
|
||||
return Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
|
|
|
|||
40
lib/widgets/layouts/two_column_layout.dart
Normal file
40
lib/widgets/layouts/two_column_layout.dart
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TwoColumnLayout extends StatelessWidget {
|
||||
final Widget mainView;
|
||||
final Widget sideView;
|
||||
|
||||
const TwoColumnLayout(
|
||||
{Key key, @required this.mainView, @required this.sideView})
|
||||
: super(key: key);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (MediaQuery.of(context).size.width <= AppConfig.columnWidth * 2) {
|
||||
return mainView;
|
||||
}
|
||||
return Scaffold(
|
||||
body: ScaffoldMessenger(
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(),
|
||||
width: 360.0,
|
||||
child: mainView,
|
||||
),
|
||||
Container(
|
||||
width: 1.0,
|
||||
color: Theme.of(context).dividerColor,
|
||||
),
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
child: sideView,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/event_extension.dart';
|
||||
|
|
@ -9,6 +9,7 @@ import 'package:fluffychat/utils/room_status_extension.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:pedantic/pedantic.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import '../../utils/date_time_extension.dart';
|
||||
import '../avatar.dart';
|
||||
|
|
@ -46,7 +47,7 @@ class ChatListItem extends StatelessWidget {
|
|||
}
|
||||
|
||||
if (room.membership == Membership.ban) {
|
||||
AdaptivePageLayout.of(context).showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(L10n.of(context).youHaveBeenBannedFromThisChat),
|
||||
),
|
||||
|
|
@ -96,15 +97,13 @@ class ChatListItem extends StatelessWidget {
|
|||
file: Matrix.of(context).shareContent['file'],
|
||||
room: room,
|
||||
),
|
||||
useRootNavigator: false,
|
||||
);
|
||||
} else {
|
||||
unawaited(room.sendEvent(Matrix.of(context).shareContent));
|
||||
}
|
||||
Matrix.of(context).shareContent = null;
|
||||
}
|
||||
await AdaptivePageLayout.of(context)
|
||||
.pushNamedAndRemoveUntilIsFirst('/rooms/${room.id}');
|
||||
context.vRouter.push('/rooms/${room.id}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -126,7 +125,6 @@ class ChatListItem extends StatelessWidget {
|
|||
title: L10n.of(context).areYouSure,
|
||||
okLabel: L10n.of(context).yes,
|
||||
cancelLabel: L10n.of(context).no,
|
||||
useRootNavigator: false,
|
||||
);
|
||||
if (confirmed == OkCancelResult.cancel) return;
|
||||
await showFutureLoadingDialog(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import '../avatar.dart';
|
||||
import '../matrix.dart';
|
||||
|
|
@ -18,8 +18,7 @@ class PublicRoomListItem extends StatelessWidget {
|
|||
future: () => _joinRoomAndWait(context),
|
||||
);
|
||||
if (success.error == null) {
|
||||
await AdaptivePageLayout.of(context)
|
||||
.pushNamed('/rooms/${success.result}');
|
||||
VRouter.of(context).pushNamed('/rooms/${success.result}');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class _LogViewerState extends State<LogViewer> {
|
|||
Widget build(BuildContext context) {
|
||||
final outputEvents = Logs()
|
||||
.outputEvents
|
||||
.where((e) => e.level.index >= logLevel.index)
|
||||
.where((e) => e.level.index <= logLevel.index)
|
||||
.toList();
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
|
|
@ -44,7 +44,12 @@ class _LogViewerState extends State<LogViewer> {
|
|||
itemCount: outputEvents.length,
|
||||
itemBuilder: (context, i) => SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Text(outputEvents[i].toDisplayString()),
|
||||
child: SelectableText(
|
||||
outputEvents[i].toDisplayString(),
|
||||
style: TextStyle(
|
||||
color: outputEvents[i].color,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
@ -52,8 +57,26 @@ class _LogViewerState extends State<LogViewer> {
|
|||
}
|
||||
|
||||
extension on LogEvent {
|
||||
Color get color {
|
||||
switch (level) {
|
||||
case Level.wtf:
|
||||
return Colors.purple;
|
||||
case Level.error:
|
||||
return Colors.red;
|
||||
case Level.warning:
|
||||
return Colors.orange;
|
||||
case Level.info:
|
||||
return Colors.green;
|
||||
case Level.debug:
|
||||
return Colors.white;
|
||||
case Level.verbose:
|
||||
default:
|
||||
return Colors.grey;
|
||||
}
|
||||
}
|
||||
|
||||
String toDisplayString() {
|
||||
var str = '# $title';
|
||||
var str = '# [${level.toString().split('.').last.toUpperCase()}] $title';
|
||||
if (exception != null) {
|
||||
str += ' - ${exception.toString()}';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import 'dart:io';
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:famedlysdk/encryption.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/matrix_locals.dart';
|
||||
|
|
@ -14,7 +13,6 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_app_lock/flutter_app_lock.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
import 'package:http/http.dart' as http;
|
||||
|
|
@ -22,7 +20,6 @@ import 'package:url_launcher/url_launcher.dart';
|
|||
import 'package:desktop_notifications/desktop_notifications.dart';
|
||||
|
||||
import '../utils/beautify_string_extension.dart';
|
||||
import '../utils/localized_exception_extension.dart';
|
||||
import '../utils/famedlysdk_store.dart';
|
||||
import '../pages/key_verification_dialog.dart';
|
||||
import '../utils/platform_infos.dart';
|
||||
|
|
@ -30,13 +27,14 @@ import '../config/app_config.dart';
|
|||
import '../config/setting_keys.dart';
|
||||
import '../utils/matrix_sdk_extensions.dart/fluffy_client.dart';
|
||||
import '../utils/background_push.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
class Matrix extends StatefulWidget {
|
||||
static const String callNamespace = 'chat.fluffy.jitsi_call';
|
||||
|
||||
final Widget child;
|
||||
|
||||
final GlobalKey<AdaptivePageLayoutState> apl;
|
||||
final GlobalKey<VRouterState> router;
|
||||
|
||||
final BuildContext context;
|
||||
|
||||
|
|
@ -44,7 +42,7 @@ class Matrix extends StatefulWidget {
|
|||
|
||||
Matrix({
|
||||
this.child,
|
||||
@required this.apl,
|
||||
@required this.router,
|
||||
@required this.context,
|
||||
this.testClient,
|
||||
Key key,
|
||||
|
|
@ -137,7 +135,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
title: L10n.of(context).pleaseEnterYourPassword,
|
||||
okLabel: L10n.of(context).ok,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
useRootNavigator: false,
|
||||
textFields: [
|
||||
DialogTextField(
|
||||
minLines: 1,
|
||||
|
|
@ -190,7 +187,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
await showOkCancelAlertDialog(
|
||||
message: L10n.of(context).pleaseFollowInstructionsOnWeb,
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
okLabel: L10n.of(context).next,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
)) {
|
||||
|
|
@ -287,9 +283,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
});
|
||||
}
|
||||
client = FluffyClient();
|
||||
LoadingDialog.defaultTitle = L10n.of(context).loadingPleaseWait;
|
||||
LoadingDialog.defaultBackLabel = L10n.of(context).close;
|
||||
LoadingDialog.defaultOnError = (Object e) => e.toLocalizedString(context);
|
||||
|
||||
onRoomKeyRequestSub ??=
|
||||
client.onRoomKeyRequest.stream.listen((RoomKeyRequest request) async {
|
||||
|
|
@ -300,7 +293,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
final sender = room.getUserByMXIDSync(request.sender);
|
||||
if (await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
title: L10n.of(context).requestToReadOlderMessages,
|
||||
message:
|
||||
'${sender.id}\n\n${L10n.of(context).device}:\n${request.requestingDevice.deviceId}\n\n${L10n.of(context).publicKey}:\n${request.requestingDevice.ed25519Key.beautified}',
|
||||
|
|
@ -324,7 +316,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
};
|
||||
if (await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
title: L10n.of(context).newVerificationRequest,
|
||||
message: L10n.of(context).askVerificationRequest(request.userId),
|
||||
okLabel: L10n.of(context).ok,
|
||||
|
|
@ -350,7 +341,8 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
onLoginStateChanged ??= client.onLoginStateChanged.stream.listen((state) {
|
||||
if (loginState != state) {
|
||||
loginState = state;
|
||||
widget.apl.currentState.pushNamedAndRemoveAllOthers('/');
|
||||
widget.router.currentState
|
||||
.push(loginState == LoginState.logged ? '/rooms' : '/home');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -380,7 +372,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
}
|
||||
|
||||
if (PlatformInfos.isMobile) {
|
||||
_backgroundPush = BackgroundPush(client, context, widget.apl);
|
||||
_backgroundPush = BackgroundPush(client, context, widget.router);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue