Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions lib/core/providers/supabase_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SupabaseService extends StateHandler {
if (user != null) {
// Handle OAuth sign-in flow
if (event == AuthChangeEvent.signedIn) {
_loginSnackShown = true;
await _handleOAuthSignIn(user);
}
await _fetchCurrentUserDetails(
Expand All @@ -39,10 +40,17 @@ class SupabaseService extends StateHandler {

CurrentUser? _currentUser; // Holds the consolidated user data
bool _isDark = false;
bool _loginSnackShown = false;

bool get isDark => _isDark;
CurrentUser? get currentUser => _currentUser;
String get defaultPfpPath => _defaultPfpPath;
bool get loginSnackShown => _loginSnackShown;

void setLoginSnackShown(bool value) {
_loginSnackShown = value;
notifyListeners();
}

// --- Theme Management ---
Future<void> _loadTheme() async {
Expand Down Expand Up @@ -70,7 +78,9 @@ class SupabaseService extends StateHandler {
// If it's an OAuth user and they don't have our custom metadata fields,
// it's their first time.
if (isOAuth && (currentAvatarUrl == null || currentName == null)) {
final String? name = user.userMetadata!['full_name'] as String? ?? user.userMetadata!['name'] as String?;
final String? name =
user.userMetadata!['full_name'] as String? ??
user.userMetadata!['name'] as String?;
final String? avatarUrl = user.userMetadata!['avatar_url'] as String?;

final Map<String, dynamic> updatedData = {};
Expand Down Expand Up @@ -176,8 +186,10 @@ class SupabaseService extends StateHandler {
// and added to your Supabase Auth Providers -> Google -> Redirect URIs
// For desktop, usually 'http://localhost:port' or similar is used.
final String? redirectUrl =
kIsWeb ?
kReleaseMode ? 'http://cookethflow.cookethcompany.xyz/dashboard' : 'http://localhost:3000/dashboard'
kIsWeb
? kReleaseMode
? 'http://cookethflow.cookethcompany.xyz/dashboard'
: 'http://localhost:3000/dashboard'
: (Platform.isAndroid || Platform.isIOS
? 'myapp://login-callback/'
: null); // For mobile/desktop
Expand All @@ -201,8 +213,10 @@ class SupabaseService extends StateHandler {
Future<String> signInWithGithub() async {
try {
final String? redirectUrl =
kIsWeb ?
kReleaseMode ? 'http://cookethflow.cookethcompany.xyz/dashboard' : 'http://localhost:3000/dashboard'
kIsWeb
? kReleaseMode
? 'http://cookethflow.cookethcompany.xyz/dashboard'
: 'http://localhost:3000/dashboard'
: (Platform.isAndroid || Platform.isIOS
? 'my.scheme://my-host'
: null); // Replace with your actual scheme
Expand Down Expand Up @@ -390,8 +404,7 @@ class SupabaseService extends StateHandler {
}

// --- Profile Picture Management ---
final String _profileBucketName =
'profile'; // Renamed bucket for clarity
final String _profileBucketName = 'profile'; // Renamed bucket for clarity
final String _defaultPfpPath =
'assets/images/pfp.png'; // Make sure this asset exists!

Expand Down Expand Up @@ -505,4 +518,4 @@ class SupabaseService extends StateHandler {
}
return null;
}
}
}
4 changes: 3 additions & 1 deletion lib/core/utils/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ enum InteractionMode {
drawingConnector,
}

enum ConnectorAnchor { top, bottom, left, right }
enum ConnectorAnchor { top, bottom, left, right }

enum SnackbarType { success, error, info, warning }
54 changes: 19 additions & 35 deletions lib/features/auth/widgets/login_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:cookethflow/core/providers/supabase_provider.dart';
import 'package:cookethflow/core/router/app_route_const.dart';
import 'package:cookethflow/core/theme/colors.dart';
import 'package:cookethflow/features/auth/providers/auth_provider.dart';
import 'package:cookethflow/features/dashboard/widgets/snackbar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -33,9 +34,7 @@ class LoginForm extends StatelessWidget {
// Check if current route is not already dashboard to prevent loop
context.go(RoutesPath.dashboard);
// context.goNamed(RouteName.dashboard,pathParameters: {'username': supabaseService.currentUser!.name!});
authProvider.setLoading(
false,
);
authProvider.setLoading(false);
});
}

Expand Down Expand Up @@ -150,7 +149,7 @@ class LoginForm extends StatelessWidget {
authProvider.obscurePassword
? PhosphorIconsRegular.eye
: PhosphorIconsRegular.eyeSlash,
size: 24.sp,
size: isMobile ? 45.sp : 24.sp,
),
onPressed: authProvider.toggleObscurePassword,
style: ButtonStyle(
Expand Down Expand Up @@ -193,19 +192,12 @@ class LoginForm extends StatelessWidget {
password: authProvider.passwordController.text,
);
if (res != "Logged in successfully") {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(res),
duration: const Duration(seconds: 5),
),
);
CustomSnackbar.showError(context, res);
}
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(passwordValidationCheck),
duration: const Duration(seconds: 2),
),
CustomSnackbar.showError(
context,
passwordValidationCheck,
);
}
// Navigation handled by the Consumer2's listener
Expand Down Expand Up @@ -265,10 +257,9 @@ class LoginForm extends StatelessWidget {
onPressed: () async {
// Call void method, loading handled by provider
await authProvider.googleAuth();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Initiating Google Sign-In..."),
),
CustomSnackbar.showInfo(
context,
"Initiating Google Sign-In...",
);
// Navigation handled by the Consumer2's listener
},
Expand Down Expand Up @@ -316,10 +307,9 @@ class LoginForm extends StatelessWidget {
onPressed: () async {
// Call void method, loading handled by provider
await authProvider.githubSignin();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Initiating GitHub Sign-In..."),
),
CustomSnackbar.showInfo(
context,
"Initiating GitHub Sign-In...",
);
// Navigation handled by the Consumer2's listener
},
Expand Down Expand Up @@ -377,12 +367,9 @@ class LoginForm extends StatelessWidget {
onPressed: () async {
// Call void method, loading handled by provider
await authProvider.googleAuth();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
"Initiating Google Sign-In...",
),
),
CustomSnackbar.showInfo(
context,
"Initiating Google Sign-In...",
);
// Navigation handled by the Consumer2's listener
},
Expand Down Expand Up @@ -436,12 +423,9 @@ class LoginForm extends StatelessWidget {
onPressed: () async {
// Call void method, loading handled by provider
await authProvider.githubSignin();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
"Initiating GitHub Sign-In...",
),
),
CustomSnackbar.showInfo(
context,
"Initiating GitHub Sign-In...",
);
// Navigation handled by the Consumer2's listener
},
Expand Down
35 changes: 31 additions & 4 deletions lib/features/dashboard/pages/desktop/dashboard_desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,40 @@ import 'package:cookethflow/features/dashboard/pages/desktop/short_cut_setting.d
import 'package:cookethflow/features/dashboard/providers/dashboard_provider.dart';
import 'package:cookethflow/features/dashboard/widgets/dashboard_drawer.dart';
import 'package:cookethflow/features/dashboard/widgets/project_card.dart';
import 'package:cookethflow/features/dashboard/widgets/snackbar.dart';
import 'package:cookethflow/features/dashboard/widgets/start_project.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:cookethflow/core/helpers/responsive_layout.helper.dart' as rh;
import 'package:cookethflow/core/utils/enums.dart' as en;

class DashboardDesktop extends StatelessWidget {
class DashboardDesktop extends StatefulWidget {
const DashboardDesktop({super.key});

@override
State<DashboardDesktop> createState() => _DashboardDesktopState();
}

class _DashboardDesktopState extends State<DashboardDesktop> {
@override
void initState() {
super.initState();

// Show snackbar after the first frame is rendered
WidgetsBinding.instance.addPostFrameCallback((_) {
final su = Provider.of<SupabaseService>(context, listen: false);
if (su.loginSnackShown) {
CustomSnackbar.showSuccess(context, "Successfully Logged in");
Future.delayed(Duration(seconds: 4), () {
if (mounted) {
context.read<SupabaseService>().setLoginSnackShown(false);
}
});
}
});
}

@override
Widget build(BuildContext context) {
en.DeviceType deviceType = rh.ResponsiveLayoutHelper.getDeviceType(context);
Expand Down Expand Up @@ -48,9 +72,12 @@ class DashboardDesktop extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Padding(
padding: EdgeInsets.only(bottom: 20.h),
child: const StartProject(),
Visibility(
visible: provider.tabIndex <= 1,
child: Padding(
padding: EdgeInsets.only(bottom: 20.h),
child: const StartProject(),
),
),
const SizedBox(height: 32),
Expanded(
Expand Down
27 changes: 26 additions & 1 deletion lib/features/dashboard/pages/mobile/dashboard_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:cookethflow/features/dashboard/pages/desktop/short_cut_setting.d
import 'package:cookethflow/features/dashboard/pages/mobile/drawer_mobile.dart';
import 'package:cookethflow/features/dashboard/providers/dashboard_provider.dart';
import 'package:cookethflow/features/dashboard/widgets/project_card.dart';
import 'package:cookethflow/features/dashboard/widgets/snackbar.dart';
import 'package:cookethflow/features/dashboard/widgets/start_project.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
Expand All @@ -20,6 +21,24 @@ class DashboardMobile extends StatefulWidget {

class _DashboardMobileState extends State<DashboardMobile> {
bool isVisible = false;
@override
void initState() {
super.initState();

// Show snackbar after the first frame is rendered
WidgetsBinding.instance.addPostFrameCallback((_) {
final su = Provider.of<SupabaseService>(context, listen: false);
if (su.loginSnackShown) {
CustomSnackbar.showSuccess(context, "Successfully Logged in");
Future.delayed(Duration(seconds: 4), () {
if (mounted) {
context.read<SupabaseService>().setLoginSnackShown(false);
}
});
}
});
}

@override
Widget build(BuildContext context) {
en.DeviceType deviceType = rh.ResponsiveLayoutHelper.getDeviceType(context);
Expand Down Expand Up @@ -57,7 +76,13 @@ class _DashboardMobileState extends State<DashboardMobile> {
child: Icon(Icons.menu, size: 30),
),
),
const StartProject(),
Visibility(
visible: provider.tabIndex <= 1,
child: Padding(
padding: EdgeInsets.only(bottom: 20.h),
child: const StartProject(),
),
),
],
),
const SizedBox(height: 34),
Expand Down
3 changes: 2 additions & 1 deletion lib/features/dashboard/pages/mobile/drawer_mobile.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:cookethflow/core/helpers/responsive_layout.helper.dart' as rh;
import 'package:cookethflow/core/providers/supabase_provider.dart';
import 'package:cookethflow/core/theme/colors.dart';
import 'package:cookethflow/features/dashboard/pages/mobile/edit_profile_mobile.dart';
import 'package:cookethflow/features/dashboard/providers/dashboard_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
Expand Down Expand Up @@ -124,7 +125,7 @@ class DashboardDrawerMob extends StatelessWidget {
showDialog(
context: context,
builder:
(context) => const ProfileSettingsWidget(),
(context) => const ProfileSettingsWidgetMob(),
);
},
icon: Icon(
Expand Down
Loading