Skip to content

Commit ed53af0

Browse files
committed
chore(share_plus): Fix formatting
1 parent 6cbdb44 commit ed53af0

8 files changed

Lines changed: 88 additions & 118 deletions

File tree

packages/share_plus/share_plus/lib/src/share_plus_linux.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ class SharePlusLinuxPlugin extends SharePlatform {
3232
final uri = Uri(
3333
scheme: 'mailto',
3434
query: queryParameters.entries
35-
.map((e) =>
36-
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value ?? '')}')
35+
.map(
36+
(e) =>
37+
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value ?? '')}',
38+
)
3739
.join('&'),
3840
);
3941

packages/share_plus/share_plus/lib/src/share_plus_web.dart

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ class SharePlusWebPlugin extends SharePlatform {
3737
try {
3838
canShare = _navigator.canShare(data);
3939
} on NoSuchMethodError catch (e) {
40-
developer.log(
41-
'Share API is not supported in this User Agent.',
42-
error: e,
43-
);
40+
developer.log('Share API is not supported in this User Agent.', error: e);
4441

4542
return _fallback(params, 'Navigator.canShare() is unavailable');
4643
}
@@ -56,10 +53,7 @@ class SharePlusWebPlugin extends SharePlatform {
5653
return _resultDismissed;
5754
}
5855

59-
developer.log(
60-
'Failed to share uri',
61-
error: '${e.name}: ${e.message}',
62-
);
56+
developer.log('Failed to share uri', error: '${e.name}: ${e.message}');
6357

6458
return _fallback(params, 'Navigator.share() failed: ${e.message}');
6559
}
@@ -98,38 +92,19 @@ class SharePlusWebPlugin extends SharePlatform {
9892
}
9993

10094
if (uri != null) {
101-
data = ShareData(
102-
url: uri,
103-
);
95+
data = ShareData(url: uri);
10496
} else if (webFiles.isNotEmpty && text != null && title != null) {
105-
data = ShareData(
106-
text: text,
107-
title: title,
108-
files: webFiles.toJS,
109-
);
97+
data = ShareData(text: text, title: title, files: webFiles.toJS);
11098
} else if (webFiles.isNotEmpty && text != null) {
111-
data = ShareData(
112-
text: text,
113-
files: webFiles.toJS,
114-
);
99+
data = ShareData(text: text, files: webFiles.toJS);
115100
} else if (webFiles.isNotEmpty && title != null) {
116-
data = ShareData(
117-
title: title,
118-
files: webFiles.toJS,
119-
);
101+
data = ShareData(title: title, files: webFiles.toJS);
120102
} else if (webFiles.isNotEmpty) {
121-
data = ShareData(
122-
files: webFiles.toJS,
123-
);
103+
data = ShareData(files: webFiles.toJS);
124104
} else if (text != null && title != null) {
125-
data = ShareData(
126-
text: text,
127-
title: title,
128-
);
105+
data = ShareData(text: text, title: title);
129106
} else {
130-
data = ShareData(
131-
text: text!,
132-
);
107+
data = ShareData(text: text!);
133108
}
134109

135110
return data;
@@ -161,17 +136,16 @@ class SharePlusWebPlugin extends SharePlatform {
161136
throw Exception(error);
162137
}
163138

164-
final queryParameters = {
165-
if (subject != null) 'subject': subject,
166-
'body': text,
167-
};
139+
final queryParameters = {'subject': ?subject, 'body': text};
168140

169141
// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
170142
final uri = Uri(
171143
scheme: 'mailto',
172144
query: queryParameters.entries
173-
.map((e) =>
174-
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
145+
.map(
146+
(e) =>
147+
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}',
148+
)
175149
.join('&'),
176150
);
177151

@@ -227,7 +201,4 @@ class SharePlusWebPlugin extends SharePlatform {
227201
}
228202
}
229203

230-
const _resultDismissed = ShareResult(
231-
'',
232-
ShareResultStatus.dismissed,
233-
);
204+
const _resultDismissed = ShareResult('', ShareResultStatus.dismissed);

packages/share_plus/share_plus/lib/src/share_plus_windows.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ class SharePlusWindowsPlugin extends SharePlatform {
3939
final uri = Uri(
4040
scheme: 'mailto',
4141
query: queryParameters.entries
42-
.map((e) =>
43-
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value ?? '')}')
42+
.map(
43+
(e) =>
44+
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value ?? '')}',
45+
)
4446
.join('&'),
4547
);
4648

packages/share_plus/share_plus/lib/src/windows_version_helper.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ class VersionHelper {
3030
..wServicePackMinor = 0
3131
..wSuiteMask = 0
3232
..wProductType = 0;
33-
final rtlGetVersion = DynamicLibrary.open('ntdll.dll').lookupFunction<
34-
Void Function(Pointer<OSVERSIONINFOEX>),
35-
void Function(Pointer<OSVERSIONINFOEX>)>('RtlGetVersion');
33+
final rtlGetVersion = DynamicLibrary.open('ntdll.dll')
34+
.lookupFunction<
35+
Void Function(Pointer<OSVERSIONINFOEX>),
36+
void Function(Pointer<OSVERSIONINFOEX>)
37+
>('RtlGetVersion');
3638
rtlGetVersion(pointer);
3739
isWindows10RS5OrGreater =
3840
pointer.ref.dwBuildNumber >= kWindows10RS5BuildNumber;

packages/share_plus/share_plus/test/share_plus_linux_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ void main() {
1313
test('url encoding is correct for &', () async {
1414
final mock = MockUrlLauncherPlatform();
1515

16-
await SharePlusLinuxPlugin(mock).share(
17-
ShareParams(text: 'foo&bar', subject: 'bar&foo'),
18-
);
16+
await SharePlusLinuxPlugin(
17+
mock,
18+
).share(ShareParams(text: 'foo&bar', subject: 'bar&foo'));
1919

2020
expect(mock.url, 'mailto:?subject=bar%26foo&body=foo%26bar');
2121
});
@@ -24,19 +24,19 @@ void main() {
2424
test('url encoding is correct for spaces', () async {
2525
final mock = MockUrlLauncherPlatform();
2626

27-
await SharePlusLinuxPlugin(mock).share(
28-
ShareParams(text: 'foo bar', subject: 'bar foo'),
29-
);
27+
await SharePlusLinuxPlugin(
28+
mock,
29+
).share(ShareParams(text: 'foo bar', subject: 'bar foo'));
3030

3131
expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar');
3232
});
3333

3434
test('can share URI on Linux', () async {
3535
final mock = MockUrlLauncherPlatform();
3636

37-
await SharePlusLinuxPlugin(mock).share(
38-
ShareParams(uri: Uri.parse('http://example.com')),
39-
);
37+
await SharePlusLinuxPlugin(
38+
mock,
39+
).share(ShareParams(uri: Uri.parse('http://example.com')));
4040

4141
expect(mock.url, 'mailto:?body=http%3A%2F%2Fexample.com');
4242
});

packages/share_plus/share_plus/test/share_plus_test.dart

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@ void main() {
1919
);
2020
});
2121

22-
test('share throws ArgumentError if both uri and text are provided',
23-
() async {
24-
expect(
25-
() => sharePlus.share(
26-
ShareParams(
27-
uri: Uri.parse('https://example.com'),
28-
text: 'text',
22+
test(
23+
'share throws ArgumentError if both uri and text are provided',
24+
() async {
25+
expect(
26+
() => sharePlus.share(
27+
ShareParams(uri: Uri.parse('https://example.com'), text: 'text'),
2928
),
30-
),
31-
throwsA(isA<ArgumentError>()),
32-
);
33-
});
29+
throwsA(isA<ArgumentError>()),
30+
);
31+
},
32+
);
3433

3534
test('share throws ArgumentError if text is empty', () async {
3635
expect(
@@ -47,14 +46,19 @@ void main() {
4746
});
4847

4948
test(
50-
'share throws ArgumentError if fileNameOverrides length does not match files length',
51-
() async {
52-
expect(
53-
() => sharePlus.share(ShareParams(
54-
files: [XFile('path')], fileNameOverrides: ['name1', 'name2'])),
55-
throwsA(isA<ArgumentError>()),
56-
);
57-
});
49+
'share throws ArgumentError if fileNameOverrides length does not match files length',
50+
() async {
51+
expect(
52+
() => sharePlus.share(
53+
ShareParams(
54+
files: [XFile('path')],
55+
fileNameOverrides: ['name1', 'name2'],
56+
),
57+
),
58+
throwsA(isA<ArgumentError>()),
59+
);
60+
},
61+
);
5862

5963
test('share calls platform share method with correct params', () async {
6064
final params = ShareParams(text: 'text');

packages/share_plus/share_plus/test/share_plus_windows_test.dart

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,15 @@ import 'package:share_plus_platform_interface/share_plus_platform_interface.dart
77
import 'url_launcher_mock.dart';
88

99
void main() {
10-
test(
11-
'registered instance',
12-
() {
13-
SharePlusWindowsPlugin.registerWith();
14-
expect(SharePlatform.instance, isA<SharePlusWindowsPlugin>());
15-
},
16-
skip: VersionHelper.instance.isWindows10RS5OrGreater,
17-
);
10+
test('registered instance', () {
11+
SharePlusWindowsPlugin.registerWith();
12+
expect(SharePlatform.instance, isA<SharePlusWindowsPlugin>());
13+
}, skip: VersionHelper.instance.isWindows10RS5OrGreater);
1814

19-
test(
20-
'registered instance',
21-
() {
22-
SharePlusWindowsPlugin.registerWith();
23-
expect(SharePlatform.instance, isA<MethodChannelShare>());
24-
},
25-
skip: !VersionHelper.instance.isWindows10RS5OrGreater,
26-
);
15+
test('registered instance', () {
16+
SharePlusWindowsPlugin.registerWith();
17+
expect(SharePlatform.instance, isA<MethodChannelShare>());
18+
}, skip: !VersionHelper.instance.isWindows10RS5OrGreater);
2719

2820
// These tests are only valid on Windows versions lower than 10.0.17763.0.
2921

@@ -32,9 +24,9 @@ void main() {
3224
() async {
3325
final mock = MockUrlLauncherPlatform();
3426

35-
await SharePlusWindowsPlugin(mock).share(
36-
ShareParams(text: 'foo&bar', subject: 'bar&foo'),
37-
);
27+
await SharePlusWindowsPlugin(
28+
mock,
29+
).share(ShareParams(text: 'foo&bar', subject: 'bar&foo'));
3830

3931
expect(mock.url, 'mailto:?subject=bar%26foo&body=foo%26bar');
4032
},
@@ -47,9 +39,9 @@ void main() {
4739
() async {
4840
final mock = MockUrlLauncherPlatform();
4941

50-
await SharePlusWindowsPlugin(mock).share(
51-
ShareParams(text: 'foo bar', subject: 'bar foo'),
52-
);
42+
await SharePlusWindowsPlugin(
43+
mock,
44+
).share(ShareParams(text: 'foo bar', subject: 'bar foo'));
5345

5446
expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar');
5547
},
@@ -61,9 +53,9 @@ void main() {
6153
() async {
6254
final mock = MockUrlLauncherPlatform();
6355

64-
await SharePlusWindowsPlugin(mock).share(
65-
ShareParams(uri: Uri.parse('http://example.com')),
66-
);
56+
await SharePlusWindowsPlugin(
57+
mock,
58+
).share(ShareParams(uri: Uri.parse('http://example.com')));
6759

6860
expect(mock.url, 'mailto:?body=http%3A%2F%2Fexample.com');
6961
},

packages/share_plus/share_plus_platform_interface/lib/method_channel/method_channel_share.dart

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ class MethodChannelShare extends SharePlatform {
3030

3131
Future<Map<String, dynamic>> _toPlatformMap(ShareParams params) async {
3232
assert(
33-
params.text != null ||
34-
params.uri != null ||
35-
(params.files != null && params.files!.isNotEmpty),
36-
'At least one of text, uri or files must be provided',
33+
params.text != null ||
34+
params.uri != null ||
35+
(params.files != null && params.files!.isNotEmpty),
36+
'At least one of text, uri or files must be provided',
3737
);
3838

3939
final map = <String, dynamic>{
@@ -52,7 +52,7 @@ class MethodChannelShare extends SharePlatform {
5252

5353
if (params.files != null) {
5454
final filesWithPath =
55-
await _getFiles(params.files!, params.fileNameOverrides);
55+
await _getFiles(params.files!, params.fileNameOverrides);
5656
assert(filesWithPath.every((element) => element.path.isNotEmpty));
5757

5858
final mimeTypes = filesWithPath
@@ -70,7 +70,7 @@ class MethodChannelShare extends SharePlatform {
7070
if (params.excludedCupertinoActivities != null &&
7171
params.excludedCupertinoActivities!.isNotEmpty) {
7272
final excludedActivityTypes =
73-
params.excludedCupertinoActivities!.map((e) => e.value).toList();
73+
params.excludedCupertinoActivities!.map((e) => e.value).toList();
7474
map['excludedCupertinoActivities'] = excludedActivityTypes;
7575
}
7676

@@ -85,8 +85,7 @@ class MethodChannelShare extends SharePlatform {
8585
/// then make new file in TemporaryDirectory and return with path
8686
/// the system will automatically delete files in this
8787
/// TemporaryDirectory as disk space is needed elsewhere on the device
88-
Future<XFile> _getFile(
89-
XFile file, {
88+
Future<XFile> _getFile(XFile file, {
9089
String? tempRoot,
9190
String? nameOverride,
9291
}) async {
@@ -96,8 +95,8 @@ class MethodChannelShare extends SharePlatform {
9695
tempRoot ??= (await getTemporaryDirectory()).path;
9796
// Method returns null as in v2.0.0
9897
final extension =
99-
// ignore: dead_null_aware_expression
100-
extensionFromMime(file.mimeType ?? 'octet-stream') ?? 'bin';
98+
// ignore: dead_null_aware_expression
99+
extensionFromMime(file.mimeType ?? 'octet-stream') ?? 'bin';
101100

102101
//By having a UUID v4 folder wrapping the file
103102
//This path generation algorithm will not only minimize the risk of name collision but also ensure that the filename
@@ -129,10 +128,8 @@ class MethodChannelShare extends SharePlatform {
129128
}
130129

131130
/// A wrapper of [MethodChannelShare._getFile] for multiple files.
132-
Future<List<XFile>> _getFiles(
133-
List<XFile> files,
134-
List<String>? fileNameOverrides,
135-
) async {
131+
Future<List<XFile>> _getFiles(List<XFile> files,
132+
List<String>? fileNameOverrides,) async {
136133
return Future.wait([
137134
for (var index = 0; index < files.length; index++)
138135
_getFile(

0 commit comments

Comments
 (0)