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

@ -56,8 +56,14 @@ enum ActiveFilter {
class ChatList extends StatefulWidget {
static BuildContext? contextForVoip;
final bool displayNavigationRail;
final String? activeChat;
const ChatList({Key? key}) : super(key: key);
const ChatList({
Key? key,
this.displayNavigationRail = false,
required this.activeChat,
}) : super(key: key);
@override
ChatListController createState() => ChatListController();
@ -259,7 +265,7 @@ class ChatListController extends State<ChatList>
Stream<Client> get clientStream => _clientStream.stream;
void addAccountAction() => VRouter.of(context).to('/settings/account');
void addAccountAction() => context.go('/rooms/settings/account');
void _onScroll() {
final newScrolledToTop = scrollController.position.pixels <= 0;
@ -271,7 +277,7 @@ class ChatListController extends State<ChatList>
void editSpace(BuildContext context, String spaceId) async {
await Matrix.of(context).client.getRoomById(spaceId)!.postLoad();
if (mounted) {
VRouter.of(context).toSegments(['spaces', spaceId]);
context.go('/rooms/spaces/$spaceId');
}
}
@ -281,7 +287,7 @@ class ChatListController extends State<ChatList>
final selectedRoomIds = <String>{};
String? get activeChat => VRouter.of(context).pathParameters['roomid'];
String? get activeChat => widget.activeChat;
SelectMode get selectMode => Matrix.of(context).shareContent != null
? SelectMode.share
@ -300,7 +306,7 @@ class ChatListController extends State<ChatList>
name: file.path,
).detectFileType,
};
VRouter.of(context).to('/rooms');
context.go('/rooms');
}
void _processIncomingSharedText(String? text) {
@ -315,12 +321,12 @@ class ChatListController extends State<ChatList>
'msgtype': 'm.text',
'body': text,
};
VRouter.of(context).to('/rooms');
context.go('/rooms');
}
void _processIncomingUris(String? text) async {
if (text == null) return;
VRouter.of(context).to('/rooms');
context.go('/rooms');
WidgetsBinding.instance.addPostFrameCallback((_) {
UrlLauncher(context, text).openMatrixToUrl();
});
@ -582,7 +588,7 @@ class ChatListController extends State<ChatList>
}
void setActiveClient(Client client) {
VRouter.of(context).to('/rooms');
context.go('/rooms');
setState(() {
activeFilter = AppConfig.separateChatTypes
? ActiveFilter.messages
@ -595,7 +601,7 @@ class ChatListController extends State<ChatList>
}
void setActiveBundle(String bundle) {
VRouter.of(context).to('/rooms');
context.go('/rooms');
setState(() {
selectedRoomIds.clear();
Matrix.of(context).activeBundle = bundle;

View file

@ -61,7 +61,7 @@ class ChatListItem extends StatelessWidget {
}
if (room.membership == Membership.leave) {
VRouter.of(context).toSegments(['archive', room.id]);
context.go(['', 'archive', room.id].join('/'));
}
if (room.membership == Membership.join) {
@ -86,7 +86,7 @@ class ChatListItem extends StatelessWidget {
Matrix.of(context).shareContent = null;
}
VRouter.of(context).toSegments(['rooms', room.id]);
context.go(['', 'rooms', room.id].join('/'));
}
}

View file

@ -86,13 +86,12 @@ class ChatListView extends StatelessWidget {
stream: Matrix.of(context).onShareContentChanged.stream,
builder: (_, __) {
final selectMode = controller.selectMode;
return VWidgetGuard(
onSystemPop: (redirector) async {
return WillPopScope(
onWillPop: () async {
final selMode = controller.selectMode;
if (selMode != SelectMode.normal) {
controller.cancelAction();
redirector.stopRedirection();
return;
return false;
}
if (controller.activeFilter !=
(AppConfig.separateChatTypes
@ -100,14 +99,14 @@ class ChatListView extends StatelessWidget {
: ActiveFilter.allChats)) {
controller
.onDestinationSelected(AppConfig.separateChatTypes ? 1 : 0);
redirector.stopRedirection();
return;
return false;
}
return true;
},
child: Row(
children: [
if (FluffyThemes.isColumnMode(context) &&
FluffyThemes.getDisplayNavigationRail(context)) ...[
controller.widget.displayNavigationRail) ...[
Builder(
builder: (context) {
final allSpaces =
@ -193,8 +192,7 @@ class ChatListView extends StatelessWidget {
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.keyN
},
onKeysPressed: () =>
VRouter.of(context).to('/newprivatechat'),
onKeysPressed: () => context.go('/rooms/newprivatechat'),
helpLabel: L10n.of(context)!.newChat,
child: selectMode == SelectMode.normal &&
!controller.isSearchMode

View file

@ -261,16 +261,16 @@ class ClientChooserButton extends StatelessWidget {
cancelLabel: L10n.of(context)!.cancel,
);
if (consent != OkCancelResult.ok) return;
VRouter.of(context).to('/settings/addaccount');
context.go('/rooms/settings/addaccount');
break;
case SettingsAction.newStory:
VRouter.of(context).to('/stories/create');
context.go('/rooms/stories/create');
break;
case SettingsAction.newGroup:
VRouter.of(context).to('/newgroup');
context.go('/rooms/newgroup');
break;
case SettingsAction.newSpace:
VRouter.of(context).to('/newspace');
context.go('/rooms/newspace');
break;
case SettingsAction.invite:
FluffyShare.share(
@ -282,10 +282,10 @@ class ClientChooserButton extends StatelessWidget {
);
break;
case SettingsAction.settings:
VRouter.of(context).to('/settings');
context.go('/rooms/settings');
break;
case SettingsAction.archive:
VRouter.of(context).to('/archive');
context.go('/rooms/archive');
break;
}
}

View file

@ -73,13 +73,13 @@ class _SpaceViewState extends State<SpaceView> {
}
if (spaceChild.roomType == 'm.space') {
if (spaceChild.roomId == widget.controller.activeSpaceId) {
VRouter.of(context).toSegments(['spaces', spaceChild.roomId]);
context.go('/rooms/spaces/${spaceChild.roomId}');
} else {
widget.controller.setActiveSpace(spaceChild.roomId);
}
return;
}
VRouter.of(context).toSegments(['rooms', spaceChild.roomId]);
context.go(['', 'rooms', spaceChild.roomId].join('/'));
}
void _onSpaceChildContextMenu([
@ -234,13 +234,13 @@ class _SpaceViewState extends State<SpaceView> {
);
final spaceChildren = response.rooms;
final canLoadMore = response.nextBatch != null;
return VWidgetGuard(
onSystemPop: (redirector) async {
return WillPopScope(
onWillPop: () async {
if (parentSpace != null) {
widget.controller.setActiveSpace(parentSpace.id);
redirector.stopRedirection();
return;
return false;
}
return true;
},
child: CustomScrollView(
controller: widget.scrollController,

View file

@ -22,13 +22,13 @@ class StartChatFloatingActionButton extends StatelessWidget {
switch (activeFilter) {
case ActiveFilter.allChats:
case ActiveFilter.messages:
VRouter.of(context).to('/newprivatechat');
context.go('/rooms/newprivatechat');
break;
case ActiveFilter.groups:
VRouter.of(context).to('/newgroup');
context.go('/rooms/newgroup');
break;
case ActiveFilter.spaces:
VRouter.of(context).to('/newspace');
context.go('/rooms/newspace');
break;
}
}

View file

@ -23,7 +23,7 @@ class StoriesHeader extends StatelessWidget {
const StoriesHeader({required this.filter, Key? key}) : super(key: key);
void _addToStoryAction(BuildContext context) =>
VRouter.of(context).to('/stories/create');
context.go('/rooms/stories/create');
void _goToStoryAction(BuildContext context, String roomId) async {
final room = Matrix.of(context).client.getRoomById(roomId);
@ -35,7 +35,7 @@ class StoriesHeader extends StatelessWidget {
);
if (result.error != null) return;
}
VRouter.of(context).toSegments(['stories', roomId]);
context.go(['', 'stories', roomId].join('/'));
}
void _contextualActions(BuildContext context, Room room) async {
@ -249,7 +249,7 @@ class _StoryButton extends StatelessWidget {
child: FloatingActionButton.small(
heroTag: null,
onPressed: () =>
VRouter.of(context).to('/stories/create'),
context.go('/rooms/stories/create'),
child: const Icon(
Icons.add_outlined,
size: 16,