2020-09-09 17:41:54 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-04-05 20:14:39 +02:00
|
|
|
import 'package:lemmy_api_client/v3.dart';
|
2020-09-09 17:41:54 +02:00
|
|
|
|
|
|
|
import '../pages/community.dart';
|
2021-09-11 01:04:15 +02:00
|
|
|
import '../pages/full_post/full_post.dart';
|
2020-09-09 17:41:54 +02:00
|
|
|
import '../pages/instance.dart';
|
2020-10-06 22:24:03 +02:00
|
|
|
import '../pages/media_view.dart';
|
2020-09-10 14:00:39 +02:00
|
|
|
import '../pages/user.dart';
|
2020-09-09 17:41:54 +02:00
|
|
|
|
2020-09-30 19:05:00 +02:00
|
|
|
/// Pushes onto the navigator stack the given widget
|
2020-09-16 22:53:04 +02:00
|
|
|
Future<dynamic> goTo(
|
|
|
|
BuildContext context,
|
|
|
|
Widget Function(BuildContext context) builder,
|
|
|
|
) =>
|
2021-09-30 12:55:23 +02:00
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
2020-09-16 22:53:04 +02:00
|
|
|
builder: builder,
|
2020-09-09 17:41:54 +02:00
|
|
|
));
|
|
|
|
|
2020-09-30 19:05:00 +02:00
|
|
|
/// Replaces the top of the navigator stack with the given widget
|
2020-09-28 20:28:06 +02:00
|
|
|
Future<dynamic> goToReplace(
|
|
|
|
BuildContext context,
|
|
|
|
Widget Function(BuildContext context) builder,
|
|
|
|
) =>
|
2021-09-30 12:55:23 +02:00
|
|
|
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
2020-09-28 20:28:06 +02:00
|
|
|
builder: builder,
|
|
|
|
));
|
|
|
|
|
2020-12-31 14:58:23 +01:00
|
|
|
void goToInstance(BuildContext context, String instanceHost) =>
|
|
|
|
goTo(context, (context) => InstancePage(instanceHost: instanceHost));
|
2020-09-16 22:53:04 +02:00
|
|
|
|
2020-09-09 17:41:54 +02:00
|
|
|
// ignore: camel_case_types
|
|
|
|
abstract class goToCommunity {
|
|
|
|
/// Navigates to `CommunityPage`
|
2020-12-31 14:58:23 +01:00
|
|
|
static void byId(
|
|
|
|
BuildContext context, String instanceHost, int communityId) =>
|
2020-09-16 22:53:04 +02:00
|
|
|
goTo(
|
|
|
|
context,
|
|
|
|
(context) => CommunityPage.fromId(
|
2020-12-31 14:58:23 +01:00
|
|
|
instanceHost: instanceHost, communityId: communityId),
|
2020-09-16 22:53:04 +02:00
|
|
|
);
|
2020-09-09 17:41:54 +02:00
|
|
|
|
|
|
|
static void byName(
|
2020-12-31 14:58:23 +01:00
|
|
|
BuildContext context, String instanceHost, String communityName) =>
|
2020-09-16 22:53:04 +02:00
|
|
|
goTo(
|
|
|
|
context,
|
|
|
|
(context) => CommunityPage.fromName(
|
2020-12-31 14:58:23 +01:00
|
|
|
instanceHost: instanceHost, communityName: communityName),
|
2020-09-16 22:53:04 +02:00
|
|
|
);
|
2020-09-09 17:41:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ignore: camel_case_types
|
|
|
|
abstract class goToUser {
|
2020-12-31 14:58:23 +01:00
|
|
|
static void byId(BuildContext context, String instanceHost, int userId) =>
|
2020-09-16 22:53:04 +02:00
|
|
|
goTo(context,
|
2020-12-31 14:58:23 +01:00
|
|
|
(context) => UserPage(instanceHost: instanceHost, userId: userId));
|
2020-09-09 17:41:54 +02:00
|
|
|
|
|
|
|
static void byName(
|
2020-12-31 14:58:23 +01:00
|
|
|
BuildContext context, String instanceHost, String userName) =>
|
2020-09-09 17:41:54 +02:00
|
|
|
throw UnimplementedError('need to create UserProfile constructor first');
|
2021-02-24 20:52:18 +01:00
|
|
|
|
2021-04-05 20:14:39 +02:00
|
|
|
static void fromPersonSafe(BuildContext context, PersonSafe personSafe) =>
|
|
|
|
goToUser.byId(context, personSafe.instanceHost, personSafe.id);
|
2020-09-09 17:41:54 +02:00
|
|
|
}
|
|
|
|
|
2021-10-18 01:11:04 +02:00
|
|
|
void goToPost(BuildContext context, String instanceHost, int postId) =>
|
|
|
|
Navigator.of(context).push(FullPostPage.route(postId, instanceHost));
|
2020-10-06 22:24:03 +02:00
|
|
|
|
|
|
|
void goToMedia(BuildContext context, String url) => Navigator.push(
|
2020-10-06 17:02:19 +02:00
|
|
|
context,
|
|
|
|
PageRouteBuilder(
|
|
|
|
pageBuilder: (_, __, ___) => MediaViewPage(url),
|
|
|
|
transitionDuration: const Duration(milliseconds: 300),
|
2021-02-08 12:15:48 +01:00
|
|
|
opaque: false,
|
2020-10-06 17:02:19 +02:00
|
|
|
transitionsBuilder: (_, animation, __, child) =>
|
|
|
|
FadeTransition(opacity: animation, child: child),
|
|
|
|
),
|
|
|
|
);
|