Skip to content

Commit c5d059f

Browse files
committed
♻️ Refactored theme constructor and getter with theme capability.
Fix #22 .
1 parent 4ad9104 commit c5d059f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/src/widget/asset_picker.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AssetPicker extends StatelessWidget {
2727
@required this.provider,
2828
this.pickerTheme,
2929
int gridCount = 4,
30-
Color themeColor = C.themeColor,
30+
Color themeColor,
3131
TextDelegate textDelegate,
3232
}) : assert(
3333
provider != null,
@@ -38,7 +38,8 @@ class AssetPicker extends StatelessWidget {
3838
'Theme and theme color cannot be set at the same time.',
3939
),
4040
gridCount = gridCount ?? 4,
41-
themeColor = themeColor ?? C.themeColor,
41+
themeColor =
42+
pickerTheme?.colorScheme?.primary ?? themeColor ?? C.themeColor,
4243
super(key: key) {
4344
Constants.textDelegate = textDelegate ?? DefaultTextDelegate();
4445
}
@@ -74,7 +75,7 @@ class AssetPicker extends StatelessWidget {
7475
int gridCount = 4,
7576
RequestType requestType = RequestType.image,
7677
List<AssetEntity> selectedAssets,
77-
Color themeColor = C.themeColor,
78+
Color themeColor,
7879
ThemeData pickerTheme,
7980
TextDelegate textDelegate,
8081
Curve routeCurve = Curves.easeIn,
@@ -183,8 +184,8 @@ class AssetPicker extends StatelessWidget {
183184
/// 切换路径时的动画时长
184185
Duration get switchingPathDuration => kThemeAnimationDuration * 1.5;
185186

186-
/// [ThemeData] for picker.
187-
/// 选择器使用的主题
187+
/// Build a dark theme according to the theme color.
188+
/// 通过主题色构建一个默认的暗黑主题
188189
static ThemeData themeData(Color themeColor) => ThemeData.dark().copyWith(
189190
buttonColor: themeColor,
190191
brightness: Brightness.dark,
@@ -210,8 +211,18 @@ class AssetPicker extends StatelessWidget {
210211
),
211212
);
212213

214+
/// [ThemeData] for picker.
215+
/// 选择器使用的主题
213216
ThemeData get theme => pickerTheme ?? themeData(themeColor);
214217

218+
/// Return a system ui overlay style according to
219+
/// the brightness of the theme data.
220+
/// 根据主题返回状态栏的明暗样式
221+
SystemUiOverlayStyle get overlayStyle =>
222+
theme.brightness == Brightness.light
223+
? SystemUiOverlayStyle.dark
224+
: SystemUiOverlayStyle.light;
225+
215226
/// Path entity select widget.
216227
/// 路径选择部件
217228
Widget get pathEntitySelector => UnconstrainedBox(
@@ -1082,7 +1093,7 @@ class AssetPicker extends StatelessWidget {
10821093
@override
10831094
Widget build(BuildContext context) {
10841095
return AnnotatedRegion<SystemUiOverlayStyle>(
1085-
value: SystemUiOverlayStyle.light,
1096+
value: overlayStyle,
10861097
child: Theme(
10871098
data: theme,
10881099
child: ChangeNotifierProvider<AssetPickerProvider>.value(

0 commit comments

Comments
 (0)