refactor: Migrate routes to go router

This commit is contained in:
krille-chan 2023-08-07 18:40:02 +02:00
commit ee957ab1f6
No known key found for this signature in database
52 changed files with 584 additions and 612 deletions

View file

@ -38,14 +38,17 @@ import 'sticker_picker_dialog.dart';
class ChatPage extends StatelessWidget {
final Widget? sideView;
final String roomId;
const ChatPage({Key? key, this.sideView}) : super(key: key);
const ChatPage({
Key? key,
this.sideView,
required this.roomId,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final roomId = context.vRouter.pathParameters['roomid'];
final room =
roomId == null ? null : Matrix.of(context).client.getRoomById(roomId);
final room = Matrix.of(context).client.getRoomById(roomId);
if (room == null) {
return Scaffold(
appBar: AppBar(title: Text(L10n.of(context)!.oopsSomethingWentWrong)),
@ -58,7 +61,11 @@ class ChatPage extends StatelessWidget {
),
);
}
return ChatPageWithRoom(sideView: sideView, room: room);
return ChatPageWithRoom(
key: Key('chat_page_$roomId'),
sideView: sideView,
room: room,
);
}
}
@ -188,7 +195,7 @@ class ChatController extends State<ChatPageWithRoom> {
);
final roomId = success.result;
if (roomId == null) return;
VRouter.of(context).toSegments(['rooms', roomId]);
context.go(['', 'rooms', roomId].join('/'));
}
void leaveChat() async {
@ -197,7 +204,7 @@ class ChatController extends State<ChatPageWithRoom> {
future: room.leave,
);
if (success.error != null) return;
VRouter.of(context).to('/rooms');
context.go('/rooms');
}
EmojiPickerType emojiPickerType = EmojiPickerType.keyboard;
@ -329,7 +336,7 @@ class ChatController extends State<ChatPageWithRoom> {
// "load more" button is visible on the screen
SchedulerBinding.instance.addPostFrameCallback((_) async {
if (mounted) {
final event = VRouter.of(context).queryParameters['event'];
final event = GoRouterState.of(context).uri.queryParameters['event'];
if (event != null) {
scrollToEventId(event);
}
@ -803,7 +810,7 @@ class ChatController extends State<ChatPageWithRoom> {
};
}
setState(() => selectedEvents.clear());
VRouter.of(context).to('/rooms');
context.go('/rooms');
}
void sendAgainAction() {
@ -901,7 +908,7 @@ class ChatController extends State<ChatPageWithRoom> {
future: room.forget,
);
if (result.error != null) return;
VRouter.of(context).to('/archive');
context.go('/rooms/archive');
}
void typeEmoji(Emoji? emoji) {
@ -1017,7 +1024,7 @@ class ChatController extends State<ChatPageWithRoom> {
future: room.leave,
);
if (result.error == null) {
VRouter.of(context).toSegments(['rooms', result.result!]);
context.go(['', 'rooms', result.result!].join('/'));
}
}

View file

@ -36,8 +36,7 @@ class ChatAppBarTitle extends StatelessWidget {
)
: controller.isArchived
? null
: () =>
VRouter.of(context).toSegments(['rooms', room.id, 'details']),
: () => context.go(['', 'rooms', room.id, 'details'].join('/')),
child: Row(
children: [
Hero(

View file

@ -4,7 +4,6 @@ import 'package:badges/badges.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/config/app_config.dart';
@ -147,15 +146,16 @@ class ChatView extends StatelessWidget {
}
final bottomSheetPadding = FluffyThemes.isColumnMode(context) ? 16.0 : 8.0;
return VWidgetGuard(
onSystemPop: (redirector) async {
return WillPopScope(
onWillPop: () async {
if (controller.selectedEvents.isNotEmpty) {
controller.clearSelectedEvents();
redirector.stopRedirection();
return false;
} else if (controller.showEmojiPicker) {
controller.emojiPickerAction();
redirector.stopRedirection();
return false;
}
return true;
},
child: GestureDetector(
onTapDown: (_) => controller.setReadMarker(),

View file

@ -38,8 +38,8 @@ class EncryptionButton extends StatelessWidget {
? Colors.orange
: null,
),
onPressed: () => VRouter.of(context)
.toSegments(['rooms', room.id, 'encryption']),
onPressed: () =>
context.go(['', 'rooms', room.id, 'encryption'].join('/')),
),
);
},