diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a48fb8c..39e8c641 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ that can be found in the LICENSE file. --> # Changelog +## 8.4.2 + +### Fixes + +- Avoid clearing selected assets when disposing the provider. (#428) + ## 8.4.1 ### Fixes diff --git a/example/pubspec.yaml b/example/pubspec.yaml index da25223d..bf984680 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,6 @@ name: wechat_assets_picker_demo description: The demo project for the wechat_assets_picker package. -version: 8.4.1+35 +version: 8.4.2+36 publish_to: none environment: diff --git a/lib/src/provider/asset_picker_provider.dart b/lib/src/provider/asset_picker_provider.dart index 09a5119d..e9885669 100644 --- a/lib/src/provider/asset_picker_provider.dart +++ b/lib/src/provider/asset_picker_provider.dart @@ -56,7 +56,6 @@ abstract class AssetPickerProvider extends ChangeNotifier { _paths.clear(); _currentPath = null; _currentAssets.clear(); - _selectedAssets.clear(); super.dispose(); } diff --git a/pubspec.yaml b/pubspec.yaml index 69297bbf..ce131f81 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: wechat_assets_picker -version: 8.4.1 +version: 8.4.2 description: | An image picker (also with videos and audio) for Flutter projects based on WeChat's UI, diff --git a/test/providers_test.dart b/test/providers_test.dart index 590c3abb..0ca8255b 100644 --- a/test/providers_test.dart +++ b/test/providers_test.dart @@ -36,5 +36,28 @@ void main() async { await tester.pumpAndSettle(); expect(() => provider.addListener(() {}), throwsA(isA())); }); + + /// Regression: https://github.com/fluttercandies/flutter_wechat_assets_picker/issues/427 + testWidgets( + 'does not clear selected assets', + (WidgetTester tester) async { + final List selectedAssets = [testAssetEntity]; + await tester.pumpWidget( + defaultPickerTestApp( + onButtonPressed: (BuildContext context) { + AssetPicker.pickAssets( + context, + pickerConfig: AssetPickerConfig(selectedAssets: selectedAssets), + ); + }, + ), + ); + await tester.tap(defaultButtonFinder); + await tester.pumpAndSettle(); + await tester.tap(find.widgetWithIcon(IconButton, Icons.close)); + await tester.pumpAndSettle(); + expect(selectedAssets, contains(testAssetEntity)); + }, + ); }); } diff --git a/test/test_utils.dart b/test/test_utils.dart index ad0f0110..86e83bd2 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -98,9 +98,7 @@ class TestAssetPickerDelegate extends AssetPickerDelegate { filterOptions: pickerConfig.filterOptions, ); provider - ..currentAssets = [ - const AssetEntity(id: 'test', typeInt: 0, width: 0, height: 0), - ] + ..currentAssets = [testAssetEntity] ..currentPath = PathWrapper( path: pathEntity, assetCount: 1, @@ -140,3 +138,10 @@ class TestAssetPickerDelegate extends AssetPickerDelegate { return result; } } + +const AssetEntity testAssetEntity = AssetEntity( + id: 'test', + typeInt: 0, + width: 0, + height: 0, +);