Skip to content

Commit

Permalink
core: replace auto_route with go_router (#406)
Browse files Browse the repository at this point in the history
* ft: migrate to go_router
* fix(tests): go_router tests
  • Loading branch information
wizlif committed Jun 6, 2023
1 parent bb85d24 commit 55de4cb
Show file tree
Hide file tree
Showing 51 changed files with 464 additions and 402 deletions.
7 changes: 3 additions & 4 deletions lib/presentation/auth/auth_screen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:auto_route/auto_route.dart';
import 'package:dots_indicator/dots_indicator.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';

import '../../application/auth/auth_bloc.dart';
import '../../application/user/profile/profile_bloc.dart';
import '../routes/app_routes.gr.dart';
import '../routes/app_routes.dart';
import '../shared_widgets/custom_app_bars/custom_appbar.dart';
import '../themes/constants.dart';
import '../utils/context.ext.dart';
Expand Down Expand Up @@ -115,8 +115,7 @@ class AuthPageState extends State<AuthPage> {
);
}

void _authDone(BuildContext context) =>
context.router.replaceAll([const VerifiedRoute()]);
void _authDone(BuildContext context) => context.go(AppPage.verified.path);

void _toPage(int page) => _pageController.animateToPage(
page,
Expand Down
12 changes: 6 additions & 6 deletions lib/presentation/auth/unauthenticated_screen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import '../routes/app_routes.gr.dart';
import '../shared_widgets/pill_button.dart';
import '../themes/constants.dart';
import '../../domain/core/i_settings_repository.dart';
import '../../infrastructure/core/injection.dart';
import '../routes/app_routes.dart';
import '../shared_widgets/pill_button.dart';
import '../themes/constants.dart';

class UnauthenticatedPage extends StatelessWidget {
@override
Expand Down Expand Up @@ -51,7 +51,7 @@ class UnauthenticatedPage extends StatelessWidget {
text: 'Log In',
isEnabled: true,
isLoading: false,
onTap: () => context.router.push(const AuthRoute()),
onTap: () => context.push(AppPage.auth.path),
lightBackground: true,
),
const SizedBox(height: 80),
Expand All @@ -66,7 +66,7 @@ class UnauthenticatedPage extends StatelessWidget {
// Push onboarding screen if first time launching application
final settingsRepository = getIt<ISettingsRepository>();
if (!(await settingsRepository.getWasUserOnboarded())) {
context.router.push(const OnboardingRoute());
context.push(AppPage.onBoarding.path);
}
}
}
6 changes: 2 additions & 4 deletions lib/presentation/auth/widgets/profile_photo.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:io';

import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';

import '../../../application/auth/auth_bloc.dart';
import '../../../application/user/avatar/avatar_bloc.dart';
Expand Down Expand Up @@ -42,9 +42,7 @@ class SelectProfilePhotoState extends State<SelectProfilePhoto> {
uploading: () {
/// TODO: Loading indication
},
uploadSuccess: () {
context.router.pop();
},
uploadSuccess: context.pop,
uploadFailed: () {
/// TODO: Show error snackbar | Implement failures
},
Expand Down
10 changes: 4 additions & 6 deletions lib/presentation/auth/widgets/verified.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:rive/rive.dart';
import 'package:shimmer/shimmer.dart';

import '../../../application/user/profile/profile_bloc.dart';
import '../../../infrastructure/core/injection.dart';
import '../../routes/app_routes.gr.dart';
import '../../routes/app_routes.dart';
import '../../shared_widgets/pill_button.dart';
import '../../shared_widgets/shimmers/title_shimmer_line.dart';
import '../../themes/constants.dart';
Expand Down Expand Up @@ -80,13 +80,11 @@ class VerifiedPage extends StatelessWidget {
),
const SizedBox(height: 40),
PillButton(
onTap: () =>
context.router.replaceAll([const HomeRoute()]),
onTap: () => context.go(AppPage.home.path),
text: 'Go to CrowdActions',
),
TextButton(
onPressed: () =>
context.router.replaceAll([const HomeRoute()]),
onPressed: () => context.go(AppPage.home.path),
child: const Text(
'Show me all CrowdActions',
style: TextStyle(
Expand Down
8 changes: 4 additions & 4 deletions lib/presentation/core/app_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import '../../application/auth/auth_bloc.dart';
import '../../application/user/profile/profile_bloc.dart';
import '../../application/user/profile_tab/profile_tab_bloc.dart';
import '../../infrastructure/core/injection.dart';
import '../routes/app_routes.gr.dart';

import '../routes/app_routes.dart';
import '../themes/themes.dart';

class AppWidget extends StatelessWidget {
Expand Down Expand Up @@ -35,7 +36,7 @@ class AppWidget extends StatelessWidget {
.add(FetchProfileTabInfo());
},
unauthenticated: () {
_appRouter.replaceAll([const UnauthenticatedRoute()]);
_appRouter.router.go(AppPage.unauthenticated.path);
},
orElse: () {},
);
Expand All @@ -44,8 +45,7 @@ class AppWidget extends StatelessWidget {
color: Colors.white,
title: 'CollAction',
theme: lightTheme(),
routerDelegate: _appRouter.delegate(),
routeInformationParser: _appRouter.defaultRouteParser(),
routerConfig: _appRouter.router,
),
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import '../../../core/core.dart';
import '../../../domain/crowdaction/crowdaction_comment.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CommentAppBarDelegate extends SliverPersistentHeaderDelegate {
child: IconButton(
icon: const Icon(CollactionIcons.left),
iconSize: 24,
onPressed: () => context.router.pop(),
onPressed: context.pop,
color: Colors.white,
),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import '../../../shared_widgets/pill_button.dart';
import '../../../shared_widgets/selectable_chip.dart';
Expand Down Expand Up @@ -145,7 +145,7 @@ class FlagDialogState extends State<FlagDialog> {
width: double.infinity,
height: 52,
child: TextButton(
onPressed: () => context.router.pop(),
onPressed: context.pop,
child: const Text("Cancel"),
),
),
Expand Down Expand Up @@ -217,9 +217,7 @@ class FlagSuccess extends StatelessWidget {
),
PillButton(
text: "Got it",
onTap: () {
context.router.pop();
},
onTap: context.pop,
margin: EdgeInsets.zero,
),
const SizedBox(height: 20),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';

import '../../../../domain/crowdaction/crowdaction.dart';
import '../../../../infrastructure/core/injection.dart';
import '../../../application/auth/auth_bloc.dart';
import '../../../application/crowdaction/crowdaction_details/crowdaction_details_bloc.dart';
import '../../../application/participation/participation_bloc.dart';
import '../../../application/user/profile_tab/profile_tab_bloc.dart';
import '../../routes/app_routes.gr.dart';

import '../../routes/app_routes.dart';
import '../../shared_widgets/commitments/commitment_card_list.dart';
import '../../shared_widgets/pill_button.dart';
import '../../themes/constants.dart';
Expand Down Expand Up @@ -348,7 +349,6 @@ class CrowdActionDetailsPageState extends State<CrowdActionDetailsPage> {
}

void _createAccount(BuildContext context) {
context.router.pop();
context.router.push(const AuthRoute());
context.go(AppPage.auth.path);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';

import '../../../../../domain/crowdaction/crowdaction.dart';
import '../../../../application/participation/participation_bloc.dart';
Expand Down Expand Up @@ -91,9 +91,7 @@ class ParticipationSuccess extends StatelessWidget {
),
PillButton(
text: "Got it",
onTap: () {
context.router.pop();
},
onTap: context.pop,
margin: EdgeInsets.zero,
),
const SizedBox(height: 20),
Expand Down Expand Up @@ -223,7 +221,7 @@ class ParticipationDialog extends StatelessWidget {
width: double.infinity,
height: 52,
child: TextButton(
onPressed: () => context.router.pop(),
onPressed: context.pop,
child: const Text("Cancel"),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:auto_route/auto_route.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:shimmer/shimmer.dart';

import '../../../../core/core.dart';
Expand Down Expand Up @@ -39,7 +39,7 @@ class CrowdActionDetailsBanner extends StatelessWidget {
elevation: 4,
child: InkWell(
borderRadius: BorderRadius.circular(20),
onTap: () => context.router.pop(),
onTap: context.pop,
child: const Icon(
CollactionIcons.left,
color: kPrimaryColor400,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';

import '../../../../../domain/crowdaction/crowdaction.dart';
import '../../../../application/participation/participation_bloc.dart';
Expand Down Expand Up @@ -164,7 +164,7 @@ class WithdrawParticipation extends StatelessWidget {
width: double.infinity,
height: 52,
child: TextButton(
onPressed: () => context.router.pop(),
onPressed: context.pop,
child: const Text("Cancel"),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';

import '../../../application/crowdaction/crowdaction_participants/crowdaction_participants_bloc.dart';
Expand Down Expand Up @@ -85,7 +85,7 @@ class _CrowdActionParticipantsPageState
Icons.chevron_left,
color: kPrimaryColor200,
),
onPressed: () => context.router.pop(),
onPressed: context.pop,
),
title: const Text(
"Participants",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import '../../../domain/crowdaction/crowdaction.dart';
import '../../shared_widgets/accent_chip.dart';
Expand Down Expand Up @@ -326,9 +326,7 @@ class ComponentsDemoPageState extends State<ComponentsDemoPage> {
width: double.infinity,
height: 52,
child: TextButton(
onPressed: () {
context.router.pop();
},
onPressed: context.pop,
child: const Text("Cancel"),
),
),
Expand Down
16 changes: 8 additions & 8 deletions lib/presentation/demo/demo_screen.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import '../../domain/core/i_settings_repository.dart';
import '../../infrastructure/core/injection.dart';
import '../routes/app_routes.gr.dart';
import '../routes/app_routes.dart';
import '../shared_widgets/rectangle_button.dart';
import 'components_demo/current_user_status_text.dart';

class DemoPage extends StatelessWidget {
DemoPage({super.key});

final settingsRepository = getIt<ISettingsRepository>();
final _pageScrollController = ScrollController();

Expand All @@ -30,23 +31,22 @@ class DemoPage extends StatelessWidget {
const SizedBox(height: 30.0),
RectangleButton(
text: "Reusable Components",
onTap: () => context.router.push(const ComponentsDemoRoute()),
onTap: () => context.push(AppPage.componentsDemo.path),
),
const SizedBox(height: 10.0),
RectangleButton(
text: "Crowdaction Comments",
onTap: () =>
context.router.push(const CrowdActionCommentsRoute()),
onTap: () => context.push(AppPage.commentsDemo.path),
),
const SizedBox(height: 10.0),
RectangleButton(
text: "Contact Form",
onTap: () => context.router.push(const ContactFormRoute()),
onTap: () => context.push(AppPage.contactForm.path),
),
const SizedBox(height: 10.0),
RectangleButton(
text: "Onboarding",
onTap: () => context.router.push(const OnboardingRoute()),
onTap: () => context.push(AppPage.onBoarding.path),
),
const SizedBox(
height: 15.0,
Expand All @@ -57,7 +57,7 @@ class DemoPage extends StatelessWidget {
),
RectangleButton(
text: "Register",
onTap: () => context.router.push(const AuthRoute()),
onTap: () => context.push(AppPage.auth.path),
),
],
),
Expand Down
Loading

0 comments on commit 55de4cb

Please sign in to comment.