Create universal functions for going to common pages
This commit is contained in:
parent
c302d7dd5d
commit
1162fb1cd7
|
@ -2,6 +2,8 @@ import 'package:cached_network_image/cached_network_image.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
||||
|
||||
import '../util/api_extensions.dart';
|
||||
import '../util/goto.dart';
|
||||
import '../widgets/markdown_text.dart';
|
||||
|
||||
class CommunitiesListPage extends StatelessWidget {
|
||||
|
@ -12,10 +14,6 @@ class CommunitiesListPage extends StatelessWidget {
|
|||
: assert(communities != null),
|
||||
super(key: key);
|
||||
|
||||
void goToCommunity(BuildContext context, int id) {
|
||||
print('GO TO COMMUNITY $id');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
@ -36,7 +34,8 @@ class CommunitiesListPage extends StatelessWidget {
|
|||
child: MarkdownText(communities[i].description),
|
||||
)
|
||||
: null,
|
||||
onTap: () => goToCommunity(context, communities[i].id),
|
||||
onTap: () => goToCommunity.byId(
|
||||
context, communities[i].instanceUrl, communities[i].id),
|
||||
leading: communities[i].icon != null
|
||||
? CachedNetworkImage(
|
||||
height: 50,
|
||||
|
|
|
@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
||||
|
||||
import '../util/api_extensions.dart';
|
||||
import '../util/goto.dart';
|
||||
import '../util/intl.dart';
|
||||
import '../util/text_color.dart';
|
||||
import '../widgets/badge.dart';
|
||||
|
@ -28,15 +30,11 @@ class CommunityPage extends HookWidget {
|
|||
LemmyApi(instanceUrl).v1.getCommunity(id: communityId),
|
||||
_community = null;
|
||||
CommunityPage.fromCommunityView(this._community)
|
||||
: instanceUrl = _community.actorId.split('/')[2],
|
||||
_fullCommunityFuture = LemmyApi(_community.actorId.split('/')[2])
|
||||
: instanceUrl = _community.instanceUrl,
|
||||
_fullCommunityFuture = LemmyApi(_community.instanceUrl)
|
||||
.v1
|
||||
.getCommunity(name: _community.name);
|
||||
|
||||
void _goToInstance() {
|
||||
print('GO TO INSTANCE');
|
||||
}
|
||||
|
||||
void _subscribe() {
|
||||
print('SUBSCRIBE');
|
||||
}
|
||||
|
@ -115,7 +113,6 @@ class CommunityPage extends HookWidget {
|
|||
background: _CommunityOverview(
|
||||
community,
|
||||
instanceUrl: instanceUrl,
|
||||
goToInstance: _goToInstance,
|
||||
subscribe: _subscribe,
|
||||
),
|
||||
),
|
||||
|
@ -162,13 +159,11 @@ class CommunityPage extends HookWidget {
|
|||
class _CommunityOverview extends StatelessWidget {
|
||||
final CommunityView community;
|
||||
final String instanceUrl;
|
||||
final void Function() goToInstance;
|
||||
final void Function() subscribe;
|
||||
|
||||
_CommunityOverview(
|
||||
this.community, {
|
||||
@required this.instanceUrl,
|
||||
@required this.goToInstance,
|
||||
@required this.subscribe,
|
||||
}) : assert(instanceUrl != null),
|
||||
assert(goToInstance != null),
|
||||
|
@ -252,7 +247,7 @@ class _CommunityOverview extends StatelessWidget {
|
|||
text: instanceUrl,
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = goToInstance),
|
||||
..onTap = () => goToInstance(context, instanceUrl)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -362,10 +357,6 @@ class _AboutTab extends StatelessWidget {
|
|||
@required this.moderators,
|
||||
}) : super(key: key);
|
||||
|
||||
void goToUser(int id) {
|
||||
print('GO TO USER $id');
|
||||
}
|
||||
|
||||
void goToModlog() {
|
||||
print('GO TO MODLOG');
|
||||
}
|
||||
|
@ -441,7 +432,7 @@ class _AboutTab extends StatelessWidget {
|
|||
for (final mod in moderators)
|
||||
ListTile(
|
||||
title: Text(mod.userPreferredUsername ?? '@${mod.userName}'),
|
||||
onTap: () => goToUser(mod.id),
|
||||
onTap: () => goToUser.byId(context, mod.instanceUrl, mod.id),
|
||||
),
|
||||
]
|
||||
],
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
||||
|
||||
import '../util/api_extensions.dart';
|
||||
import '../widgets/comment_section.dart';
|
||||
import '../widgets/post.dart';
|
||||
|
||||
|
@ -16,9 +17,7 @@ class FullPostPage extends HookWidget {
|
|||
fullPost = LemmyApi(instanceUrl).v1.getPost(id: id),
|
||||
post = null;
|
||||
FullPostPage.fromPostView(this.post)
|
||||
: fullPost = LemmyApi(post.communityActorId.split('/')[2])
|
||||
.v1
|
||||
.getPost(id: post.id);
|
||||
: fullPost = LemmyApi(post.instanceUrl).v1.getPost(id: post.id);
|
||||
|
||||
void sharePost() => Share.text('Share post', post.apId, 'text/plain');
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ import 'package:intl/intl.dart';
|
|||
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
||||
import 'package:url_launcher/url_launcher.dart' as ul;
|
||||
|
||||
import '../util/api_extensions.dart';
|
||||
import '../util/goto.dart';
|
||||
import '../util/text_color.dart';
|
||||
import '../widgets/badge.dart';
|
||||
import '../widgets/bottom_modal.dart';
|
||||
|
@ -256,10 +258,6 @@ class _AboutTab extends HookWidget {
|
|||
));
|
||||
}
|
||||
|
||||
void goToCommunity(int id) {
|
||||
print('GO TO COMMUNITY $id');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
@ -309,7 +307,8 @@ class _AboutTab extends HookWidget {
|
|||
),
|
||||
if (commSnap.hasData)
|
||||
...commSnap.data.getRange(0, 6).map((e) => ListTile(
|
||||
onTap: () => goToCommunity(e.id),
|
||||
onTap: () =>
|
||||
goToCommunity.byId(context, e.instanceUrl, e.id),
|
||||
title: Text(e.name),
|
||||
leading: e.icon != null
|
||||
? CachedNetworkImage(
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:flutter_mobx/flutter_mobx.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../stores/accounts_store.dart';
|
||||
import '../util/api_extensions.dart';
|
||||
import '../widgets/bottom_modal.dart';
|
||||
import '../widgets/user_profile.dart';
|
||||
import 'settings.dart';
|
||||
|
@ -81,7 +82,7 @@ class UserProfileTab extends HookWidget {
|
|||
return Observer(
|
||||
builder: (ctx) {
|
||||
var user = ctx.watch<AccountsStore>().defaultUser;
|
||||
var instanceUrl = user.actorId.split('/')[2];
|
||||
var instanceUrl = user.instanceUrl;
|
||||
|
||||
return BottomModal(
|
||||
title: 'account',
|
||||
|
@ -120,7 +121,7 @@ class UserProfileTab extends HookWidget {
|
|||
),
|
||||
body: UserProfile(
|
||||
userId: user.id,
|
||||
instanceUrl: user.actorId.split('/')[2],
|
||||
instanceUrl: user.instanceUrl,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../pages/community.dart';
|
||||
import '../pages/instance.dart';
|
||||
import '../widgets/user_profile.dart';
|
||||
|
||||
void goToInstance(BuildContext context, String instanceUrl) =>
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => InstancePage(instanceUrl: instanceUrl),
|
||||
));
|
||||
|
||||
// ignore: camel_case_types
|
||||
abstract class goToCommunity {
|
||||
/// Navigates to `CommunityPage`
|
||||
static void byId(BuildContext context, String instanceUrl, int communityId) =>
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => CommunityPage.fromId(
|
||||
instanceUrl: instanceUrl, communityId: communityId),
|
||||
));
|
||||
|
||||
static void byName(
|
||||
BuildContext context, String instanceUrl, String communityName) =>
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => CommunityPage.fromName(
|
||||
instanceUrl: instanceUrl, communityName: communityName),
|
||||
));
|
||||
}
|
||||
|
||||
// ignore: camel_case_types
|
||||
abstract class goToUser {
|
||||
static void byId(BuildContext context, String instanceUrl, int userId) =>
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
UserProfile(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) =>
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
UserProfile(instanceUrl: instanceUrl, userId: postId)));
|
|
@ -1,9 +1,11 @@
|
|||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lemmur/util/goto.dart';
|
||||
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
import '../comment_tree.dart';
|
||||
import '../util/api_extensions.dart';
|
||||
import '../util/text_color.dart';
|
||||
import 'markdown_text.dart';
|
||||
|
||||
|
@ -21,10 +23,6 @@ class Comment extends StatelessWidget {
|
|||
print('OPEN MORE MENU');
|
||||
}
|
||||
|
||||
void _goToUser() {
|
||||
print('GO TO USER');
|
||||
}
|
||||
|
||||
void _save(bool save) {
|
||||
print('SAVE COMMENT, $save');
|
||||
}
|
||||
|
@ -83,7 +81,8 @@ class Comment extends StatelessWidget {
|
|||
Padding(
|
||||
padding: const EdgeInsets.only(right: 5),
|
||||
child: InkWell(
|
||||
onTap: _goToUser,
|
||||
onTap: () => goToUser.byId(
|
||||
context, comment.instanceUrl, comment.creatorId),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: comment.creatorAvatar,
|
||||
height: 20,
|
||||
|
@ -105,7 +104,8 @@ class Comment extends StatelessWidget {
|
|||
style: TextStyle(
|
||||
color: Theme.of(context).accentColor,
|
||||
)),
|
||||
onLongPress: _goToUser,
|
||||
onTap: () => goToUser.byId(
|
||||
context, comment.instanceUrl, comment.creatorId),
|
||||
),
|
||||
if (isOP) _CommentTag('OP', Theme.of(context).accentColor),
|
||||
if (comment.banned) _CommentTag('BANNED', Colors.red),
|
||||
|
|
|
@ -6,8 +6,9 @@ import 'package:intl/intl.dart';
|
|||
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
import '../pages/full_post.dart';
|
||||
import '../url_launcher.dart';
|
||||
import '../util/api_extensions.dart';
|
||||
import '../util/goto.dart';
|
||||
import 'markdown_text.dart';
|
||||
|
||||
enum MediaType {
|
||||
|
@ -36,34 +37,15 @@ class Post extends StatelessWidget {
|
|||
final String postUrlDomain;
|
||||
|
||||
Post(this.post, {this.fullPost = false})
|
||||
: instanceUrl = post.communityActorId.split('/')[2],
|
||||
: instanceUrl = post.instanceUrl,
|
||||
postUrlDomain = post.url != null ? post.url.split('/')[2] : null;
|
||||
|
||||
// == ACTIONS ==
|
||||
|
||||
void _openLink() {
|
||||
print('OPEN LINK');
|
||||
urlLauncher(post.url);
|
||||
}
|
||||
|
||||
void _goToUser() {
|
||||
print('GO TO USER');
|
||||
}
|
||||
|
||||
void _goToPost(BuildContext context) {
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => FullPostPage.fromPostView(post)));
|
||||
}
|
||||
|
||||
void _goToCommunity() {
|
||||
print('GO TO COMMUNITY');
|
||||
}
|
||||
|
||||
void _goToInstance() {
|
||||
print('GO TO INSTANCE');
|
||||
}
|
||||
void _openLink() => urlLauncher(post.url);
|
||||
|
||||
void _openFullImage() {
|
||||
// TODO: fullscreen media view
|
||||
print('OPEN FULL IMAGE');
|
||||
}
|
||||
|
||||
|
@ -104,7 +86,8 @@ class Post extends StatelessWidget {
|
|||
Padding(
|
||||
padding: const EdgeInsets.only(right: 10),
|
||||
child: InkWell(
|
||||
onTap: _goToCommunity,
|
||||
onTap: () => goToCommunity.byId(
|
||||
context, instanceUrl, post.communityId),
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
width: 40,
|
||||
|
@ -144,7 +127,8 @@ class Post extends StatelessWidget {
|
|||
text: post.communityName,
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = _goToCommunity),
|
||||
..onTap = () => goToCommunity.byId(
|
||||
context, instanceUrl, post.communityId)),
|
||||
TextSpan(
|
||||
text: '@',
|
||||
style: TextStyle(fontWeight: FontWeight.w300)),
|
||||
|
@ -152,7 +136,8 @@ class Post extends StatelessWidget {
|
|||
text: instanceUrl,
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = _goToInstance),
|
||||
..onTap =
|
||||
() => goToInstance(context, instanceUrl)),
|
||||
],
|
||||
),
|
||||
)
|
||||
|
@ -173,7 +158,8 @@ class Post extends StatelessWidget {
|
|||
''' ${post.creatorPreferredUsername ?? post.creatorName}''',
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = _goToUser,
|
||||
..onTap = () => goToUser.byId(
|
||||
context, post.instanceUrl, post.creatorId),
|
||||
),
|
||||
TextSpan(
|
||||
text:
|
||||
|
@ -288,11 +274,14 @@ class Post extends StatelessWidget {
|
|||
]),
|
||||
Row(children: [
|
||||
Flexible(
|
||||
child: Text(post.embedTitle,
|
||||
child: Text('${post.embedTitle}',
|
||||
style: theme.textTheme.subtitle1
|
||||
.apply(fontWeightDelta: 2)))
|
||||
]),
|
||||
Row(children: [Flexible(child: Text(post.embedDescription))]),
|
||||
if (post.embedDescription != null)
|
||||
Row(children: [
|
||||
Flexible(child: Text(post.embedDescription))
|
||||
]),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -357,7 +346,7 @@ class Post extends StatelessWidget {
|
|||
borderRadius: BorderRadius.all(Radius.circular(20)),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: fullPost ? null : () => _goToPost(context),
|
||||
onTap: fullPost ? null : () => goToPost(context, instanceUrl, post.id),
|
||||
child: Column(
|
||||
children: [
|
||||
info(),
|
||||
|
|
|
@ -5,6 +5,8 @@ import 'package:intl/intl.dart';
|
|||
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
import '../util/api_extensions.dart';
|
||||
import '../util/goto.dart';
|
||||
import '../util/intl.dart';
|
||||
import '../util/text_color.dart';
|
||||
import 'badge.dart';
|
||||
|
@ -23,7 +25,7 @@ class UserProfile extends HookWidget {
|
|||
|
||||
UserProfile.fromUserView(UserView userView)
|
||||
: _userView = Future.value(userView),
|
||||
instanceUrl = userView.actorId.split('/')[2];
|
||||
instanceUrl = userView.instanceUrl;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -173,9 +175,21 @@ class UserProfile extends HookWidget {
|
|||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
'@${userViewSnap.data?.name ?? ''}@$instanceUrl',
|
||||
style: theme.textTheme.caption,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'@${userViewSnap.data?.name ?? ''}@',
|
||||
style: theme.textTheme.caption,
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => goToInstance(context, instanceUrl),
|
||||
child: Text(
|
||||
'$instanceUrl',
|
||||
style: theme.textTheme.caption,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
|
|
Loading…
Reference in New Issue