@@ -39,6 +39,69 @@ class CameraPicker extends StatefulWidget {
39
39
40
40
final ThemeData theme;
41
41
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
+
42
105
@override
43
106
_CameraPickerState createState () => _CameraPickerState ();
44
107
}
@@ -85,6 +148,8 @@ class _CameraPickerState extends State<CameraPicker> {
85
148
@override
86
149
void initState () {
87
150
super .initState ();
151
+ _theme = widget.theme ?? CameraPicker .themeData (C .themeColor);
152
+
88
153
// TODO(Alex): Currently hide status bar will cause the viewport shaking on Android.
89
154
/// Hide system status bar automatically on iOS.
90
155
/// 在iOS设备上自动隐藏状态栏
0 commit comments