-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Start using feature-first architecture
It's a goal to refactor the source to have a clean feature-first architecture. Start by putting the new sharing feature into a separate folder features/share/ Increase test coverage for ShareButton to 100%
- Loading branch information
Showing
5 changed files
with
51 additions
and
43 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
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,40 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:open_filex/open_filex.dart'; | ||
import 'package:share_plus/share_plus.dart'; | ||
|
||
/// A class around all sharing functionality to enable testing | ||
/// (Packages: share_plus, url_launcher, open_filex) | ||
/// | ||
/// Other options for testing (dependency injection etc.) are hard to use here | ||
/// because of the usage of context.findAncestorWidgetOfExactType | ||
/// so this is probably the best way to do it | ||
class ShareService { | ||
/// Wraps Share.share() (package share_plus) | ||
Future<void> share(String text) { | ||
return Share.share(text); | ||
} | ||
|
||
/// Wraps Share.shareXFiles() (package share_plus) | ||
/// | ||
/// Not using the same argument List<XFile> because that would make it | ||
/// harder to verify that the function gets called with correct arguments | ||
/// with mocktail | ||
Future<ShareResult> shareFile(String path) { | ||
return Share.shareXFiles([XFile(path)]); | ||
} | ||
|
||
/// Wraps launchUrl (package url_launcher) | ||
Future<bool> launchUrl(Uri url) { | ||
return launchUrl(url); | ||
} | ||
|
||
/// Wraps OpenFilex.open (package open_filex) | ||
Future<OpenResult> open(String? filePath) { | ||
return OpenFilex.open(filePath); | ||
} | ||
} | ||
|
||
/// A provider for all sharing functionality to enable testing | ||
final shareProvider = Provider<ShareService>((ref) { | ||
return ShareService(); | ||
}); |
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
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