Skip to content

Commit d10186b

Browse files
authored
♻️ Use TargetPlatform for isAppleOS (#463)
1 parent 4add48c commit d10186b

File tree

8 files changed

+176
-97
lines changed

8 files changed

+176
-97
lines changed

CHANGELOG.md

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

77
## 8.6.0
88

9+
### Breaking changes
10+
11+
- Use `TargetPlatform` for the `isAppleOS` method in delegates, which relies on a `BuildContext`.
12+
913
### New features
1014

1115
- Sync all UI details from WeChat 8.3.x. (#458)

example/lib/customs/pickers/directory_file_asset_picker.dart

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ class FileAssetPickerBuilder
480480
child: Column(
481481
children: <Widget>[
482482
Expanded(child: assetsGridBuilder(context)),
483-
if (!isAppleOS) bottomActionBar(context),
483+
if (!isAppleOS(context))
484+
bottomActionBar(context),
484485
],
485486
),
486487
),
@@ -502,10 +503,10 @@ class FileAssetPickerBuilder
502503
PreferredSizeWidget appBar(BuildContext context) {
503504
return AppBar(
504505
backgroundColor: theme.appBarTheme.backgroundColor,
505-
centerTitle: isAppleOS,
506+
centerTitle: isAppleOS(context),
506507
title: pathEntitySelector(context),
507508
leading: backButton(context),
508-
actions: !isAppleOS
509+
actions: !isAppleOS(context)
509510
? <Widget>[
510511
confirmButton(context),
511512
const SizedBox(width: 14.0),
@@ -537,7 +538,7 @@ class FileAssetPickerBuilder
537538
Positioned.fill(
538539
child: assetsGridBuilder(context),
539540
),
540-
if (!isSingleAssetMode || isAppleOS)
541+
if (!isSingleAssetMode || isAppleOS(context))
541542
PositionedDirectional(
542543
bottom: 0.0,
543544
child: bottomActionBar(context),
@@ -589,7 +590,7 @@ class FileAssetPickerBuilder
589590
totalCount += 1;
590591
}
591592
final int placeholderCount;
592-
if (isAppleOS && totalCount % gridCount != 0) {
593+
if (isAppleOS(context) && totalCount % gridCount != 0) {
593594
placeholderCount = gridCount - totalCount % gridCount;
594595
} else {
595596
placeholderCount = 0;
@@ -604,7 +605,7 @@ class FileAssetPickerBuilder
604605
delegate: SliverChildBuilderDelegate(
605606
(_, int index) => Builder(
606607
builder: (BuildContext c) {
607-
if (isAppleOS) {
608+
if (isAppleOS(context)) {
608609
if (index < placeholderCount) {
609610
return const SizedBox.shrink();
610611
}
@@ -663,10 +664,10 @@ class FileAssetPickerBuilder
663664
builder: (_, List<File> assets, __) => CustomScrollView(
664665
physics: const AlwaysScrollableScrollPhysics(),
665666
controller: gridScrollController,
666-
anchor: isAppleOS ? anchor : 0,
667-
center: isAppleOS ? gridRevertKey : null,
667+
anchor: isAppleOS(context) ? anchor : 0,
668+
center: isAppleOS(context) ? gridRevertKey : null,
668669
slivers: <Widget>[
669-
if (isAppleOS)
670+
if (isAppleOS(context))
670671
SliverToBoxAdapter(
671672
child: SizedBox(
672673
height:
@@ -675,14 +676,14 @@ class FileAssetPickerBuilder
675676
),
676677
sliverGrid(_, assets),
677678
// Ignore the gap when the [anchor] is not equal to 1.
678-
if (isAppleOS && anchor == 1)
679+
if (isAppleOS(context) && anchor == 1)
679680
SliverToBoxAdapter(
680681
child: SizedBox(
681682
height: MediaQuery.of(context).padding.bottom +
682683
bottomSectionHeight,
683684
),
684685
),
685-
if (isAppleOS)
686+
if (isAppleOS(context))
686687
SliverToBoxAdapter(
687688
key: gridRevertKey,
688689
child: const SizedBox.shrink(),
@@ -829,20 +830,20 @@ class FileAssetPickerBuilder
829830
builder: (_, bool isSwitchingPath, Widget? w) => AnimatedPositioned(
830831
duration: switchingPathDuration,
831832
curve: switchingPathCurve,
832-
top: isAppleOS
833+
top: isAppleOS(context)
833834
? !isSwitchingPath
834835
? -maxHeight
835836
: appBarHeight
836837
: -(!isSwitchingPath ? maxHeight : 1.0),
837838
child: AnimatedOpacity(
838839
duration: switchingPathDuration,
839840
curve: switchingPathCurve,
840-
opacity: !isAppleOS || isSwitchingPath ? 1.0 : 0.0,
841+
opacity: !isAppleOS(context) || isSwitchingPath ? 1.0 : 0.0,
841842
child: Container(
842843
width: MediaQuery.sizeOf(context).width,
843844
height: maxHeight,
844845
decoration: BoxDecoration(
845-
borderRadius: isAppleOS
846+
borderRadius: isAppleOS(context)
846847
? const BorderRadius.vertical(bottom: Radius.circular(10.0))
847848
: null,
848849
color: theme.colorScheme.background,
@@ -970,7 +971,7 @@ class FileAssetPickerBuilder
970971
isSwitchingPath.value = false;
971972
},
972973
child: SizedBox(
973-
height: isAppleOS ? 64.0 : 52.0,
974+
height: isAppleOS(context) ? 64.0 : 52.0,
974975
child: Row(
975976
children: <Widget>[
976977
RepaintBoundary(
@@ -1085,15 +1086,15 @@ class FileAssetPickerBuilder
10851086
margin: EdgeInsets.all(
10861087
MediaQuery.sizeOf(context).width /
10871088
gridCount /
1088-
(isAppleOS ? 12.0 : 15.0),
1089+
(isAppleOS(context) ? 12.0 : 15.0),
10891090
),
10901091
width: indicatorSize,
10911092
height: indicatorSize,
10921093
alignment: AlignmentDirectional.topEnd,
10931094
child: AnimatedContainer(
10941095
duration: switchingPathDuration,
1095-
width: indicatorSize / (isAppleOS ? 1.25 : 1.5),
1096-
height: indicatorSize / (isAppleOS ? 1.25 : 1.5),
1096+
width: indicatorSize / (isAppleOS(context) ? 1.25 : 1.5),
1097+
height: indicatorSize / (isAppleOS(context) ? 1.25 : 1.5),
10971098
decoration: BoxDecoration(
10981099
border: !isSelected
10991100
? Border.all(color: Colors.white, width: 2.0)
@@ -1113,8 +1114,8 @@ class FileAssetPickerBuilder
11131114
color: isSelected
11141115
? theme.textTheme.bodyLarge?.color
11151116
: null,
1116-
fontSize: isAppleOS ? 16.0 : 14.0,
1117-
fontWeight: isAppleOS
1117+
fontSize: isAppleOS(context) ? 16.0 : 14.0,
1118+
fontWeight: isAppleOS(context)
11181119
? FontWeight.w600
11191120
: FontWeight.bold,
11201121
),
@@ -1187,7 +1188,7 @@ class FileAssetPickerBuilder
11871188
child: Stack(
11881189
fit: StackFit.expand,
11891190
children: <Widget>[
1190-
if (isAppleOS) appleOSLayout(c) else androidLayout(c),
1191+
if (isAppleOS(context)) appleOSLayout(c) else androidLayout(c),
11911192
if (Platform.isIOS) iOSPermissionOverlay(c),
11921193
],
11931194
),
@@ -1288,7 +1289,7 @@ class FileAssetPickerViewerBuilderDelegate
12881289
mainAxisAlignment: MainAxisAlignment.spaceBetween,
12891290
children: <Widget>[
12901291
const Spacer(),
1291-
if (isAppleOS && provider != null)
1292+
if (isAppleOS(context) && provider != null)
12921293
ChangeNotifierProvider<
12931294
AssetPickerViewerProvider<File>>.value(
12941295
value: provider!,
@@ -1383,7 +1384,7 @@ class FileAssetPickerViewerBuilderDelegate
13831384
child: Row(
13841385
children: <Widget>[
13851386
const BackButton(),
1386-
if (!isAppleOS)
1387+
if (!isAppleOS(context))
13871388
StreamBuilder<int>(
13881389
initialData: currentIndex,
13891390
stream: pageStreamController.stream,
@@ -1398,8 +1399,8 @@ class FileAssetPickerViewerBuilderDelegate
13981399
},
13991400
),
14001401
const Spacer(),
1401-
if (isAppleOS && provider != null) selectButton(context),
1402-
if (!isAppleOS && provider != null) confirmButton(context),
1402+
if (isAppleOS(context) && provider != null) selectButton(context),
1403+
if (!isAppleOS(context) && provider != null) confirmButton(context),
14031404
],
14041405
),
14051406
),
@@ -1512,7 +1513,7 @@ class FileAssetPickerViewerBuilderDelegate
15121513
final File asset = previewAssets.elementAt(snapshot.data!);
15131514
final bool isSelected =
15141515
currentlySelectedAssets.contains(asset);
1515-
if (isAppleOS) {
1516+
if (isAppleOS(context)) {
15161517
return _appleOSSelectButton(isSelected, asset);
15171518
} else {
15181519
return _androidSelectButton(isSelected, asset);
@@ -1522,7 +1523,7 @@ class FileAssetPickerViewerBuilderDelegate
15221523
);
15231524
},
15241525
),
1525-
if (!isAppleOS)
1526+
if (!isAppleOS(context))
15261527
Text(
15271528
textDelegate.select,
15281529
style: const TextStyle(fontSize: 18.0),

example/lib/customs/pickers/insta_asset_picker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ class InstaAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
626626
Widget _buildListAlbums(BuildContext context) {
627627
return Consumer<DefaultAssetPickerProvider>(
628628
builder: (BuildContext context, DefaultAssetPickerProvider provider, __) {
629-
if (isAppleOS) {
629+
if (isAppleOS(context)) {
630630
return pathEntityListWidget(context);
631631
}
632632

example/lib/customs/pickers/multi_tabs_assets_picker.dart

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,13 @@ class MultiTabAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
427427
AssetPickerAppBar appBar(BuildContext context) {
428428
return AssetPickerAppBar(
429429
backgroundColor: theme.appBarTheme.backgroundColor,
430-
centerTitle: isAppleOS,
430+
centerTitle: true,
431431
title: Semantics(
432432
onTapHint: textDelegate.sActionSwitchPathLabel,
433433
child: pathEntitySelector(context),
434434
),
435435
leading: backButton(context),
436-
actions: <Widget>[if (!isAppleOS) confirmButton(context)],
437-
actionsPadding: const EdgeInsetsDirectional.only(end: 14),
438-
blurRadius: isAppleOS ? appleOSBlurRadius : 0,
436+
blurRadius: isAppleOS(context) ? appleOSBlurRadius : 0,
439437
bottom: TabBar(
440438
controller: _tabController,
441439
tabs: <Tab>[
@@ -447,6 +445,47 @@ class MultiTabAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
447445
);
448446
}
449447

448+
@override
449+
Widget appleOSLayout(BuildContext context) {
450+
final AssetPickerAppBar appBarWidget = appBar(context);
451+
452+
Widget layout(BuildContext context) {
453+
return Stack(
454+
children: <Widget>[
455+
TabBarView(
456+
controller: _tabController,
457+
children: <Widget>[
458+
ChangeNotifierProvider<DefaultAssetPickerProvider>.value(
459+
value: provider,
460+
builder: (BuildContext context, _) => _buildGrid(context),
461+
),
462+
ChangeNotifierProvider<DefaultAssetPickerProvider>.value(
463+
value: videosProvider,
464+
builder: (BuildContext context, _) => _buildGrid(context),
465+
),
466+
ChangeNotifierProvider<DefaultAssetPickerProvider>.value(
467+
value: imagesProvider,
468+
builder: (BuildContext context, _) => _buildGrid(context),
469+
),
470+
],
471+
),
472+
appBarWidget,
473+
],
474+
);
475+
}
476+
477+
return ValueListenableBuilder<bool>(
478+
valueListenable: permissionOverlayDisplay,
479+
builder: (_, bool value, Widget? child) {
480+
if (value) {
481+
return ExcludeSemantics(child: child);
482+
}
483+
return child!;
484+
},
485+
child: layout(context),
486+
);
487+
}
488+
450489
@override
451490
Widget androidLayout(BuildContext context) {
452491
return AssetPickerAppBarWrapper(
@@ -471,9 +510,6 @@ class MultiTabAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
471510
);
472511
}
473512

474-
@override
475-
Widget appleOSLayout(BuildContext context) => androidLayout(context);
476-
477513
Widget _buildGrid(BuildContext context) {
478514
return Consumer<DefaultAssetPickerProvider>(
479515
builder: (BuildContext context, DefaultAssetPickerProvider p, __) {
@@ -508,14 +544,19 @@ class MultiTabAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
508544
value: overlayStyle,
509545
child: Theme(
510546
data: theme,
511-
child: Material(
512-
color: theme.canvasColor,
513-
child: Stack(
514-
fit: StackFit.expand,
515-
children: <Widget>[
516-
if (isAppleOS) appleOSLayout(context) else androidLayout(context),
517-
if (Platform.isIOS) iOSPermissionOverlay(context),
518-
],
547+
child: Builder(
548+
builder: (BuildContext context) => Material(
549+
color: theme.canvasColor,
550+
child: Stack(
551+
fit: StackFit.expand,
552+
children: <Widget>[
553+
if (isAppleOS(context))
554+
appleOSLayout(context)
555+
else
556+
androidLayout(context),
557+
if (Platform.isIOS) iOSPermissionOverlay(context),
558+
],
559+
),
519560
),
520561
),
521562
),

guides/migration_guide.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,35 @@ This document gathered all breaking changes and migrations requirement between m
88

99
## Major versions
1010

11+
- [8.6.0](#860)
1112
- [8.3.0](#830)
1213
- [8.2.0](#820)
1314
- [8.0.0](#800)
1415
- [7.0.0](#700)
1516
- [6.0.0](#600)
1617
- [5.0.0](#500)
1718

19+
## 8.6.0
20+
21+
### Summary
22+
23+
`isAppleOS` in `AssetPickerBuilderDelegate` and `AssetPickerViewerBuilderDelegate`
24+
has been refactored to relies on the `TargetPlatform` from a given `BuildContext`.
25+
Delegates that extends those should update the signature at least.
26+
27+
### Details
28+
29+
Before:
30+
31+
```dart
32+
bool get isAppleOS;
33+
```
34+
35+
After:
36+
```dart
37+
bool isAppleOS(BuildContext context);
38+
```
39+
1840
## 8.3.0
1941

2042
### Summary

0 commit comments

Comments
 (0)