Skip to content

Commit

Permalink
add empty biometric setup page
Browse files Browse the repository at this point in the history
  • Loading branch information
youngbryanyu committed Mar 5, 2024
1 parent ee38832 commit 0bde3a2
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 17 deletions.
30 changes: 30 additions & 0 deletions frontend/lib/common/components/buttons/small_round_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter/material.dart';

/* A small round button holding any text */
class SmallRoundButton extends StatelessWidget {
final String title;
final VoidCallback onPressed;

const SmallRoundButton({
super.key,
required this.title,
required this.onPressed,
});

@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
),
backgroundColor: Theme.of(context).colorScheme.primary,
),
child: Text(
title,
style: Theme.of(context).textTheme.labelLarge,
),
);
}
}
3 changes: 1 addition & 2 deletions frontend/lib/features/auth/pages/auth_page_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class AuthPageSelector extends ConsumerWidget {
}
} else {
/* User is logged in */
return const SyncingPageSelector();
// return HomePage();
return const SyncingPageSelector(); /* Always sync when app starts */
}
},
loading: () => const CircularProgressIndicator(),
Expand Down
2 changes: 2 additions & 0 deletions frontend/lib/features/home/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class HomePage extends ConsumerWidget {
ref.read(authPageStateProvider.notifier).state = AuthPageState.login;

// TODO: notify user if not all data has been synced with server yet

// TODO: move this to a central shared file
}

@override
Expand Down
69 changes: 69 additions & 0 deletions frontend/lib/features/onboarding/pages/enter_biometrics_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:frontend/common/components/buttons/small_round_button.dart';
import 'package:frontend/features/auth/providers/auth_page_state_provider.dart';

class EnterBiometricsPage extends ConsumerWidget {
const EnterBiometricsPage({super.key});

void signOutUser(WidgetRef ref) async {
FirebaseAuth.instance.signOut();
ref.read(authPageStateProvider.notifier).state = AuthPageState.login;

// TODO: notify user if not all data has been synced with server yet

// TODO: move this to a central shared file
}

@override
Widget build(BuildContext context, WidgetRef ref) {
/* Get the screen height */
double screenHeight = MediaQuery.of(context).size.height;
// Controllers for form fields
final TextEditingController birthdayController = TextEditingController();
// Add controllers for other fields as needed

return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.background,
title: Text(
"Profile Setup",
style: Theme.of(context).textTheme.displaySmall,
)),
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Birthday",
style: TextStyle(fontSize: 16),
),
TextField(
controller: birthdayController,
decoration: const InputDecoration(
hintText: 'YYYY-MM-DD',
),
),
// Add other fields (sex, height, weight, etc.) here
SizedBox(height: screenHeight * .01),

/* Save button */
Align(
alignment: Alignment.centerRight,
child: SmallRoundButton(
title: "Save",
onPressed: () {
signOutUser(ref);
},
),
)
],
),
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:frontend/features/home/pages/home_page_selector.dart";
import "package:frontend/features/onboarding/pages/enter_biometrics_page.dart";
import "package:frontend/features/onboarding/pages/welcome_page.dart";
import "package:frontend/features/onboarding/providers/onboarding_page_state_provider.dart";

Expand All @@ -21,6 +22,8 @@ class OnboardingPageSelector extends ConsumerWidget {
switch (pageState) {
case OnboardingPageState.welcome:
return const WelcomePage();
case OnboardingPageState.enterBiometrics:
return const EnterBiometricsPage();
default:
return const HomePageSelector();
}
Expand Down
31 changes: 18 additions & 13 deletions frontend/lib/features/onboarding/pages/welcome_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:frontend/features/syncing/providers/syncing_page_state_provider.dart';
import 'package:frontend/common/components/buttons/small_round_button.dart';
import 'package:frontend/features/onboarding/providers/onboarding_page_state_provider.dart';

/* Welcome page shown before user onboards */
class WelcomePage extends ConsumerWidget {
const WelcomePage({super.key});

Expand All @@ -19,23 +21,26 @@ class WelcomePage extends ConsumerWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
/* Title text */
Text(
"Let's get you set up",
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
style: Theme.of(context).textTheme.displayLarge,
),
SizedBox(height: screenHeight * .01),
ElevatedButton(
// TODO: navigate to next page instead of home
Text(
"Looks like you haven't set up your profile yet",
style: Theme.of(context).textTheme.bodyMedium,
),
SizedBox(height: screenHeight * .01),

/* Next page button */
SmallRoundButton(
title: "Next",
onPressed: () {
ref.read(syncingPageStateProvider.notifier).state =
SyncingPageState.home;
ref.read(onboardingPageStateProvider.notifier).state =
OnboardingPageState.enterBiometrics;
},
child: const Text('Next'),
// TODO create button (use auth buttom)
),
)
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
/* States for which auth page the user is on */
enum OnboardingPageState {
welcome,
enterBiometrics,
finishOnboarding,
customMacros,
}

/* Listen for state changes for which onboarding page the user is on */
Expand Down
6 changes: 6 additions & 0 deletions frontend/lib/features/syncing/pages/syncing_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:frontend/common/services/api/user_api_service.dart';
import 'package:frontend/common/services/realm/user_realm_service.dart';
import 'package:frontend/features/auth/providers/auth_page_state_provider.dart';
import 'package:frontend/features/onboarding/providers/onboarding_page_state_provider.dart';
import 'package:frontend/features/syncing/providers/syncing_page_state_provider.dart';
import 'package:frontend/logging/logger.dart';

Expand Down Expand Up @@ -36,6 +37,8 @@ class SyncingPage extends ConsumerWidget {
if (userData == null) {
ref.read(syncingPageStateProvider.notifier).state =
SyncingPageState.onboarding;
ref.read(onboardingPageStateProvider.notifier).state =
OnboardingPageState.welcome;
return;
}

Expand Down Expand Up @@ -70,6 +73,7 @@ class SyncingPage extends ConsumerWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
/* Loading circle*/
const CircularProgressIndicator(),
SizedBox(height: screenHeight * .01),
Text(
Expand All @@ -80,6 +84,8 @@ class SyncingPage extends ConsumerWidget {
),
),
SizedBox(height: screenHeight * .01),

/* Cancel button */
GestureDetector(
onTap: () {
signOutUser(ref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SyncingPageSelector extends ConsumerWidget {
case SyncingPageState.home:
return const HomePageSelector();
default:
return const HomePageSelector();
return const SyncingPage();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';

/* States for which syncing page the user is on */
enum SyncingPageState { syncing, onboarding, home }
enum SyncingPageState {
syncing,
onboarding,
home,
}

/* Listen for state changes for which onboarding page the user is on */
final syncingPageStateProvider = StateProvider<SyncingPageState>((ref) {
Expand Down

0 comments on commit 0bde3a2

Please sign in to comment.