-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
151 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
Clone this repository into your existing Flutter app, and rename the folder to `lib`. | ||
|
||
Then, add the following dependencies to your Flutter project: | ||
```bash | ||
flutter pub add go_router get_it provider firebase_core firebase_auth firebase_storage shared_preferences image_picker uuid http feather_icons emoji_picker_flutter cached_network_image | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'dart:developer'; | ||
import 'dart:io'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:image_picker/image_picker.dart'; | ||
import '../auth/auth_controller.dart'; | ||
import '../error_handlers/info_exception.dart'; | ||
import '../../service_locator.dart'; | ||
import 'package:uuid/uuid.dart'; | ||
import '../../components/system_alert.dart'; | ||
import 'package:firebase_storage/firebase_storage.dart'; | ||
import 'error_service.dart'; | ||
|
||
class MediaService { | ||
|
||
final FirebaseStorage _storage = sl(); | ||
final AuthController _authController = sl(); | ||
final ErrorService _errorService = sl(); | ||
|
||
final Uuid uuid = const Uuid(); | ||
|
||
Future<XFile?> getUserChosenVideo(BuildContext context) async { | ||
|
||
//Get the image picker | ||
final ImagePicker picker = ImagePicker(); | ||
|
||
final XFile? video = await picker.pickVideo(source: ImageSource.gallery); | ||
|
||
return video; | ||
|
||
} | ||
|
||
Future<File?> getUserChosenImage(BuildContext context) async { | ||
|
||
//Open the image picker | ||
final ImagePicker picker = ImagePicker(); | ||
|
||
bool? usingCamera = await SophiaAlert.showPlatformDialog(context, 'Choose a file source', 'Would you like to select from your photo gallery or take a new picture?', [ | ||
const AlertAction(buttonText: 'Camera', returnValue: true, type: AlertActionType.normal), | ||
const AlertAction(buttonText: 'Gallery', returnValue: false, type: AlertActionType.normal), | ||
]); | ||
|
||
if (usingCamera == null) return null; | ||
|
||
final XFile? image = await picker.pickImage(source: usingCamera ? ImageSource.camera : ImageSource.gallery); | ||
|
||
if (image == null) return null; | ||
|
||
final file = File(image.path); | ||
|
||
return file; | ||
|
||
} | ||
|
||
Future<String?> uploadFile(File mediaFile, String path, [void Function(TaskSnapshot taskSnapshot)? streamListener, String contentType = 'image/jpeg']) async { | ||
final itemRef = _storage.ref().child(path); | ||
final uploadTask = itemRef.putFile(mediaFile, SettableMetadata( | ||
contentType: contentType | ||
)); | ||
|
||
//Allow for monitoring upload progress | ||
uploadTask.snapshotEvents.listen((TaskSnapshot snapshot) { | ||
|
||
if (snapshot.state == TaskState.error) { | ||
_errorService.receiveError(const InfoException('Error uploading file')); | ||
} | ||
|
||
streamListener?.call(snapshot); | ||
|
||
}); | ||
|
||
final snapshot = await uploadTask.whenComplete(() => null); | ||
|
||
if (snapshot.state == TaskState.error) { | ||
return null; | ||
} | ||
|
||
final url = await snapshot.ref.getDownloadURL(); | ||
|
||
return url; | ||
|
||
} | ||
|
||
String uniqueFilename() { | ||
return uuid.v4(); | ||
} | ||
|
||
String getUserStoragePath() { | ||
return 'users/${_authController.getCurrentUserId()}'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'dart:collection'; | ||
import 'dart:io'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import '../../pages/base_page.dart'; | ||
|
||
class NavigationChainService { | ||
|
||
final Queue<String> _currentNavigationChain = Queue(); | ||
|
||
void triggerNavigationChain(BuildContext context, List<String> routes) { | ||
_currentNavigationChain.clear(); | ||
_currentNavigationChain.addAll(routes); | ||
|
||
_triggerNextNavigation(context); | ||
} | ||
|
||
void _triggerNextNavigation(BuildContext context) { | ||
if (_currentNavigationChain.isNotEmpty) { | ||
WidgetsBinding.instance.addPostFrameCallback((_) { | ||
context.push(_currentNavigationChain.removeFirst()); | ||
}); | ||
} | ||
} | ||
|
||
void registerPage(BuildContext context) { | ||
//If we're a root page (i.e. there are no SophiaPages above us), navigate to the next route | ||
if (BasePageParentIndicator.maybeOf(context) == null && context.mounted) { | ||
_triggerNextNavigation(context); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import '../components/basic/tab_bar.dart'; | ||
|
||
class BaseTabView extends StatelessWidget { | ||
|
||
final StatefulNavigationShell navigationShell; | ||
|
||
const BaseTabView({super.key, required this.navigationShell}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
bottomNavigationBar: TabBar(currentIndex: navigationShell.currentIndex, navigationShell: navigationShell,), | ||
body: navigationShell, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters