Skip to content

Commit 0d71045

Browse files
authored
⚡️ Improve theme (#713)
Resolves #712. The PR also improves by inheriting the base theme rather than standalone constructors.
1 parent 74267bb commit 0d71045

15 files changed

+41
-131
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,24 @@ that can be found in the LICENSE file. -->
1111

1212
*None.*
1313

14+
## 9.8.0
15+
16+
> [!NOTE]
17+
> Be aware of potential minor theme changes since the base theme has taken place in the picker's theme.
18+
19+
**Improvements**
20+
21+
- Improve themes by inheriting the base theme rather than standalone constructors.
22+
23+
**Fixes**
24+
25+
- Enabling using the package on Flutter 3.35.
26+
1427
## 9.7.0
1528

1629
**Improvements**
1730

18-
- Allows to specify the fallback text delegate through `assetPickerTextDelegateFromLocale`.
31+
- Allows specifying the fallback text delegate through `assetPickerTextDelegateFromLocale`.
1932

2033
## 9.6.0
2134

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ include: package:flutter_lints/flutter.yaml
33
analyzer:
44
errors:
55
deprecated_member_use: ignore
6+
deprecated_member_use_from_same_package: ignore
67

78
linter:
89
rules:

example/lib/customs/pickers/directory_file_asset_picker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ class FileAssetPickerBuilder
806806
borderRadius: isAppleOS(context)
807807
? const BorderRadius.vertical(bottom: Radius.circular(10.0))
808808
: null,
809-
color: theme.colorScheme.background,
809+
color: theme.colorScheme.surface,
810810
),
811811
child: w,
812812
),

example/lib/customs/pickers/insta_asset_picker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ class InstaAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
743743
padding: const EdgeInsets.all(4),
744744
color: isPreview
745745
? theme.unselectedWidgetColor.withOpacity(.5)
746-
: theme.colorScheme.background.withOpacity(.1),
746+
: theme.colorScheme.surface.withOpacity(.1),
747747
child: Align(
748748
alignment: AlignmentDirectional.topEnd,
749749
child: isSelected && !isSingleAssetMode

example/lib/main.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import 'package:flutter/material.dart';
66
import 'package:flutter/services.dart';
77
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
8-
import 'package:wechat_assets_picker_demo/l10n/gen/app_localizations.dart';
98

109
import 'constants/extensions.dart';
10+
import 'l10n/gen/app_localizations.dart';
1111
import 'pages/splash_page.dart';
1212

1313
const Color themeColor = Color(0xff00bc56);
@@ -28,10 +28,11 @@ class MyApp extends StatelessWidget {
2828
const MyApp({super.key});
2929

3030
ThemeData _buildTheme(Brightness brightness) {
31-
return ThemeData(
32-
brightness: brightness,
33-
primarySwatch: themeColor.swatch,
34-
textSelectionTheme: const TextSelectionThemeData(cursorColor: themeColor),
31+
return ThemeData.from(
32+
colorScheme: ColorScheme.fromSwatch(
33+
primarySwatch: themeColor.swatch,
34+
brightness: brightness,
35+
),
3536
);
3637
}
3738

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: wechat_assets_picker_demo
22
description: The demo project for the wechat_assets_picker package.
3-
version: 9.7.0+68
3+
version: 9.8.0+69
44
publish_to: none
55

66
environment:

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'dart:math' as math;
77
import 'dart:ui' as ui;
88

99
import 'package:flutter/gestures.dart';
10-
import 'package:flutter/material.dart';
10+
import 'package:flutter/material.dart' hide Path;
1111
import 'package:flutter/semantics.dart';
1212
import 'package:flutter/services.dart';
1313
import 'package:photo_manager/photo_manager.dart';
@@ -564,7 +564,7 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
564564
builder: (_, AssetPickerProvider<Asset, Path> p, __) {
565565
if (!p.selectedAssets.contains(asset) && p.selectedMaximumAssets) {
566566
return Container(
567-
color: theme.colorScheme.background.withOpacity(.85),
567+
color: theme.colorScheme.surface.withOpacity(.85),
568568
);
569569
}
570570
return const SizedBox.shrink();
@@ -2006,7 +2006,7 @@ class DefaultAssetPickerBuilderDelegate
20062006
maxHeight: MediaQuery.sizeOf(context).height *
20072007
(isAppleOS(context) ? .6 : .8),
20082008
),
2009-
color: theme.colorScheme.background,
2009+
color: theme.colorScheme.surface,
20102010
child: child,
20112011
),
20122012
),
@@ -2343,7 +2343,7 @@ class DefaultAssetPickerBuilderDelegate
23432343
p.selectedAssets.isNotEmpty);
23442344
if (isDisabled) {
23452345
return Container(
2346-
color: theme.colorScheme.background.withOpacity(.85),
2346+
color: theme.colorScheme.surface.withOpacity(.85),
23472347
);
23482348
}
23492349
return const SizedBox.shrink();
@@ -2431,7 +2431,7 @@ class DefaultAssetPickerBuilderDelegate
24312431
padding: EdgeInsets.all(indicatorSize * .35),
24322432
color: selected
24332433
? theme.colorScheme.primary.withOpacity(.45)
2434-
: theme.colorScheme.background.withOpacity(.1),
2434+
: theme.colorScheme.surface.withOpacity(.1),
24352435
child: selected && !isSingleAssetMode
24362436
? Align(
24372437
alignment: AlignmentDirectional.topStart,

lib/src/delegates/asset_picker_delegate.dart

Lines changed: 4 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// Use of this source code is governed by an Apache license that can be found
33
// in the LICENSE file.
44

5-
import 'package:flutter/material.dart';
5+
import 'package:flutter/material.dart' hide Path;
66
import 'package:flutter/services.dart';
77
import 'package:photo_manager/photo_manager.dart';
8-
import 'package:wechat_picker_library/wechat_picker_library.dart';
8+
import 'package:wechat_picker_library/wechat_picker_library.dart'
9+
show buildTheme;
910

1011
import '../constants/config.dart';
1112
import '../constants/constants.dart';
@@ -243,112 +244,6 @@ class AssetPickerDelegate {
243244
/// 设置 [light] 为 true 时可以获取浅色版本的主题。
244245
/// {@endtemplate}
245246
ThemeData themeData(Color? themeColor, {bool light = false}) {
246-
themeColor ??= defaultThemeColorWeChat;
247-
if (light) {
248-
return ThemeData.light().copyWith(
249-
primaryColor: Colors.grey[50],
250-
primaryColorLight: Colors.grey[50],
251-
primaryColorDark: Colors.grey[50],
252-
canvasColor: Colors.grey[100],
253-
scaffoldBackgroundColor: Colors.grey[50],
254-
cardColor: Colors.grey[50],
255-
highlightColor: Colors.transparent,
256-
textSelectionTheme: TextSelectionThemeData(
257-
cursorColor: themeColor,
258-
selectionColor: themeColor.withAlpha(100),
259-
selectionHandleColor: themeColor,
260-
),
261-
indicatorColor: themeColor,
262-
appBarTheme: AppBarTheme(
263-
backgroundColor: Colors.grey[100],
264-
systemOverlayStyle: const SystemUiOverlayStyle(
265-
statusBarBrightness: Brightness.light,
266-
statusBarIconBrightness: Brightness.dark,
267-
),
268-
iconTheme: IconThemeData(color: Colors.grey[900]),
269-
elevation: 0,
270-
),
271-
bottomAppBarTheme: BottomAppBarTheme(
272-
color: Colors.grey[100],
273-
),
274-
buttonTheme: ButtonThemeData(buttonColor: themeColor),
275-
iconTheme: IconThemeData(color: Colors.grey[900]),
276-
checkboxTheme: CheckboxThemeData(
277-
checkColor: MaterialStateProperty.all(Colors.black),
278-
fillColor: MaterialStateProperty.resolveWith((states) {
279-
if (states.contains(MaterialState.selected)) {
280-
return themeColor;
281-
}
282-
return null;
283-
}),
284-
side: const BorderSide(color: Colors.black),
285-
),
286-
colorScheme: ColorScheme(
287-
primary: Colors.grey[50]!,
288-
secondary: themeColor,
289-
background: Colors.grey[50]!,
290-
surface: Colors.grey[50]!,
291-
brightness: Brightness.light,
292-
error: const Color(0xffcf6679),
293-
onPrimary: Colors.white,
294-
onSecondary: Colors.grey[100]!,
295-
onSurface: Colors.black,
296-
onBackground: Colors.black,
297-
onError: Colors.white,
298-
),
299-
);
300-
}
301-
return ThemeData.dark().copyWith(
302-
primaryColor: Colors.grey[900],
303-
primaryColorLight: Colors.grey[900],
304-
primaryColorDark: Colors.grey[900],
305-
canvasColor: Colors.grey[850],
306-
scaffoldBackgroundColor: Colors.grey[900],
307-
cardColor: Colors.grey[900],
308-
highlightColor: Colors.transparent,
309-
textSelectionTheme: TextSelectionThemeData(
310-
cursorColor: themeColor,
311-
selectionColor: themeColor.withAlpha(100),
312-
selectionHandleColor: themeColor,
313-
),
314-
indicatorColor: themeColor,
315-
appBarTheme: AppBarTheme(
316-
backgroundColor: Colors.grey[850],
317-
systemOverlayStyle: const SystemUiOverlayStyle(
318-
statusBarBrightness: Brightness.dark,
319-
statusBarIconBrightness: Brightness.light,
320-
),
321-
iconTheme: const IconThemeData(color: Colors.white),
322-
elevation: 0,
323-
),
324-
bottomAppBarTheme: BottomAppBarTheme(
325-
color: Colors.grey[850],
326-
),
327-
buttonTheme: ButtonThemeData(buttonColor: themeColor),
328-
iconTheme: const IconThemeData(color: Colors.white),
329-
checkboxTheme: CheckboxThemeData(
330-
checkColor: MaterialStateProperty.all(Colors.white),
331-
fillColor: MaterialStateProperty.resolveWith((states) {
332-
if (states.contains(MaterialState.selected)) {
333-
return themeColor;
334-
}
335-
return null;
336-
}),
337-
side: const BorderSide(color: Colors.white),
338-
),
339-
colorScheme: ColorScheme(
340-
primary: Colors.grey[900]!,
341-
secondary: themeColor,
342-
background: Colors.grey[900]!,
343-
surface: Colors.grey[900]!,
344-
brightness: Brightness.dark,
345-
error: const Color(0xffcf6679),
346-
onPrimary: Colors.black,
347-
onSecondary: Colors.grey[850]!,
348-
onSurface: Colors.white,
349-
onBackground: Colors.white,
350-
onError: Colors.black,
351-
),
352-
);
247+
return buildTheme(themeColor, light: light);
353248
}
354249
}

lib/src/delegates/asset_picker_viewer_builder_delegate.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'dart:async';
66
import 'dart:math' as math;
77

88
import 'package:extended_image/extended_image.dart';
9-
import 'package:flutter/material.dart';
9+
import 'package:flutter/material.dart' hide Path;
1010
import 'package:flutter/semantics.dart';
1111
import 'package:flutter/services.dart';
1212
import 'package:photo_manager/photo_manager.dart';

lib/src/provider/asset_picker_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'dart:io';
77
import 'dart:math' as math;
88
import 'dart:typed_data';
99

10-
import 'package:flutter/material.dart';
10+
import 'package:flutter/material.dart' hide Path;
1111
import 'package:photo_manager/photo_manager.dart';
1212
import 'package:provider/provider.dart';
1313

0 commit comments

Comments
 (0)