Skip to content

Commit 74b892a

Browse files
authored
✨ Implement the default light theme (#234)
1 parent 1abb871 commit 74b892a

File tree

6 files changed

+68
-4
lines changed

6 files changed

+68
-4
lines changed

example/lib/constants/picker_method.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,25 @@ class PickMethod {
317317
);
318318
}
319319

320+
factory PickMethod.customizableTheme(int maxAssetsCount) {
321+
return PickMethod(
322+
icon: '🎨',
323+
name: 'Customizable theme',
324+
description: 'Picking assets with the light theme with different color.',
325+
method: (BuildContext context, List<AssetEntity> assets) {
326+
return AssetPicker.pickAssets(
327+
context,
328+
maxAssets: maxAssetsCount,
329+
selectedAssets: assets,
330+
pickerTheme: AssetPicker.themeData(
331+
Colors.lightBlueAccent,
332+
light: true,
333+
),
334+
);
335+
},
336+
);
337+
}
338+
320339
final String icon;
321340
final String name;
322341
final String description;

example/lib/pages/multi_assets_page.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class _MultiAssetsPageState extends State<MultiAssetsPage>
4848
},
4949
),
5050
PickMethod.noPreview(maxAssetsCount),
51+
PickMethod.customizableTheme(maxAssetsCount),
5152
PickMethod.customFilterOptions(maxAssetsCount),
5253
PickMethod.preventGIFPicked(maxAssetsCount),
5354
PickMethod.keepScrollOffset(

example/lib/pages/single_assets_page.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class _SingleAssetPageState extends State<SingleAssetPage>
3939
PickMethod.customFilterOptions(maxAssetsCount),
4040
PickMethod.preventGIFPicked(maxAssetsCount),
4141
PickMethod.noPreview(maxAssetsCount),
42+
PickMethod.customizableTheme(maxAssetsCount),
4243
];
4344
}
4445

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,11 @@ class DefaultAssetPickerBuilderDelegate
759759

760760
/// [Duration] when triggering path switching.
761761
/// 切换路径时的动画时长
762-
Duration get switchingPathDuration => kThemeAnimationDuration;
762+
Duration get switchingPathDuration => const Duration(milliseconds: 300);
763763

764764
/// [Curve] when triggering path switching.
765765
/// 切换路径时的动画曲线
766-
Curve get switchingPathCurve => Curves.easeInOut;
766+
Curve get switchingPathCurve => Curves.easeInOutQuad;
767767

768768
/// Whether the [SpecialPickerType.wechatMoment] is enabled.
769769
/// 当前是否为微信朋友圈选择模式

lib/src/delegates/asset_picker_viewer_builder_delegate.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ class DefaultAssetPickerViewerBuilderDelegate
983983
? SystemUiOverlayStyle.light
984984
: SystemUiOverlayStyle.dark),
985985
child: Material(
986-
color: Colors.black,
986+
color: themeData.colorScheme.onSecondary,
987987
child: Stack(
988988
children: <Widget>[
989989
Positioned.fill(child: _pageViewBuilder(context)),

lib/src/widget/asset_picker.dart

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,50 @@ class AssetPicker<Asset, Path> extends StatefulWidget {
199199

200200
/// Build a dark theme according to the theme color.
201201
/// 通过主题色构建一个默认的暗黑主题
202-
static ThemeData themeData(Color themeColor) {
202+
static ThemeData themeData(Color themeColor, {bool light = false}) {
203+
if (light) {
204+
return ThemeData.light().copyWith(
205+
primaryColor: Colors.grey[50],
206+
primaryColorBrightness: Brightness.dark,
207+
primaryColorLight: Colors.grey[50],
208+
primaryColorDark: Colors.grey[50],
209+
canvasColor: Colors.grey[100],
210+
scaffoldBackgroundColor: Colors.grey[50],
211+
bottomAppBarColor: Colors.grey[50],
212+
cardColor: Colors.grey[50],
213+
highlightColor: Colors.transparent,
214+
toggleableActiveColor: themeColor,
215+
textSelectionTheme: TextSelectionThemeData(
216+
cursorColor: themeColor,
217+
selectionColor: themeColor.withAlpha(100),
218+
selectionHandleColor: themeColor,
219+
),
220+
indicatorColor: themeColor,
221+
appBarTheme: const AppBarTheme(
222+
systemOverlayStyle: SystemUiOverlayStyle(
223+
statusBarBrightness: Brightness.light,
224+
statusBarIconBrightness: Brightness.dark,
225+
),
226+
elevation: 0,
227+
),
228+
buttonTheme: ButtonThemeData(buttonColor: themeColor),
229+
colorScheme: ColorScheme(
230+
primary: Colors.grey[50]!,
231+
primaryVariant: Colors.grey[50]!,
232+
secondary: themeColor,
233+
secondaryVariant: themeColor,
234+
background: Colors.grey[50]!,
235+
surface: Colors.grey[50]!,
236+
brightness: Brightness.light,
237+
error: const Color(0xffcf6679),
238+
onPrimary: Colors.white,
239+
onSecondary: Colors.white,
240+
onSurface: Colors.black,
241+
onBackground: Colors.black,
242+
onError: Colors.white,
243+
),
244+
);
245+
}
203246
return ThemeData.dark().copyWith(
204247
primaryColor: Colors.grey[900],
205248
primaryColorBrightness: Brightness.dark,

0 commit comments

Comments
 (0)