Skip to content

Commit d8e9ea5

Browse files
authored
🐛 Fix conditions with the confirm button (#367)
1 parent a174875 commit d8e9ea5

File tree

7 files changed

+191
-42
lines changed

7 files changed

+191
-42
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.1.1
8+
9+
### Fixes
10+
11+
- Fix conditions with the confirm button. (#367)
12+
713
## 8.1.0
814

915
### New features

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.1.0+25
3+
version: 8.1.1+26
44
publish_to: none
55

66
environment:

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,9 @@ class DefaultAssetPickerBuilderDelegate
899899
// If no preview and single asset mode, do not show confirm button,
900900
// because any click on an asset selects it.
901901
// - On iOS and macOS, show nothing.
902-
actions: !isAppleOS && !isSingleAssetMode
903-
? <Widget>[confirmButton(context)]
904-
: null,
902+
actions: <Widget>[
903+
if (!isAppleOS && isPreviewEnabled) confirmButton(context),
904+
],
905905
actionsPadding: const EdgeInsetsDirectional.only(end: 14),
906906
blurRadius: isAppleOS ? appleOSBlurRadius : 0,
907907
);

pubspec.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: wechat_assets_picker
22
description: An audio/video/image picker in pure Dart which is the same with WeChat, support multi picking.
3-
version: 8.1.0
3+
version: 8.1.1
44
homepage: https://github.com/fluttercandies/flutter_wechat_assets_picker
55

66
environment:
@@ -17,5 +17,7 @@ dependencies:
1717
video_player: ^2.4.0
1818

1919
dev_dependencies:
20+
flutter_localizations:
21+
sdk: flutter
2022
flutter_test:
2123
sdk: flutter

test/config_test.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// [Author] Alex (https://github.com/AlexV525)
3+
// [Date] 2022/09/20 17:06
4+
//
5+
6+
import 'package:flutter/material.dart';
7+
import 'package:flutter_test/flutter_test.dart';
8+
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
9+
10+
import 'test_utils.dart';
11+
12+
void main() {
13+
PhotoManager.withPlugin(TestPhotoManagerPlugin());
14+
AssetPicker.setPickerDelegate(TestAssetPickerDelegate());
15+
16+
group('PathNameBuilder', () {
17+
testWidgets('called correctly', (WidgetTester tester) async {
18+
await tester.pumpWidget(
19+
defaultPickerTestApp(
20+
onButtonPressed: (BuildContext context) {
21+
AssetPicker.pickAssets(
22+
context,
23+
pickerConfig: AssetPickerConfig(
24+
pathNameBuilder: (AssetPathEntity p) => 'testPathNameBuilder',
25+
),
26+
);
27+
},
28+
),
29+
);
30+
await tester.tap(defaultButtonFinder);
31+
await tester.pumpAndSettle();
32+
await tester.tap(find.byIcon(Icons.keyboard_arrow_down));
33+
await tester.pumpAndSettle();
34+
expect(find.text('testPathNameBuilder'), findsOneWidget);
35+
});
36+
});
37+
}

test/delegates/builder_delegate_test.dart renamed to test/test_utils.dart

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,62 @@
1-
// Copyright 2019 The FlutterCandies author. All rights reserved.
2-
// Use of this source code is governed by an Apache license that can be found
3-
// in the LICENSE file.
1+
//
2+
// [Author] Alex (https://github.com/AlexV525)
3+
// [Date] 2022/09/20 16:35
4+
//
45

56
import 'package:flutter/foundation.dart';
67
import 'package:flutter/material.dart';
8+
import 'package:flutter_localizations/flutter_localizations.dart';
79
import 'package:flutter_test/flutter_test.dart';
810
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
911

10-
void main() {
11-
PhotoManager.withPlugin(TestPhotoManagerPlugin());
12-
AssetPicker.setPickerDelegate(TestAssetPickerDelegate());
12+
const String _testButtonText = 'Picker test press';
1313

14-
final Finder defaultButtonFinder = find.byType(TextButton);
14+
final Finder defaultButtonFinder = find.widgetWithText(
15+
TextButton,
16+
_testButtonText,
17+
);
1518

16-
Widget _defaultApp({void Function(BuildContext)? onButtonPressed}) {
17-
return MaterialApp(
18-
home: Builder(
19-
builder: (BuildContext context) => Scaffold(
20-
body: Center(
21-
child: TextButton(
22-
onPressed: () => onButtonPressed?.call(context),
23-
child: const Text('Press'),
24-
),
25-
),
19+
Widget defaultPickerTestApp({
20+
void Function(BuildContext)? onButtonPressed,
21+
Locale locale = const Locale('zh'),
22+
}) {
23+
return MaterialApp(
24+
home: _DefaultHomePage(onButtonPressed),
25+
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
26+
GlobalWidgetsLocalizations.delegate,
27+
GlobalMaterialLocalizations.delegate,
28+
GlobalCupertinoLocalizations.delegate,
29+
],
30+
supportedLocales: const <Locale>[
31+
Locale('zh'),
32+
Locale('en'),
33+
Locale('he'),
34+
Locale('de'),
35+
Locale('ru'),
36+
Locale('ja'),
37+
Locale('ar'),
38+
Locale('fr'),
39+
],
40+
locale: locale,
41+
);
42+
}
43+
44+
class _DefaultHomePage extends StatelessWidget {
45+
const _DefaultHomePage(this.onButtonPressed, {Key? key}) : super(key: key);
46+
47+
final void Function(BuildContext)? onButtonPressed;
48+
49+
@override
50+
Widget build(BuildContext context) {
51+
return Scaffold(
52+
body: Center(
53+
child: TextButton(
54+
onPressed: () => onButtonPressed?.call(context),
55+
child: const Text(_testButtonText),
2656
),
2757
),
2858
);
2959
}
30-
31-
testWidgets('PathNameBuilder called correctly', (WidgetTester tester) async {
32-
await tester.pumpWidget(
33-
_defaultApp(
34-
onButtonPressed: (BuildContext context) {
35-
AssetPicker.pickAssets(
36-
context,
37-
pickerConfig: AssetPickerConfig(
38-
pathNameBuilder: (AssetPathEntity p) => 'testPathNameBuilder',
39-
),
40-
);
41-
},
42-
),
43-
);
44-
await tester.tap(defaultButtonFinder);
45-
await tester.pumpAndSettle();
46-
await tester.tap(find.byIcon(Icons.keyboard_arrow_down));
47-
await tester.pumpAndSettle();
48-
expect(find.text('testPathNameBuilder'), findsOneWidget);
49-
});
5060
}
5161

5262
class TestPhotoManagerPlugin extends PhotoManagerPlugin {

test/widget_test.dart

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//
2+
// [Author] Alex (https://github.com/AlexV525)
3+
// [Date] 2022/09/20 17:09
4+
//
5+
6+
import 'package:flutter/material.dart';
7+
import 'package:flutter_test/flutter_test.dart';
8+
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
9+
10+
import 'test_utils.dart';
11+
12+
void main() {
13+
PhotoManager.withPlugin(TestPhotoManagerPlugin());
14+
AssetPicker.setPickerDelegate(TestAssetPickerDelegate());
15+
16+
group('Confirm button', () {
17+
group('displays when enabled preview', () {
18+
testWidgets(
19+
'with multiple assets picking',
20+
(WidgetTester tester) async {
21+
await tester.pumpWidget(
22+
defaultPickerTestApp(
23+
onButtonPressed: (BuildContext context) {
24+
AssetPicker.pickAssets(
25+
context,
26+
pickerConfig: const AssetPickerConfig(
27+
maxAssets: 10,
28+
// ignore: avoid_redundant_argument_values
29+
specialPickerType: null, // Explicitly null.
30+
),
31+
);
32+
},
33+
),
34+
);
35+
await tester.tap(defaultButtonFinder);
36+
await tester.pumpAndSettle();
37+
expect(
38+
find.text(const AssetPickerTextDelegate().confirm),
39+
findsOneWidget,
40+
);
41+
},
42+
);
43+
testWidgets(
44+
'with single asset picking',
45+
(WidgetTester tester) async {
46+
await tester.pumpWidget(
47+
defaultPickerTestApp(
48+
onButtonPressed: (BuildContext context) {
49+
AssetPicker.pickAssets(
50+
context,
51+
pickerConfig: const AssetPickerConfig(
52+
maxAssets: 1,
53+
// ignore: avoid_redundant_argument_values
54+
specialPickerType: null, // Explicitly null.
55+
),
56+
);
57+
},
58+
),
59+
);
60+
await tester.tap(defaultButtonFinder);
61+
await tester.pumpAndSettle();
62+
expect(
63+
find.text(const AssetPickerTextDelegate().confirm),
64+
findsOneWidget,
65+
);
66+
},
67+
);
68+
});
69+
70+
testWidgets(
71+
'not display when disabled preview',
72+
(WidgetTester tester) async {
73+
await tester.pumpWidget(
74+
defaultPickerTestApp(
75+
onButtonPressed: (BuildContext context) {
76+
AssetPicker.pickAssets(
77+
context,
78+
pickerConfig: AssetPickerConfig(
79+
specialPickerType: SpecialPickerType.noPreview,
80+
),
81+
);
82+
},
83+
),
84+
);
85+
await tester.tap(defaultButtonFinder);
86+
await tester.pumpAndSettle();
87+
expect(
88+
find.text(const AssetPickerTextDelegate().confirm),
89+
findsNothing,
90+
);
91+
},
92+
);
93+
});
94+
}

0 commit comments

Comments
 (0)