Skip to content

Commit 77383af

Browse files
committed
🎨 Move static method from assets picker.
1 parent feab727 commit 77383af

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
///
2+
/// [Author] Alex (https://github.com/AlexV525)
3+
/// [Date] 2020/7/15 21:44
4+
///
5+
import 'package:flutter/material.dart';
6+
7+
/// Built a slide page transition for the picker.
8+
/// 为选择器构造一个上下进出的页面过渡动画
9+
class SlidePageTransitionBuilder<T> extends PageRoute<T> {
10+
SlidePageTransitionBuilder({
11+
@required this.builder,
12+
this.transitionCurve = Curves.easeIn,
13+
this.transitionDuration = const Duration(milliseconds: 500),
14+
});
15+
16+
final Widget builder;
17+
18+
final Curve transitionCurve;
19+
20+
@override
21+
final Duration transitionDuration;
22+
23+
@override
24+
final bool opaque = true;
25+
26+
@override
27+
final bool barrierDismissible = false;
28+
29+
@override
30+
final bool maintainState = true;
31+
32+
@override
33+
Color get barrierColor => null;
34+
35+
@override
36+
String get barrierLabel => null;
37+
38+
@override
39+
Widget buildPage(
40+
BuildContext context,
41+
Animation<double> animation,
42+
Animation<double> secondaryAnimation,
43+
) {
44+
return builder;
45+
}
46+
47+
@override
48+
Widget buildTransitions(
49+
BuildContext context,
50+
Animation<double> animation,
51+
Animation<double> secondaryAnimation,
52+
Widget child,
53+
) {
54+
return SlideTransition(
55+
position: Tween<Offset>(
56+
begin: const Offset(0, 1),
57+
end: Offset.zero,
58+
).animate(CurvedAnimation(
59+
curve: transitionCurve,
60+
parent: animation,
61+
)),
62+
child: child,
63+
);
64+
}
65+
}

lib/src/widget/camera_picker.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,69 @@ class CameraPicker extends StatefulWidget {
3939

4040
final ThemeData theme;
4141

42+
/// Static method to create [AssetEntity] through camera.
43+
/// 通过相机创建 [AssetEntity] 的静态方法
44+
static Future<AssetEntity> pickFromCamera(
45+
BuildContext context, {
46+
bool shouldKeptInLocal = true,
47+
}) async {
48+
final AssetEntity result = await Navigator.of(
49+
context,
50+
rootNavigator: true,
51+
).push<AssetEntity>(
52+
SlidePageTransitionBuilder<AssetEntity>(
53+
builder: CameraPicker(
54+
shouldKeptInLocal: shouldKeptInLocal,
55+
),
56+
transitionCurve: Curves.easeIn,
57+
transitionDuration: const Duration(milliseconds: 300),
58+
),
59+
);
60+
return result;
61+
}
62+
63+
/// Build a dark theme according to the theme color.
64+
/// 通过主题色构建一个默认的暗黑主题
65+
static ThemeData themeData(Color themeColor) => ThemeData.dark().copyWith(
66+
buttonColor: themeColor,
67+
brightness: Brightness.dark,
68+
primaryColor: Colors.grey[900],
69+
primaryColorBrightness: Brightness.dark,
70+
primaryColorLight: Colors.grey[900],
71+
primaryColorDark: Colors.grey[900],
72+
accentColor: themeColor,
73+
accentColorBrightness: Brightness.dark,
74+
canvasColor: Colors.grey[850],
75+
scaffoldBackgroundColor: Colors.grey[900],
76+
bottomAppBarColor: Colors.grey[900],
77+
cardColor: Colors.grey[900],
78+
highlightColor: Colors.transparent,
79+
toggleableActiveColor: themeColor,
80+
cursorColor: themeColor,
81+
textSelectionColor: themeColor.withAlpha(100),
82+
textSelectionHandleColor: themeColor,
83+
indicatorColor: themeColor,
84+
appBarTheme: const AppBarTheme(
85+
brightness: Brightness.dark,
86+
elevation: 0,
87+
),
88+
colorScheme: ColorScheme(
89+
primary: Colors.grey[900],
90+
primaryVariant: Colors.grey[900],
91+
secondary: themeColor,
92+
secondaryVariant: themeColor,
93+
background: Colors.grey[900],
94+
surface: Colors.grey[900],
95+
brightness: Brightness.dark,
96+
error: const Color(0xffcf6679),
97+
onPrimary: Colors.black,
98+
onSecondary: Colors.black,
99+
onSurface: Colors.white,
100+
onBackground: Colors.white,
101+
onError: Colors.black,
102+
),
103+
);
104+
42105
@override
43106
_CameraPickerState createState() => _CameraPickerState();
44107
}
@@ -85,6 +148,8 @@ class _CameraPickerState extends State<CameraPicker> {
85148
@override
86149
void initState() {
87150
super.initState();
151+
_theme = widget.theme ?? CameraPicker.themeData(C.themeColor);
152+
88153
// TODO(Alex): Currently hide status bar will cause the viewport shaking on Android.
89154
/// Hide system status bar automatically on iOS.
90155
/// 在iOS设备上自动隐藏状态栏

0 commit comments

Comments
 (0)