replace route pages with cupertino ones

This commit is contained in:
shilangyu 2020-09-16 22:53:04 +02:00
parent fc52ce91a8
commit d3eee1e837
8 changed files with 54 additions and 38 deletions

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:provider/provider.dart';
import 'pages/instance.dart';
import 'stores/accounts_store.dart';
import 'stores/config_store.dart';
@ -51,7 +52,9 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter hello world'),
home: InstancePage(
instanceUrl: 'dev.lemmy.ml',
),
);
},
);

View File

@ -1,5 +1,6 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:esys_flutter_share/esys_flutter_share.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:intl/intl.dart';
@ -272,10 +273,11 @@ class _AboutTab extends HookWidget {
}
void goToBannedUsers(BuildContext c) {
Navigator.of(c).push(MaterialPageRoute(
builder: (_) => UsersListPage(
goTo(
c,
(_) => UsersListPage(
users: site.banned.reversed.toList(), title: 'Banned users'),
));
);
}
@override
@ -284,11 +286,12 @@ class _AboutTab extends HookWidget {
final commSnap = useFuture(communitiesFuture);
void goToCommunities() {
Navigator.of(context).push(MaterialPageRoute(
builder: (_) => CommunitiesListPage(
goTo(
context,
(_) => CommunitiesListPage(
communities: commSnap.data,
title: 'Communities of ${site.site.name}'),
));
);
}
return SingleChildScrollView(

View File

@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
@ -5,6 +6,7 @@ import 'package:provider/provider.dart';
import '../stores/accounts_store.dart';
import '../util/api_extensions.dart';
import '../util/goto.dart';
import '../widgets/bottom_modal.dart';
import '../widgets/user_profile.dart';
import 'settings.dart';
@ -27,8 +29,7 @@ class UserProfileTab extends HookWidget {
Text('No account was added.'),
FlatButton.icon(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (_) => AccountsConfigPage()));
goTo(context, (_) => AccountsConfigPage());
},
icon: Icon(Icons.add),
label: Text('Add account'),
@ -113,8 +114,7 @@ class UserProfileTab extends HookWidget {
IconButton(
icon: Icon(Icons.settings),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => SettingsPage()));
goTo(context, (_) => SettingsPage());
},
)
],

View File

@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
@ -5,6 +6,7 @@ import 'package:provider/provider.dart';
import '../stores/accounts_store.dart';
import '../stores/config_store.dart';
import '../util/goto.dart';
class SettingsPage extends StatelessWidget {
@override
@ -26,16 +28,14 @@ class SettingsPage extends StatelessWidget {
leading: Icon(Icons.person),
title: Text('Accounts'),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => AccountsConfigPage()));
goTo(context, (_) => AccountsConfigPage());
},
),
ListTile(
leading: Icon(Icons.color_lens),
title: Text('Appearance'),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => AppearanceConfigPage()));
goTo(context, (_) => AppearanceConfigPage());
},
)
],

View File

@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart' as ul;
@ -7,6 +8,7 @@ import 'pages/full_post.dart';
import 'pages/instance.dart';
import 'pages/user.dart';
import 'stores/accounts_store.dart';
import 'util/goto.dart';
Future<void> linkLauncher({
@required BuildContext context,
@ -14,7 +16,7 @@ Future<void> linkLauncher({
@required String instanceUrl,
}) async {
push(Widget Function() builder) {
Navigator.of(context).push(MaterialPageRoute(builder: (c) => builder()));
goTo(context, (c) => builder());
}
final instances = context.read<AccountsStore>().users.keys.toList();

View File

@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../pages/community.dart';
@ -5,41 +6,46 @@ import '../pages/full_post.dart';
import '../pages/instance.dart';
import '../pages/user.dart';
void goToInstance(BuildContext context, String instanceUrl) =>
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => InstancePage(instanceUrl: instanceUrl),
Future<dynamic> goTo(
BuildContext context,
Widget Function(BuildContext context) builder,
) =>
Navigator.of(context).push(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) =>
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => CommunityPage.fromId(
goTo(
context,
(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(
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) =>
Navigator.of(context).push(MaterialPageRoute(
builder: (context) =>
UserPage(instanceUrl: instanceUrl, userId: 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) =>
Navigator.of(context).push(MaterialPageRoute(
builder: (context) =>
FullPostPage(instanceUrl: instanceUrl, id: postId)));
void goToPost(BuildContext context, String instanceUrl, int postId) => goTo(
context, (context) => FullPostPage(instanceUrl: instanceUrl, id: postId));

View File

@ -1,6 +1,8 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../pages/media_view.dart';
import '../util/goto.dart';
class FullscreenableImage extends StatelessWidget {
final String url;
@ -13,9 +15,7 @@ class FullscreenableImage extends StatelessWidget {
}) : super(key: key);
_onTap(BuildContext c) {
Navigator.of(c).push(MaterialPageRoute(
builder: (context) => MediaViewPage(url),
));
goTo(c, (context) => MediaViewPage(url));
}
@override

View File

@ -1,5 +1,6 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:esys_flutter_share/esys_flutter_share.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
@ -425,9 +426,10 @@ class Post extends StatelessWidget {
child: InkWell(
onTap: fullPost
? null
: () => Navigator.of(context).push(MaterialPageRoute(
builder: (context) => FullPostPage.fromPostView(
post))), //, instanceUrl, post.id),
: () => goTo(
context,
(context) =>
FullPostPage.fromPostView(post)), //, instanceUrl, post.id),
child: Column(
children: [
info(),