Skip to content

Commit ec7adc1

Browse files
authored
💄 Update style usages for ThemeData (#519)
Resolves #500.
1 parent 3013f86 commit ec7adc1

File tree

5 files changed

+109
-96
lines changed

5 files changed

+109
-96
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ See the [Migration Guide](guides/migration_guide.md) for the details of breaking
1212

1313
- Integrate `PermissionRequestOption` for callers.
1414

15+
### Improvements
16+
17+
- Adapt `ThemeData` usages.
18+
1519
## 8.9.0-dev.1
1620

1721
### Breaking changes

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ class DefaultAssetPickerBuilderDelegate
14341434
gradient: LinearGradient(
14351435
begin: AlignmentDirectional.bottomCenter,
14361436
end: AlignmentDirectional.topCenter,
1437-
colors: <Color>[theme.dividerColor, Colors.transparent],
1437+
colors: <Color>[theme.splashColor, Colors.transparent],
14381438
),
14391439
),
14401440
child: Padding(
@@ -1465,7 +1465,7 @@ class DefaultAssetPickerBuilderDelegate
14651465
gradient: LinearGradient(
14661466
begin: AlignmentDirectional.topCenter,
14671467
end: AlignmentDirectional.bottomCenter,
1468-
colors: <Color>[theme.dividerColor, Colors.transparent],
1468+
colors: <Color>[theme.splashColor, Colors.transparent],
14691469
),
14701470
),
14711471
child: Padding(
@@ -1502,7 +1502,7 @@ class DefaultAssetPickerBuilderDelegate
15021502
height: appBarItemHeight,
15031503
padding: const EdgeInsets.symmetric(horizontal: 12),
15041504
color: theme.colorScheme.secondary,
1505-
disabledColor: theme.dividerColor,
1505+
disabledColor: theme.splashColor,
15061506
shape: RoundedRectangleBorder(
15071507
borderRadius: BorderRadius.circular(3),
15081508
),
@@ -1745,7 +1745,7 @@ class DefaultAssetPickerBuilderDelegate
17451745
padding: const EdgeInsetsDirectional.only(start: 12, end: 6),
17461746
decoration: BoxDecoration(
17471747
borderRadius: BorderRadius.circular(999),
1748-
color: theme.dividerColor,
1748+
color: theme.focusColor,
17491749
),
17501750
child: Selector<DefaultAssetPickerProvider,
17511751
PathWrapper<AssetPathEntity>?>(
@@ -2107,7 +2107,7 @@ class DefaultAssetPickerBuilderDelegate
21072107
gradient: LinearGradient(
21082108
begin: AlignmentDirectional.bottomCenter,
21092109
end: AlignmentDirectional.topCenter,
2110-
colors: <Color>[theme.dividerColor, Colors.transparent],
2110+
colors: <Color>[theme.splashColor, Colors.transparent],
21112111
),
21122112
),
21132113
child: Row(
@@ -2147,7 +2147,9 @@ class DefaultAssetPickerBuilderDelegate
21472147
padding: const EdgeInsets.symmetric(horizontal: 20).copyWith(
21482148
bottom: context.bottomPadding,
21492149
),
2150-
color: theme.primaryColor.withOpacity(isAppleOS(context) ? .9 : 1),
2150+
color: theme.bottomAppBarTheme.color?.withOpacity(
2151+
theme.bottomAppBarTheme.color!.opacity * (isAppleOS(context) ? .9 : 1),
2152+
),
21512153
child: Row(
21522154
children: <Widget>[
21532155
if (isPreviewEnabled) previewButton(context),
@@ -2162,15 +2164,17 @@ class DefaultAssetPickerBuilderDelegate
21622164
children: <Widget>[accessLimitedBottomTip(context), child],
21632165
);
21642166
}
2165-
child = ClipRect(
2166-
child: BackdropFilter(
2167-
filter: ui.ImageFilter.blur(
2168-
sigmaX: appleOSBlurRadius,
2169-
sigmaY: appleOSBlurRadius,
2167+
if (isAppleOS(context)) {
2168+
child = ClipRect(
2169+
child: BackdropFilter(
2170+
filter: ui.ImageFilter.blur(
2171+
sigmaX: appleOSBlurRadius,
2172+
sigmaY: appleOSBlurRadius,
2173+
),
2174+
child: child,
21702175
),
2171-
child: child,
2172-
),
2173-
);
2176+
);
2177+
}
21742178
return child;
21752179
}
21762180

lib/src/delegates/asset_picker_delegate.dart

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,30 @@ class AssetPickerDelegate {
241241
selectionHandleColor: themeColor,
242242
),
243243
indicatorColor: themeColor,
244-
appBarTheme: const AppBarTheme(
245-
systemOverlayStyle: SystemUiOverlayStyle(
244+
appBarTheme: AppBarTheme(
245+
backgroundColor: Colors.grey[100],
246+
systemOverlayStyle: const SystemUiOverlayStyle(
246247
statusBarBrightness: Brightness.light,
247248
statusBarIconBrightness: Brightness.dark,
248249
),
250+
iconTheme: IconThemeData(color: Colors.grey[900]),
249251
elevation: 0,
250252
),
253+
bottomAppBarTheme: BottomAppBarTheme(
254+
color: Colors.grey[100],
255+
),
251256
buttonTheme: ButtonThemeData(buttonColor: themeColor),
257+
iconTheme: IconThemeData(color: Colors.grey[900]),
258+
checkboxTheme: CheckboxThemeData(
259+
checkColor: MaterialStateProperty.all(Colors.black),
260+
fillColor: MaterialStateProperty.resolveWith((states) {
261+
if (states.contains(MaterialState.selected)) {
262+
return themeColor;
263+
}
264+
return null;
265+
}),
266+
side: const BorderSide(color: Colors.black),
267+
),
252268
colorScheme: ColorScheme(
253269
primary: Colors.grey[50]!,
254270
secondary: themeColor,
@@ -257,7 +273,7 @@ class AssetPickerDelegate {
257273
brightness: Brightness.light,
258274
error: const Color(0xffcf6679),
259275
onPrimary: Colors.white,
260-
onSecondary: Colors.white,
276+
onSecondary: Colors.grey[100]!,
261277
onSurface: Colors.black,
262278
onBackground: Colors.black,
263279
onError: Colors.white,
@@ -278,14 +294,30 @@ class AssetPickerDelegate {
278294
selectionHandleColor: themeColor,
279295
),
280296
indicatorColor: themeColor,
281-
appBarTheme: const AppBarTheme(
282-
systemOverlayStyle: SystemUiOverlayStyle(
297+
appBarTheme: AppBarTheme(
298+
backgroundColor: Colors.grey[850],
299+
systemOverlayStyle: const SystemUiOverlayStyle(
283300
statusBarBrightness: Brightness.dark,
284301
statusBarIconBrightness: Brightness.light,
285302
),
303+
iconTheme: const IconThemeData(color: Colors.white),
286304
elevation: 0,
287305
),
306+
bottomAppBarTheme: BottomAppBarTheme(
307+
color: Colors.grey[850],
308+
),
288309
buttonTheme: ButtonThemeData(buttonColor: themeColor),
310+
iconTheme: const IconThemeData(color: Colors.white),
311+
checkboxTheme: CheckboxThemeData(
312+
checkColor: MaterialStateProperty.all(Colors.white),
313+
fillColor: MaterialStateProperty.resolveWith((states) {
314+
if (states.contains(MaterialState.selected)) {
315+
return themeColor;
316+
}
317+
return null;
318+
}),
319+
side: const BorderSide(color: Colors.white),
320+
),
289321
colorScheme: ColorScheme(
290322
primary: Colors.grey[900]!,
291323
secondary: themeColor,
@@ -294,7 +326,7 @@ class AssetPickerDelegate {
294326
brightness: Brightness.dark,
295327
error: const Color(0xffcf6679),
296328
onPrimary: Colors.black,
297-
onSecondary: Colors.black,
329+
onSecondary: Colors.grey[850]!,
298330
onSurface: Colors.white,
299331
onBackground: Colors.white,
300332
onError: Colors.black,

lib/src/delegates/asset_picker_viewer_builder_delegate.dart

Lines changed: 41 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import '../delegates/asset_picker_text_delegate.dart';
2121
import '../internal/singleton.dart';
2222
import '../provider/asset_picker_provider.dart';
2323
import '../provider/asset_picker_viewer_provider.dart';
24+
import '../widget/asset_picker_app_bar.dart';
2425
import '../widget/asset_picker_viewer.dart';
2526
import '../widget/builder/audio_page_builder.dart';
2627
import '../widget/builder/fade_image_builder.dart';
@@ -537,7 +538,10 @@ class DefaultAssetPickerViewerBuilderDelegate
537538

538539
@override
539540
Widget bottomDetailBuilder(BuildContext context) {
540-
final Color backgroundColor = themeData.primaryColor.withOpacity(.9);
541+
final backgroundColor = themeData.bottomAppBarTheme.color?.withOpacity(
542+
themeData.bottomAppBarTheme.color!.opacity *
543+
(isAppleOS(context) ? .9 : 1),
544+
);
541545
return ValueListenableBuilder2<bool, int>(
542546
firstNotifier: isDisplayingDetail,
543547
secondNotifier: selectedNotifier,
@@ -694,72 +698,40 @@ class DefaultAssetPickerViewerBuilderDelegate
694698
/// AppBar widget.
695699
/// 顶栏部件
696700
Widget appBar(BuildContext context) {
697-
return ValueListenableBuilder<bool>(
698-
valueListenable: isDisplayingDetail,
699-
builder: (_, bool value, Widget? child) => AnimatedPositionedDirectional(
700-
duration: kThemeAnimationDuration,
701-
curve: Curves.easeInOut,
702-
top: value ? 0.0 : -(context.topPadding + kToolbarHeight),
703-
start: 0.0,
704-
end: 0.0,
705-
height: context.topPadding + kToolbarHeight,
706-
child: child!,
701+
return AssetPickerAppBar(
702+
leading: Semantics(
703+
sortKey: ordinalSortKey(0),
704+
child: IconButton(
705+
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
706+
onPressed: Navigator.of(context).maybePop,
707+
icon: const Icon(Icons.close),
708+
),
707709
),
708-
child: Container(
709-
padding: EdgeInsetsDirectional.only(top: context.topPadding),
710-
color: themeData.canvasColor,
711-
child: Row(
712-
children: <Widget>[
713-
Expanded(
714-
child: Align(
715-
alignment: AlignmentDirectional.centerStart,
716-
child: Semantics(
717-
sortKey: ordinalSortKey(0),
718-
child: IconButton(
719-
icon: const Icon(Icons.close),
720-
tooltip: MaterialLocalizations.of(
721-
context,
722-
).backButtonTooltip,
723-
onPressed: Navigator.of(context).maybePop,
710+
centerTitle: true,
711+
title: specialPickerType == null
712+
? Semantics(
713+
sortKey: ordinalSortKey(0.1),
714+
child: StreamBuilder<int>(
715+
initialData: currentIndex,
716+
stream: pageStreamController.stream,
717+
builder: (_, AsyncSnapshot<int> snapshot) => ScaleText(
718+
'${snapshot.requireData + 1}/${previewAssets.length}',
719+
style: const TextStyle(
720+
fontSize: 17,
721+
fontWeight: FontWeight.w500,
724722
),
725723
),
726724
),
727-
),
728-
if (specialPickerType == null)
729-
Expanded(
730-
child: Center(
731-
child: Semantics(
732-
sortKey: ordinalSortKey(0.1),
733-
child: StreamBuilder<int>(
734-
initialData: currentIndex,
735-
stream: pageStreamController.stream,
736-
builder: (_, AsyncSnapshot<int> snapshot) => ScaleText(
737-
'${snapshot.requireData + 1}/${previewAssets.length}',
738-
style: const TextStyle(
739-
fontSize: 17,
740-
fontWeight: FontWeight.w500,
741-
),
742-
),
743-
),
744-
),
745-
),
746-
),
747-
if (provider != null)
748-
Expanded(
749-
child: Container(
750-
alignment: AlignmentDirectional.centerEnd,
751-
padding: const EdgeInsetsDirectional.only(end: 14),
752-
child: Semantics(
753-
sortKey: ordinalSortKey(0.2),
754-
child: selectButton(context),
755-
),
756-
),
757-
)
758-
else
759-
const Spacer(),
760-
],
761-
),
762-
),
725+
)
726+
: null,
727+
actions: [
728+
if (provider != null)
729+
Semantics(
730+
sortKey: ordinalSortKey(0.2),
731+
child: selectButton(context),
732+
),
733+
const SizedBox(width: 14),
734+
],
763735
);
764736
}
765737

@@ -819,7 +791,7 @@ class DefaultAssetPickerViewerBuilderDelegate
819791
height: 32,
820792
padding: const EdgeInsets.symmetric(horizontal: 12),
821793
color: themeData.colorScheme.secondary,
822-
disabledColor: themeData.dividerColor,
794+
disabledColor: themeData.splashColor,
823795
shape: RoundedRectangleBorder(
824796
borderRadius: BorderRadius.circular(3),
825797
),
@@ -911,13 +883,12 @@ class DefaultAssetPickerViewerBuilderDelegate
911883
builder: (_, Widget? w) => StreamBuilder<int>(
912884
initialData: currentIndex,
913885
stream: pageStreamController.stream,
914-
builder: (BuildContext _, AsyncSnapshot<int> s) {
886+
builder: (_, s) {
915887
final AssetEntity asset = previewAssets.elementAt(s.data!);
916888
return Selector<AssetPickerViewerProvider<AssetEntity>,
917889
List<AssetEntity>>(
918-
selector: (_, AssetPickerViewerProvider<AssetEntity> p) =>
919-
p.currentlySelectedAssets,
920-
builder: (BuildContext c, List<AssetEntity> assets, _) {
890+
selector: (_, p) => p.currentlySelectedAssets,
891+
builder: (context, assets, _) {
921892
final bool isSelected = assets.contains(asset);
922893
return Semantics(
923894
selected: isSelected,
@@ -929,9 +900,9 @@ class DefaultAssetPickerViewerBuilderDelegate
929900
mainAxisAlignment: MainAxisAlignment.end,
930901
children: <Widget>[
931902
if (isAppleOS(context))
932-
_appleOSSelectButton(c, isSelected, asset)
903+
_appleOSSelectButton(context, isSelected, asset)
933904
else
934-
_androidSelectButton(c, isSelected, asset),
905+
_androidSelectButton(context, isSelected, asset),
935906
if (!isAppleOS(context))
936907
ScaleText(
937908
textDelegate.select,

lib/src/widget/asset_picker_app_bar.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ class AssetPickerAppBar extends StatelessWidget implements PreferredSizeWidget {
102102
@override
103103
Widget build(BuildContext context) {
104104
final ThemeData theme = Theme.of(context);
105-
final AppBarTheme appBarTheme = theme.appBarTheme;
106-
final IconThemeData iconTheme = this.iconTheme ?? theme.iconTheme;
107105
final Widget? titleWidget;
108106
if (centerTitle) {
109107
titleWidget = Center(child: title);
@@ -174,16 +172,20 @@ class AssetPickerAppBar extends StatelessWidget implements PreferredSizeWidget {
174172
);
175173
}
176174

177-
/// Apply the icon theme data.
178-
child = IconTheme.merge(data: iconTheme, child: child);
175+
final AppBarTheme appBarTheme = theme.appBarTheme;
179176

180-
final Color effectiveBackgroundColor =
181-
backgroundColor ?? theme.colorScheme.surface;
177+
/// Apply the icon theme data.
178+
child = IconTheme.merge(
179+
data: iconTheme ?? appBarTheme.iconTheme ?? theme.iconTheme,
180+
child: child,
181+
);
182182

183183
// Set [SystemUiOverlayStyle] according to the brightness.
184184
final Brightness effectiveBrightness = brightness ??
185185
appBarTheme.systemOverlayStyle?.statusBarBrightness ??
186186
theme.brightness;
187+
final Color effectiveBackgroundColor =
188+
backgroundColor ?? theme.colorScheme.surface;
187189
final SystemUiOverlayStyle overlayStyle = appBarTheme.systemOverlayStyle ??
188190
SystemUiOverlayStyle(
189191
statusBarColor: effectiveBackgroundColor,

0 commit comments

Comments
 (0)