Skip to content

Commit

Permalink
🐛 Avoid clearing selected assets when disposing the provider (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Apr 11, 2023
1 parent d0c2239 commit 1b71daf
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 0 additions & 1 deletion lib/src/provider/asset_picker_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ abstract class AssetPickerProvider<Asset, Path> extends ChangeNotifier {
_paths.clear();
_currentPath = null;
_currentAssets.clear();
_selectedAssets.clear();
super.dispose();
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
23 changes: 23 additions & 0 deletions test/providers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,28 @@ void main() async {
await tester.pumpAndSettle();
expect(() => provider.addListener(() {}), throwsA(isA<AssertionError>()));
});

/// Regression: https://github.com/fluttercandies/flutter_wechat_assets_picker/issues/427
testWidgets(
'does not clear selected assets',
(WidgetTester tester) async {
final List<AssetEntity> selectedAssets = <AssetEntity>[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));
},
);
});
}
11 changes: 8 additions & 3 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ class TestAssetPickerDelegate extends AssetPickerDelegate {
filterOptions: pickerConfig.filterOptions,
);
provider
..currentAssets = <AssetEntity>[
const AssetEntity(id: 'test', typeInt: 0, width: 0, height: 0),
]
..currentAssets = <AssetEntity>[testAssetEntity]
..currentPath = PathWrapper<AssetPathEntity>(
path: pathEntity,
assetCount: 1,
Expand Down Expand Up @@ -140,3 +138,10 @@ class TestAssetPickerDelegate extends AssetPickerDelegate {
return result;
}
}

const AssetEntity testAssetEntity = AssetEntity(
id: 'test',
typeInt: 0,
width: 0,
height: 0,
);

0 comments on commit 1b71daf

Please sign in to comment.