feat: add intro screen

This commit is contained in:
problematicconsumer
2023-09-17 00:24:00 +03:30
parent f4177da9f9
commit f3c0978136
5 changed files with 95 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:hiddify/core/prefs/prefs.dart';
import 'package:hiddify/core/router/routes/routes.dart';
import 'package:hiddify/services/deep_link_service.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
@@ -9,6 +10,7 @@ part 'app_router.g.dart';
// TODO: test and improve handling of deep link
@riverpod
GoRouter router(RouterRef ref) {
final introCompleted = ref.watch(introCompletedProvider);
final deepLink = ref.listen(
deepLinkServiceProvider,
(_, next) async {
@@ -28,6 +30,12 @@ GoRouter router(RouterRef ref) {
initialLocation: initialLocation,
debugLogDiagnostics: true,
routes: $routes,
redirect: (context, state) {
if (!introCompleted && state.uri.path != const IntroRoute().location) {
return const IntroRoute().location;
}
return null;
},
);
}

View File

@@ -1,12 +1,14 @@
import 'package:go_router/go_router.dart';
import 'package:hiddify/core/router/routes/desktop_routes.dart' as desktop;
import 'package:hiddify/core/router/routes/mobile_routes.dart' as mobile;
import 'package:hiddify/core/router/routes/shared_routes.dart' as shared;
import 'package:hiddify/utils/utils.dart';
export 'mobile_routes.dart';
export 'shared_routes.dart';
export 'shared_routes.dart' hide $appRoutes;
List<RouteBase> get $routes => [
...shared.$appRoutes,
if (PlatformUtils.isDesktop)
...desktop.$appRoutes
else

View File

@@ -1,11 +1,14 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:hiddify/features/home/view/view.dart';
import 'package:hiddify/features/intro/view/view.dart';
import 'package:hiddify/features/profile_detail/view/view.dart';
import 'package:hiddify/features/profiles/view/view.dart';
import 'package:hiddify/features/proxies/view/view.dart';
import 'package:hiddify/utils/utils.dart';
part 'shared_routes.g.dart';
final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>();
class HomeRoute extends GoRouteData {
@@ -47,6 +50,20 @@ class AddProfileRoute extends GoRouteData {
}
}
@TypedGoRoute<IntroRoute>(path: IntroRoute.path)
class IntroRoute extends GoRouteData {
const IntroRoute();
static const path = '/intro';
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return const MaterialPage(
fullscreenDialog: true,
child: IntroPage(),
);
}
}
class ProfilesRoute extends GoRouteData {
const ProfilesRoute();
static const path = 'profiles';

View File

@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:hiddify/core/core_providers.dart';
import 'package:hiddify/core/prefs/prefs.dart';
import 'package:hiddify/features/common/common.dart';
import 'package:hiddify/gen/assets.gen.dart';
import 'package:hiddify/utils/utils.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sliver_tools/sliver_tools.dart';
class IntroPage extends HookConsumerWidget with PresLogger {
const IntroPage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
return Scaffold(
body: CustomScrollView(
shrinkWrap: true,
slivers: [
const SliverGap(24),
SliverToBoxAdapter(
child: SizedBox(
width: 248,
height: 248,
child: Padding(
padding: const EdgeInsets.all(36),
child: Assets.images.logo.svg(),
),
),
),
SliverCrossAxisConstrained(
maxCrossAxisExtent: 368,
child: MultiSliver(
children: [
const LocalePrefTile(),
const SliverGap(8),
const EnableAnalyticsPrefTile(),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 24,
),
child: FilledButton(
onPressed: () async {
if (!ref.read(enableAnalyticsProvider)) {
loggy.debug("disabling analytics per user request");
await Sentry.close();
}
await ref
.read(introCompletedProvider.notifier)
.update(true);
},
child: Text(t.intro.start),
),
),
],
),
),
],
),
);
}
}

View File

@@ -0,0 +1 @@
export 'intro_page.dart';