1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-23 05:19:22 +00:00
comunicmobile/lib/utils/navigation_utils.dart

67 lines
2.0 KiB
Dart
Raw Normal View History

2020-04-16 10:06:01 +00:00
import 'package:comunic/helpers/virtual_directory_helper.dart';
2020-05-05 11:21:37 +00:00
import 'package:comunic/ui/routes/main_route/main_route.dart';
2019-11-02 11:46:17 +00:00
import 'package:comunic/ui/routes/single_post_route.dart';
2020-04-16 10:06:01 +00:00
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
2019-06-10 12:24:34 +00:00
import 'package:flutter/material.dart';
/// Navigation utilities
///
/// @author Pierre HUBERT
/// Pop a page
void popPage(BuildContext context) {
MainController.of(context)!.popPage();
}
2019-06-10 12:24:34 +00:00
/// Open the page of a user
void openUserPage({required int userID, required BuildContext context}) {
2019-06-10 12:24:34 +00:00
assert(userID != null);
assert(context != null);
MainController.of(context)!.openUserPage(userID);
2019-06-10 12:24:34 +00:00
}
2019-11-02 11:46:17 +00:00
/// Open a post in full screen
void openPostFullScreen(int postID, BuildContext context) {
MainController.of(context)!.push(SinglePostRoute(postID: postID));
2019-11-02 11:46:17 +00:00
}
2020-04-16 10:06:01 +00:00
/// Open a virtual directory
void openVirtualDirectory(BuildContext context, String directory) async {
if (directory.startsWith("@")) directory = directory.substring(1);
try {
final result = await VirtualDirectoryHelper().find(directory);
switch (result.type) {
case VirtualDirectoryType.USER:
openUserPage(context: context, userID: result.id!);
2020-04-16 10:06:01 +00:00
break;
case VirtualDirectoryType.GROUP:
MainController.of(context)!.openGroup(result.id!);
2020-04-16 10:06:01 +00:00
break;
case VirtualDirectoryType.NONE:
await showDialog(
context: context,
builder: (c) => AlertDialog(
title: Text(tr("Error")!),
content: Text(tr("Could not find related resource!")!),
2020-04-16 10:06:01 +00:00
actions: <Widget>[
MaterialButton(
child: Text(tr("OK")!),
2020-04-16 10:06:01 +00:00
onPressed: () => Navigator.of(c).pop(),
)
],
));
break;
}
} catch (e, stack) {
print(e);
print(stack);
showSimpleSnack(context, tr("Could not search virtual directory!")!);
2020-04-16 10:06:01 +00:00
}
}