73 lines
2.3 KiB
Dart
73 lines
2.3 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../pages/community.dart';
|
|
import '../pages/full_post.dart';
|
|
import '../pages/instance.dart';
|
|
import '../pages/media_view.dart';
|
|
import '../pages/user.dart';
|
|
|
|
/// 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,
|
|
));
|
|
|
|
/// Replaces the top of the navigator stack with the given widget
|
|
Future<dynamic> goToReplace(
|
|
BuildContext context,
|
|
Widget Function(BuildContext context) builder,
|
|
) =>
|
|
Navigator.of(context).pushReplacement(CupertinoPageRoute(
|
|
builder: builder,
|
|
));
|
|
|
|
void goToInstance(BuildContext context, String instanceUrl) =>
|
|
goTo(context, (context) => InstancePage(instanceUrl: instanceUrl));
|
|
|
|
// ignore: camel_case_types
|
|
abstract class goToCommunity {
|
|
/// Navigates to `CommunityPage`
|
|
static void byId(BuildContext context, String instanceUrl, int communityId) =>
|
|
goTo(
|
|
context,
|
|
(context) => CommunityPage.fromId(
|
|
instanceUrl: instanceUrl, communityId: communityId),
|
|
);
|
|
|
|
static void byName(
|
|
BuildContext context, String instanceUrl, String communityName) =>
|
|
goTo(
|
|
context,
|
|
(context) => CommunityPage.fromName(
|
|
instanceUrl: instanceUrl, communityName: communityName),
|
|
);
|
|
}
|
|
|
|
// ignore: camel_case_types
|
|
abstract class goToUser {
|
|
static void byId(BuildContext context, String instanceUrl, int userId) =>
|
|
goTo(context,
|
|
(context) => UserPage(instanceUrl: instanceUrl, userId: userId));
|
|
|
|
static void byName(
|
|
BuildContext context, String instanceUrl, String userName) =>
|
|
throw UnimplementedError('need to create UserProfile constructor first');
|
|
}
|
|
|
|
void goToPost(BuildContext context, String instanceUrl, int postId) => goTo(
|
|
context, (context) => FullPostPage(instanceUrl: instanceUrl, id: postId));
|
|
|
|
void goToMedia(BuildContext context, String url) => Navigator.push(
|
|
context,
|
|
PageRouteBuilder(
|
|
pageBuilder: (_, __, ___) => MediaViewPage(url),
|
|
transitionDuration: const Duration(milliseconds: 300),
|
|
transitionsBuilder: (_, animation, __, child) =>
|
|
FadeTransition(opacity: animation, child: child),
|
|
),
|
|
);
|