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

68 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';
import 'package:meta/meta.dart';
/// Navigation utilities
///
/// @author Pierre HUBERT
/// Pop a page
void popPage(BuildContext context) {
2020-04-17 13:26:37 +00:00
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}) {
assert(userID != null);
assert(context != null);
2020-04-17 13:26:37 +00:00
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) {
2020-04-17 13:26:37 +00:00
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);
break;
case VirtualDirectoryType.GROUP:
2020-04-17 13:26:37 +00:00
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!")),
actions: <Widget>[
MaterialButton(
child: Text(tr("OK")),
onPressed: () => Navigator.of(c).pop(),
)
],
));
break;
}
} catch (e, stack) {
print(e);
print(stack);
showSimpleSnack(context, tr("Could not search virtual directory!"));
}
}