Skip to content

Commit

Permalink
rebase: With latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wizlif committed Oct 24, 2022
1 parent 4adad0b commit 2015014
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 123 deletions.
2 changes: 0 additions & 2 deletions lib/presentation/core/routes/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ class AppRouter {
builder: (BuildContext context, GoRouterState state) {
final extra = state.extra as Map<String, Object?>? ?? {};
final crowdAction = extra['crowdAction'] as CrowdAction?;
final viewOnly = extra['viewOnly'] as bool? ?? false;

return CrowdActionDetailsPage(
crowdAction: crowdAction,
crowdActionId: crowdAction?.id,
viewOnly: viewOnly,
);
},
),
Expand Down
78 changes: 11 additions & 67 deletions lib/presentation/home/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,80 +1,24 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import '../../../presentation/themes/constants.dart';
import '../../domain/core/i_settings_repository.dart';
import '../../infrastructure/core/injection.dart';
import '../core/collaction_icons.dart';
import '../routes/app_routes.gr.dart';
import '../core/routes/app_page.dart';
import '../themes/constants.dart';

class HomePage extends StatefulWidget {
const HomePage({super.key});
part 'widgets/home_nav.dart';

@override
_HomePageState createState() => _HomePageState();
}
class HomePage extends StatelessWidget {
// Current display page
final Widget child;

class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
checkAndMaybeShowOnboarding();
});
}
const HomePage({super.key, required this.child});

@override
Widget build(BuildContext context) {
return AutoTabsScaffold(
routes: const [
CrowdactionRouter(),
UserProfileRouter(),
if (!kReleaseMode) ...[
DemoScreenRouter(),
],
],
bottomNavigationBuilder: (_, tabsRouter) => bottomNavbar(tabsRouter),
);
}

Future<void> checkAndMaybeShowOnboarding() async {
// Push onboarding screen if first time launching application
final settingsRepository = getIt<ISettingsRepository>();
if (!(await settingsRepository.getWasUserOnboarded())) {
context.router.push(const OnboardingRoute());
}
}

Widget bottomNavbar(TabsRouter tabsRouter) {
return BottomNavigationBar(
backgroundColor: Colors.white,
showSelectedLabels: false,
showUnselectedLabels: false,
selectedItemColor: kEnabledButtonColor,
unselectedItemColor: kDisabledButtonColor,
type: BottomNavigationBarType.fixed,
elevation: 0,
items: const [
BottomNavigationBarItem(
icon: Icon(CollactionIcons.collaction),
label: '',
),
BottomNavigationBarItem(
icon: Icon(CollactionIcons.user),
label: '',
),
if (!kReleaseMode) ...[
BottomNavigationBarItem(
icon: Icon(
Icons.assignment_outlined,
),
label: '',
),
],
],
currentIndex: tabsRouter.activeIndex,
onTap: tabsRouter.setActiveIndex,
return Scaffold(
body: child,
bottomNavigationBar: bottomNavbar(context),
);
}
}
11 changes: 4 additions & 7 deletions lib/presentation/home/widgets/current_upcoming_layout.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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/crowdaction/spotlight/spotlight_bloc.dart';
import '../../routes/app_routes.gr.dart';
import '../../core/routes/app_page.dart';
import '../../shared_widgets/content_placeholder.dart';
import '../../shared_widgets/micro_crowdaction_card.dart';
import '../../themes/constants.dart';
Expand Down Expand Up @@ -51,11 +51,8 @@ class _CurrentAndUpcomingLayoutState extends State<CurrentAndUpcomingLayout> {
),
),
TextButton(
onPressed: () => context.router.push(
widget.isCurrent
? const CrowdActionBrowseRoute()
: const CrowdActionBrowseRoute(),
),
onPressed: () =>
context.push(AppPage.crowdActionsList.toPath),
child: const Text(
'View all',
textAlign: TextAlign.center,
Expand Down
26 changes: 18 additions & 8 deletions lib/presentation/home/widgets/password_modal.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:go_router/go_router.dart';

import '../../../domain/core/i_settings_repository.dart';
import '../../../domain/crowdaction/crowdaction.dart';
import '../../../infrastructure/core/injection.dart';
import '../../../presentation/core/collaction_icons.dart';
import '../../../presentation/routes/app_routes.gr.dart';
import '../../../presentation/themes/constants.dart';
import '../../core/routes/app_page.dart';

class PasswordModal extends StatefulWidget {
final CrowdAction crowdAction;
Expand Down Expand Up @@ -147,10 +147,13 @@ class _PasswordModalState extends State<PasswordModal> {

addCrowdActionAccess();

context.router.replace(
CrowdActionDetailsRoute(
crowdAction: widget.crowdAction,
),
// TODO - Replace with ID
Navigator.of(context).pop();
context.push(
AppPage.crowdActionDetails.toPath,
extra: <String, Object?>{
'crowdAction': widget.crowdAction,
},
);
} else {
setState(() => _validated = false);
Expand Down Expand Up @@ -179,8 +182,15 @@ Future<void> showPasswordModal(
final accessList = await settingsRepository.getCrowdActionAccessList();

if (accessList.contains(crowdAction.id)) {
context.router.push(
CrowdActionDetailsRoute(crowdAction: crowdAction),
// if (!context.mounted) return;
// TODO: Use id
// TODO: Fix async context access
//ignore: use_build_context_synchronously
context.push(
AppPage.crowdActionDetails.toPath,
extra: <String, Object?>{
'crowdAction': crowdAction,
},
);
} else {
showModalBottomSheet(
Expand Down
16 changes: 8 additions & 8 deletions lib/presentation/profile/profile_screen.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import 'dart:io';

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

import '../../application/auth/auth_bloc.dart';
import '../../application/user/profile/profile_bloc.dart';
import '../core/collaction_icons.dart';
import '../routes/app_routes.gr.dart';
import '../core/routes/app_page.dart';
import '../shared_widgets/photo_selector.dart';
import '../shared_widgets/pill_button.dart';
import '../themes/constants.dart';
Expand Down Expand Up @@ -78,7 +78,7 @@ class _UserProfilePageState extends State<UserProfilePage> {
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () => context.router.push(const SettingsRoute()),
onPressed: () => context.push(AppPage.settings.toPath),
style: ElevatedButton.styleFrom(
foregroundColor: kPrimaryColor0,
backgroundColor: Colors.white,
Expand Down Expand Up @@ -147,7 +147,7 @@ class _UserProfilePageState extends State<UserProfilePage> {
builder: (context) => PhotoSelector(
onSelected: (image) {
setState(() => _image = image);
context.router.pop("dialog");
context.pop();
},
),
);
Expand Down Expand Up @@ -366,14 +366,14 @@ class _UserProfilePageState extends State<UserProfilePage> {
const SizedBox(height: 40),
PillButton(
text: 'Create account or sign in',
onTap: () => context.router
.push(const AuthRoute())
.then((_) {
onTap: () {
context.push(AppPage.auth.toPath);

// Refresh profile
context
.read<ProfileBloc>()
.add(GetUserProfile());
}),
},
),
],
const SizedBox(height: 20),
Expand Down
15 changes: 6 additions & 9 deletions lib/presentation/settings/settings_screen.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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/settings/build_information/build_information_bloc.dart';
import '../../../presentation/utils/launch_url.dart';
import '../../application/auth/auth_bloc.dart';
import '../../application/user/profile/profile_bloc.dart';
import '../../infrastructure/core/injection.dart';
import '../core/collaction_icons.dart';
import '../routes/app_routes.gr.dart';
import '../core/routes/app_page.dart';
import '../shared_widgets/custom_app_bars/custom_appbar.dart';
import '../themes/constants.dart';
import 'widgets/build_information_tile.dart';
Expand Down Expand Up @@ -65,24 +65,21 @@ class SettingsPage extends StatelessWidget {
title: 'Contact us',
icon: CollactionIcons.message,
trailingIcon: CollactionIcons.arrow_right,
onTap: () =>
context.router.push(const ContactFormRoute()),
onTap: () => context.push(AppPage.contactForm.toPath),
),
const SizedBox(height: 15),
SettingsListTile(
title: 'Onboarding',
icon: CollactionIcons.rocket,
trailingIcon: CollactionIcons.arrow_right,
onTap: () =>
context.router.push(const OnboardingRoute()),
onTap: () => context.push(AppPage.onBoarding.toPath),
),
const SizedBox(height: 15),
SettingsListTile(
title: 'Open source libraries',
icon: CollactionIcons.opensource,
trailingIcon: CollactionIcons.arrow_right,
onTap: () =>
context.router.push(const LicensesRoute()),
onTap: () => context.push(AppPage.licenses.toPath),
),
const SizedBox(height: 15),
SettingsListTile(
Expand Down Expand Up @@ -122,7 +119,7 @@ class SettingsPage extends StatelessWidget {
onTap: () async {
BlocProvider.of<AuthBloc>(context)
.add(const AuthEvent.signedOut());
await context.router.pop();
context.pop();
},
),
],
Expand Down
14 changes: 8 additions & 6 deletions lib/presentation/shared_widgets/micro_crowdaction_card.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:auto_route/auto_route.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:go_router/go_router.dart';

import '../../domain/crowdaction/crowdaction.dart';
import '../core/routes/app_page.dart';
import '../home/widgets/password_modal.dart';
import '../routes/app_routes.gr.dart';
import '../themes/constants.dart';
import 'accent_chip.dart';
import 'micro_lock.dart';
Expand All @@ -25,10 +25,12 @@ class MicroCrowdActionCard extends StatelessWidget {
if (crowdAction.hasPassword) {
showPasswordModal(context, crowdAction);
} else {
context.router.push(
CrowdActionDetailsRoute(
crowdActionId: crowdAction.id,
),
// TODO: Use ID & extras
context.push(
AppPage.crowdActionDetails.toPath,
extra: <String, Object?>{
'crowdAction': crowdAction,
},
);
}
},
Expand Down
21 changes: 7 additions & 14 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.9.0"
auto_route:
dependency: "direct main"
description:
name: auto_route
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.2"
auto_route_generator:
dependency: "direct dev"
description:
name: auto_route_generator
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.2"
bloc:
dependency: "direct main"
description:
Expand Down Expand Up @@ -506,6 +492,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
go_router:
dependency: "direct main"
description:
name: go_router
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.1"
graphs:
dependency: transitive
description:
Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ environment:
sdk: ">=2.18.2 <3.0.0"

dependencies:
auto_route: ^5.0.2
bloc: ^8.1.0
cached_network_image: ^3.2.2
country_codes: ^2.2.0
Expand All @@ -40,6 +39,7 @@ dependencies:
flutter_dotenv: ^5.0.2
freezed_annotation: ^2.2.0
get_it: ^7.2.0
go_router: ^5.1.1
http: ^0.13.5
image: ^3.2.2
image_cropper: ^3.0.0
Expand All @@ -60,7 +60,6 @@ dependencies:
webview_flutter: ^3.0.4

dev_dependencies:
auto_route_generator: ^5.0.2
bloc_test: ^9.1.0
build_runner: ^2.3.0
firebase_auth_mocks: ^0.8.6
Expand Down

0 comments on commit 2015014

Please sign in to comment.