lemmur-app-android/lib/util/goto.dart

75 lines
2.4 KiB
Dart
Raw Normal View History

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../pages/community.dart';
2020-09-09 17:49:01 +02:00
import '../pages/full_post.dart';
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-30 19:05:00 +02:00
/// Pushes onto the navigator stack the given widget
Future<dynamic> goTo(
BuildContext context,
Widget Function(BuildContext context) builder,
) =>
Navigator.of(context).push(CupertinoPageRoute(
builder: builder,
));
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,
) =>
Navigator.of(context).pushReplacement(CupertinoPageRoute(
builder: builder,
));
void goToInstance(BuildContext context, String instanceHost) =>
goTo(context, (context) => InstancePage(instanceHost: instanceHost));
// ignore: camel_case_types
abstract class goToCommunity {
/// Navigates to `CommunityPage`
static void byId(
BuildContext context, String instanceHost, int communityId) =>
goTo(
context,
(context) => CommunityPage.fromId(
instanceHost: instanceHost, communityId: communityId),
);
static void byName(
BuildContext context, String instanceHost, String communityName) =>
goTo(
context,
(context) => CommunityPage.fromName(
instanceHost: instanceHost, communityName: communityName),
);
}
// ignore: camel_case_types
abstract class goToUser {
static void byId(BuildContext context, String instanceHost, int userId) =>
goTo(context,
(context) => UserPage(instanceHost: instanceHost, userId: userId));
static void byName(
BuildContext context, String instanceHost, String userName) =>
throw UnimplementedError('need to create UserProfile constructor first');
}
void goToPost(BuildContext context, String instanceHost, int postId) => goTo(
context, (context) => FullPostPage(instanceHost: instanceHost, id: postId));
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),
),
);