Skip to content

Commit 1b71daf

Browse files
authored
🐛 Avoid clearing selected assets when disposing the provider (#428)
1 parent d0c2239 commit 1b71daf

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ that can be found in the LICENSE file. -->
44

55
# Changelog
66

7+
## 8.4.2
8+
9+
### Fixes
10+
11+
- Avoid clearing selected assets when disposing the provider. (#428)
12+
713
## 8.4.1
814

915
### Fixes

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: wechat_assets_picker_demo
22
description: The demo project for the wechat_assets_picker package.
3-
version: 8.4.1+35
3+
version: 8.4.2+36
44
publish_to: none
55

66
environment:

lib/src/provider/asset_picker_provider.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ abstract class AssetPickerProvider<Asset, Path> extends ChangeNotifier {
5656
_paths.clear();
5757
_currentPath = null;
5858
_currentAssets.clear();
59-
_selectedAssets.clear();
6059
super.dispose();
6160
}
6261

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: wechat_assets_picker
2-
version: 8.4.1
2+
version: 8.4.2
33
description: |
44
An image picker (also with videos and audio)
55
for Flutter projects based on WeChat's UI,

test/providers_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,28 @@ void main() async {
3636
await tester.pumpAndSettle();
3737
expect(() => provider.addListener(() {}), throwsA(isA<AssertionError>()));
3838
});
39+
40+
/// Regression: https://github.com/fluttercandies/flutter_wechat_assets_picker/issues/427
41+
testWidgets(
42+
'does not clear selected assets',
43+
(WidgetTester tester) async {
44+
final List<AssetEntity> selectedAssets = <AssetEntity>[testAssetEntity];
45+
await tester.pumpWidget(
46+
defaultPickerTestApp(
47+
onButtonPressed: (BuildContext context) {
48+
AssetPicker.pickAssets(
49+
context,
50+
pickerConfig: AssetPickerConfig(selectedAssets: selectedAssets),
51+
);
52+
},
53+
),
54+
);
55+
await tester.tap(defaultButtonFinder);
56+
await tester.pumpAndSettle();
57+
await tester.tap(find.widgetWithIcon(IconButton, Icons.close));
58+
await tester.pumpAndSettle();
59+
expect(selectedAssets, contains(testAssetEntity));
60+
},
61+
);
3962
});
4063
}

test/test_utils.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ class TestAssetPickerDelegate extends AssetPickerDelegate {
9898
filterOptions: pickerConfig.filterOptions,
9999
);
100100
provider
101-
..currentAssets = <AssetEntity>[
102-
const AssetEntity(id: 'test', typeInt: 0, width: 0, height: 0),
103-
]
101+
..currentAssets = <AssetEntity>[testAssetEntity]
104102
..currentPath = PathWrapper<AssetPathEntity>(
105103
path: pathEntity,
106104
assetCount: 1,
@@ -140,3 +138,10 @@ class TestAssetPickerDelegate extends AssetPickerDelegate {
140138
return result;
141139
}
142140
}
141+
142+
const AssetEntity testAssetEntity = AssetEntity(
143+
id: 'test',
144+
typeInt: 0,
145+
width: 0,
146+
height: 0,
147+
);

0 commit comments

Comments
 (0)