Skip to content

Commit 72d279e

Browse files
authored
Merge pull request #7 from CookethOrg/dev
Minor fixes
2 parents 96c76f7 + a064d86 commit 72d279e

7 files changed

Lines changed: 236 additions & 233 deletions

File tree

.github/workflows/build_web.yaml

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
1-
name: Deploy Cooketh Flow Web
1+
# name: Deploy Cooketh Flow Web
22

3-
on:
4-
push:
5-
branches:
6-
- master
3+
# on:
4+
# push:
5+
# branches:
6+
# - master
77

8-
permissions:
9-
contents: write
8+
# permissions:
9+
# contents: write
1010

11-
jobs:
12-
build-and-deploy:
13-
runs-on: ubuntu-latest
11+
# jobs:
12+
# build-and-deploy:
13+
# runs-on: ubuntu-latest
1414

15-
steps:
16-
- name: Checkout code
17-
uses: actions/checkout@v4
15+
# steps:
16+
# - name: Checkout code
17+
# uses: actions/checkout@v4
1818

19-
- name: Set up Flutter
20-
uses: subosito/flutter-action@v2
21-
with:
22-
flutter-version: '3.29.2'
23-
channel: 'stable'
19+
# - name: Set up Flutter
20+
# uses: subosito/flutter-action@v2
21+
# with:
22+
# flutter-version: '3.29.2'
23+
# channel: 'stable'
2424

25-
- name: Enable web support
26-
run: flutter config --enable-web
25+
# - name: Enable web support
26+
# run: flutter config --enable-web
2727

28-
- name: Check Flutter setup
29-
run: flutter doctor
28+
# - name: Check Flutter setup
29+
# run: flutter doctor
3030

31-
- name: Install dependencies
32-
run: flutter pub get
31+
# - name: Install dependencies
32+
# run: flutter pub get
3333

34-
- name: Verify web configuration
35-
run: |
36-
if [ -f "web/index.html" ]; then
37-
echo "Web configuration found"
38-
else
39-
echo "Error: web/index.html not found. Ensure web support is enabled in your project."
40-
exit 1
41-
fi
34+
# - name: Verify web configuration
35+
# run: |
36+
# if [ -f "web/index.html" ]; then
37+
# echo "Web configuration found"
38+
# else
39+
# echo "Error: web/index.html not found. Ensure web support is enabled in your project."
40+
# exit 1
41+
# fi
4242

43-
- name: Build web
44-
run: flutter build web --release
43+
# - name: Build web
44+
# run: flutter build web --release
4545

46-
- name: Debug build output
47-
run: |
48-
echo "Current directory: $(pwd)"
49-
ls -la
50-
if [ -d "build/web" ]; then
51-
echo "build/web exists"
52-
ls -la build/web
53-
else
54-
echo "Error: build/web directory not found"
55-
exit 1
56-
fi
46+
# - name: Debug build output
47+
# run: |
48+
# echo "Current directory: $(pwd)"
49+
# ls -la
50+
# if [ -d "build/web" ]; then
51+
# echo "build/web exists"
52+
# ls -la build/web
53+
# else
54+
# echo "Error: build/web directory not found"
55+
# exit 1
56+
# fi
5757

58-
- name: Copy build to temporary directory
59-
run: |
60-
mkdir -p /tmp/web-build
61-
cp -r build/web/* /tmp/web-build/
58+
# - name: Copy build to temporary directory
59+
# run: |
60+
# mkdir -p /tmp/web-build
61+
# cp -r build/web/* /tmp/web-build/
6262

63-
- name: Debug temporary directory
64-
run: |
65-
echo "Temporary directory contents:"
66-
ls -la /tmp/web-build/
63+
# - name: Debug temporary directory
64+
# run: |
65+
# echo "Temporary directory contents:"
66+
# ls -la /tmp/web-build/
6767

68-
- name: Create or update gh-pages branch
69-
run: |
70-
git config --global user.name 'github-actions[bot]'
71-
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
72-
git checkout -B gh-pages
73-
rm -rf ./*
74-
cp -r /tmp/web-build/* .
75-
git add .
76-
git commit -m "Deploy web build to gh-pages" || echo "No changes to commit"
77-
git push origin gh-pages --force
68+
# - name: Create or update gh-pages branch
69+
# run: |
70+
# git config --global user.name 'github-actions[bot]'
71+
# git config --global user.email 'github-actions[bot]@users.noreply.github.com'
72+
# git checkout -B gh-pages
73+
# rm -rf ./*
74+
# cp -r /tmp/web-build/* .
75+
# git add .
76+
# git commit -m "Deploy web build to gh-pages" || echo "No changes to commit"
77+
# git push origin gh-pages --force
7878

79-
- name: Debug gh-pages branch contents
80-
run: |
81-
echo "gh-pages branch contents after deployment:"
82-
ls -la
79+
# - name: Debug gh-pages branch contents
80+
# run: |
81+
# echo "gh-pages branch contents after deployment:"
82+
# ls -la

lib/core/services/supabase_service.dart

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import 'dart:io';
2-
32
import 'package:cookethflow/core/utils/enums.dart';
43
import 'package:cookethflow/core/utils/state_handler.dart';
54
import 'package:cookethflow/core/utils/ui_helper.dart';
65
import 'package:cookethflow/models/flow_manager.dart';
76
import 'package:cookethflow/models/flow_node.dart';
87
import 'package:file_selector/file_selector.dart';
8+
import 'package:flutter/foundation.dart'; // For kIsWeb
99
import 'package:flutter/material.dart';
1010
import 'package:http/http.dart' as http;
1111
import 'package:path_provider/path_provider.dart';
@@ -19,7 +19,7 @@ class SupabaseService extends StateHandler {
1919

2020
late AuthResponse _userData;
2121
bool _userDataSet = false;
22-
XFile? _userPfp = XFile('assets/Frame 271.png');
22+
XFile? _userPfp;
2323
String? _userName;
2424
String? _email;
2525

@@ -38,7 +38,7 @@ class SupabaseService extends StateHandler {
3838

3939
void setUserPfp(XFile? val) {
4040
_userPfp = val;
41-
print('Updated userPfp: ${val?.name}');
41+
print('Updated userPfp: ${val?.path}');
4242
notifyListeners();
4343
}
4444

@@ -56,7 +56,6 @@ class SupabaseService extends StateHandler {
5656
return text.length > 12 ? '${text.substring(0, 12)}...' : text;
5757
}
5858

59-
// Initialize user data on service creation
6059
Future<void> _initializeUserData() async {
6160
final user = supabase.auth.currentUser;
6261
if (user != null) {
@@ -67,9 +66,7 @@ class SupabaseService extends StateHandler {
6766

6867
Future<Map<String, dynamic>?> fetchCurrentUserName() async {
6968
final user = supabase.auth.currentUser;
70-
if (user == null) {
71-
return null;
72-
}
69+
if (user == null) return null;
7370

7471
try {
7572
final response = await supabase
@@ -87,9 +84,7 @@ class SupabaseService extends StateHandler {
8784

8885
Future<Map<String, dynamic>?> fetchCurrentUserDetails() async {
8986
final user = supabase.auth.currentUser;
90-
if (user == null) {
91-
return null;
92-
}
87+
if (user == null) return null;
9388

9489
try {
9590
final response =
@@ -272,7 +267,7 @@ class SupabaseService extends StateHandler {
272267
await supabase.auth.signOut();
273268
_userName = null;
274269
_email = null;
275-
_userPfp = XFile('assets/Frame 271.png');
270+
_userPfp = null; // Set to null to use asset in UI
276271
_userDataSet = false;
277272
notifyListeners();
278273
} catch (e) {
@@ -289,7 +284,7 @@ class SupabaseService extends StateHandler {
289284
await supabase.auth.signOut();
290285
_userName = null;
291286
_email = null;
292-
_userPfp = XFile('assets/Frame 271.png');
287+
_userPfp = null; // Set to null to use asset in UI
293288
_userDataSet = false;
294289
notifyListeners();
295290
} catch (e) {
@@ -383,12 +378,10 @@ class SupabaseService extends StateHandler {
383378
final user = supabase.auth.currentUser;
384379
if (user == null) throw Exception('User not authenticated');
385380

386-
// Get file extension and MIME type
387381
final extension = imageFile.name.split('.').last.toLowerCase();
388382
final mimeType = _getMimeTypeFromExtension(extension);
389383
final storagePath = '${user.id}/pfp.$extension';
390384

391-
// Remove existing profile picture if it exists
392385
try {
393386
await supabase.storage
394387
.from(_profileBucketName)
@@ -397,28 +390,22 @@ class SupabaseService extends StateHandler {
397390
print('No existing profile picture to remove: $e');
398391
}
399392

400-
// Read file bytes for web compatibility
401393
final bytes = await imageFile.readAsBytes();
402394

403-
// Upload to Supabase
404395
await supabase.storage.from(_profileBucketName).uploadBinary(
405396
storagePath,
406397
bytes,
407398
fileOptions: FileOptions(contentType: mimeType, upsert: true),
408399
);
409400

410-
// Get public URL
411401
final String publicUrl =
412402
supabase.storage.from(_profileBucketName).getPublicUrl(storagePath);
413403

414-
// Update user table with new URL
415404
await supabase
416405
.from('User')
417406
.update({'profile_picture_url': publicUrl}).eq('id', user.id);
418407

419-
// Update local state
420-
setUserPfp(imageFile);
421-
notifyListeners();
408+
setUserPfp(imageFile); // Use the uploaded file directly
422409
return publicUrl;
423410
} catch (e) {
424411
print('Error uploading profile picture: $e');
@@ -446,22 +433,32 @@ class SupabaseService extends StateHandler {
446433
const supportedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
447434

448435
if (supportedExtensions.contains(fileExtension)) {
449-
// For web, store the URL directly instead of downloading
450-
setUserPfp(XFile.fromData(
451-
await http.get(Uri.parse(pfpUrl)).then((res) => res.bodyBytes),
452-
name: 'pfp.$fileExtension',
453-
mimeType: _getMimeTypeFromExtension(fileExtension),
454-
));
436+
if (kIsWeb) {
437+
// Web: Use XFile.fromData for in-memory bytes
438+
final bytes = await http.get(uri).then((res) => res.bodyBytes);
439+
setUserPfp(XFile.fromData(
440+
bytes,
441+
name: 'pfp.$fileExtension',
442+
mimeType: _getMimeTypeFromExtension(fileExtension),
443+
));
444+
} else {
445+
// Desktop: Save to temporary file
446+
final tempDir = await getTemporaryDirectory();
447+
final tempFile = File('${tempDir.path}/pfp.$fileExtension');
448+
final bytes = await http.get(uri).then((res) => res.bodyBytes);
449+
await tempFile.writeAsBytes(bytes);
450+
setUserPfp(XFile(tempFile.path));
451+
}
455452
notifyListeners();
456453
return;
457454
}
458455
}
459-
// Fallback to default image
460-
setUserPfp(XFile(_defaultPfpPath));
456+
// Fallback to null (UI should use Image.asset for default)
457+
setUserPfp(null);
461458
notifyListeners();
462459
} catch (e) {
463460
print('Error fetching profile picture: $e');
464-
setUserPfp(XFile(_defaultPfpPath));
461+
setUserPfp(null);
465462
notifyListeners();
466463
}
467464
}

0 commit comments

Comments
 (0)