yasukotelin / ext_storage

ext_storage is minimal flutter plugin that provides external storage path and external public storage path.
MIT License
29 stars 61 forks source link

Unit testing with ext storage not feasible with Platform.isAndroid #16

Open tonywu1999 opened 3 years ago

tonywu1999 commented 3 years ago

https://github.com/yasukotelin/ext_storage/blob/master/lib/ext_storage.dart#L33-L46

Instead of using Platform.isAndroid to check if the current Platform is Android, I'm proposing the following solution:

import 'package:flutter/foundation.dart' show defaultTargetPlatform, TargetPlatform;

if (defaultTargetPlatform != TargetPlatform.android) {
    throw UnsupportedError("Only android supported");
}

This will making widget testing with ext_storage easier because in tests, Platform.isAndroid always returns false. Whereas with defaultTargetPlatform != TargetPlatform.android, a tester could use debugDefaultTargetPlatformOverride to determine if the test environment is Android vs iOS:

testWidgets('test Android', (WidgetTester tester) async {
    debugDefaultTargetPlatformOverride = TargetPlatform.android;
    // Insert Test Code Here
    debugDefaultTargetPlatformOverride = null;

I can submit a PR for this if you would like.

shatanikmahanty commented 3 years ago

This package has not been updated for a long time, I was hoping the author will atleast update the flutter embedding to v2 but no commits on this repo since Apr 6,2020. If you could fork the code and upload it with improved code the community as well as me would find it very helpful. Thanks!