Skip to content

🐛 Make ThemeData properly wraps the content #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 78 additions & 44 deletions lib/src/states/camera_picker_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,10 @@ class CameraPickerState extends State<CameraPicker>
return const SizedBox.shrink();
}
Widget backButton = buildBackButton(context);
Widget flashModeSwitch = buildFlashModeSwitch(context, v);
Widget flashModeSwitch = buildFlashModeSwitch(
context: context,
cameraValue: v,
);
if (isCameraRotated && !enableScaledPreview) {
backButton = RotatedBox(
quarterTurns: cameraQuarterTurns,
Expand Down Expand Up @@ -1296,9 +1299,12 @@ class CameraPickerState extends State<CameraPicker>

/// The button to switch flash modes.
/// 切换闪光灯模式的按钮
Widget buildFlashModeSwitch(BuildContext context, CameraValue value) {
Widget buildFlashModeSwitch({
required BuildContext context,
required CameraValue cameraValue,
}) {
final IconData icon;
switch (value.flashMode) {
switch (cameraValue.flashMode) {
case FlashMode.off:
icon = Icons.flash_off;
break;
Expand All @@ -1313,15 +1319,18 @@ class CameraPickerState extends State<CameraPicker>
break;
}
return IconButton(
onPressed: () => switchFlashesMode(value),
tooltip: textDelegate.sFlashModeLabel(value.flashMode),
onPressed: () => switchFlashesMode(cameraValue),
tooltip: textDelegate.sFlashModeLabel(cameraValue.flashMode),
icon: Icon(icon, size: 24),
);
}

/// Text widget for shooting tips.
/// 拍摄的提示文字
Widget buildCaptureTips(CameraController? controller) {
Widget buildCaptureTips({
required BuildContext context,
CameraController? controller,
}) {
return AnimatedOpacity(
duration: recordDetectDuration,
opacity: controller?.value.isRecordingVideo ?? false ? 0 : 1,
Expand Down Expand Up @@ -1398,7 +1407,10 @@ class CameraPickerState extends State<CameraPicker>
const Spacer(),
Expanded(
child: Center(
child: buildCaptureButton(context, constraints),
child: buildCaptureButton(
context: context,
constraints: constraints,
),
),
),
if (controller != null &&
Expand Down Expand Up @@ -1429,7 +1441,10 @@ class CameraPickerState extends State<CameraPicker>

/// The shooting button.
/// 拍照按钮
Widget buildCaptureButton(BuildContext context, BoxConstraints constraints) {
Widget buildCaptureButton({
required BuildContext context,
required BoxConstraints constraints,
}) {
final showProgressIndicator =
isCaptureButtonTapDown || MediaQuery.accessibleNavigationOf(context);

Expand Down Expand Up @@ -1500,7 +1515,8 @@ class CameraPickerState extends State<CameraPicker>
showProgressIndicator && isShootingButtonAnimate,
duration: pickerConfig.maximumRecordingDuration!,
size: size,
ringsColor: theme.indicatorColor,
// ignore: deprecated_member_use
ringsColor: Theme.of(context).indicatorColor,
ringsWidth: 3,
),
),
Expand All @@ -1514,13 +1530,14 @@ class CameraPickerState extends State<CameraPicker>
}

Widget buildExposureSlider({
required BuildContext context,
required ExposureMode mode,
required double size,
required double height,
required double gap,
}) {
final bool isLocked = mode == ExposureMode.locked;
final Color? color = isLocked ? _lockedColor : theme.iconTheme.color;
final color = isLocked ? _lockedColor : Theme.of(context).iconTheme.color;
final Widget lineWidget = ValueListenableBuilder<bool>(
valueListenable: isFocusPointDisplays,
builder: (_, bool value, Widget? child) => AnimatedOpacity(
Expand Down Expand Up @@ -1580,6 +1597,7 @@ class CameraPickerState extends State<CameraPicker>
/// The area widget for the last exposure point that user manually set.
/// 用户手动设置的曝光点的区域显示
Widget buildFocusingPoint({
required BuildContext context,
required CameraValue cameraValue,
required BoxConstraints constraints,
int quarterTurns = 0,
Expand Down Expand Up @@ -1612,6 +1630,7 @@ class CameraPickerState extends State<CameraPicker>
const SizedBox(height: verticalGap),
Expanded(
child: buildExposureSlider(
context: context,
mode: exposureMode,
size: size,
height: height,
Expand Down Expand Up @@ -1698,7 +1717,7 @@ class CameraPickerState extends State<CameraPicker>
size: pointWidth,
color: cameraValue.exposureMode == ExposureMode.locked
? _lockedColor
: theme.iconTheme.color!,
: Theme.of(context).iconTheme.color,
),
),
),
Expand All @@ -1718,10 +1737,10 @@ class CameraPickerState extends State<CameraPicker>

/// The [GestureDetector] widget for setting exposure point manually.
/// 用于手动设置曝光点的 [GestureDetector]
Widget buildExposureDetector(
BuildContext context,
BoxConstraints constraints,
) {
Widget buildExposureDetector({
required BuildContext context,
required BoxConstraints constraints,
}) {
return Semantics(
label: textDelegate.sCameraPreviewLabel(
innerController?.description.lensDirection,
Expand Down Expand Up @@ -1812,8 +1831,9 @@ class CameraPickerState extends State<CameraPicker>
children: <Widget>[
preview,
if (pickerConfig.enableSetExposure)
buildExposureDetector(context, constraints),
buildExposureDetector(context: context, constraints: constraints),
buildFocusingPoint(
context: context,
cameraValue: cameraValue,
constraints: constraints,
quarterTurns: cameraQuarterTurns,
Expand Down Expand Up @@ -1865,11 +1885,11 @@ class CameraPickerState extends State<CameraPicker>
);
}

Widget buildForegroundBody(
BuildContext context,
BoxConstraints constraints,
Widget buildForegroundBody({
required BuildContext context,
required BoxConstraints constraints,
DeviceOrientation? deviceOrientation,
) {
}) {
final orientation = deviceOrientation ?? MediaQuery.orientationOf(context);
final isPortrait = orientation.toString().contains('portrait');
return SafeArea(
Expand All @@ -1888,7 +1908,12 @@ class CameraPickerState extends State<CameraPicker>
child: buildSettingActions(context),
),
const Spacer(),
ExcludeSemantics(child: buildCaptureTips(innerController)),
ExcludeSemantics(
child: buildCaptureTips(
context: context,
controller: innerController,
),
),
Semantics(
sortKey: const OrdinalSortKey(2),
hidden: innerController == null,
Expand Down Expand Up @@ -1974,9 +1999,13 @@ class CameraPickerState extends State<CameraPicker>
previewWidget,
if (enableScaledPreview) ...<Widget>[
if (pickerConfig.enableSetExposure)
buildExposureDetector(context, constraints),
buildExposureDetector(
context: context,
constraints: constraints,
),
buildInitializeWrapper(
builder: (CameraValue v, _) => buildFocusingPoint(
context: context,
cameraValue: v,
constraints: constraints,
),
Expand All @@ -1988,13 +2017,17 @@ class CameraPickerState extends State<CameraPicker>
),
],
if (innerController == null)
buildForegroundBody(context, constraints, null)
buildForegroundBody(
context: context,
constraints: constraints,
deviceOrientation: null,
)
else
buildInitializeWrapper(
builder: (CameraValue v, _) => buildForegroundBody(
context,
constraints,
v.deviceOrientation,
context: context,
constraints: constraints,
deviceOrientation: v.deviceOrientation,
),
),
],
Expand All @@ -2005,21 +2038,6 @@ class CameraPickerState extends State<CameraPicker>

@override
Widget build(BuildContext context) {
Widget body = Builder(builder: buildBody);
if (isCameraRotated && enableScaledPreview) {
final MediaQueryData mq = MediaQuery.of(context);
body = RotatedBox(
quarterTurns: pickerConfig.cameraQuarterTurns,
child: MediaQuery(
data: mq.copyWith(
size: pickerConfig.cameraQuarterTurns.isOdd
? mq.size.flipped
: mq.size,
),
child: body,
),
);
}
return AnnotatedRegion<SystemUiOverlayStyle>(
value: const SystemUiOverlayStyle(
systemNavigationBarIconBrightness: Brightness.light,
Expand All @@ -2028,9 +2046,25 @@ class CameraPickerState extends State<CameraPicker>
),
child: Theme(
data: theme,
child: Material(
color: Colors.black,
child: body,
child: Builder(
builder: (context) {
Widget body = buildBody(context);
if (isCameraRotated && enableScaledPreview) {
final MediaQueryData mq = MediaQuery.of(context);
body = RotatedBox(
quarterTurns: pickerConfig.cameraQuarterTurns,
child: MediaQuery(
data: mq.copyWith(
size: pickerConfig.cameraQuarterTurns.isOdd
? mq.size.flipped
: mq.size,
),
child: body,
),
);
}
return Material(color: Colors.black, child: body);
},
),
),
);
Expand Down
27 changes: 16 additions & 11 deletions lib/src/states/camera_picker_viewer_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class CameraPickerViewerState extends State<CameraPickerViewer> {
minWidth: 20,
height: 32,
padding: const EdgeInsets.symmetric(horizontal: 20),
color: theme.colorScheme.secondary,
color: Theme.of(context).colorScheme.secondary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(3),
),
Expand All @@ -298,7 +298,7 @@ class CameraPickerViewerState extends State<CameraPickerViewer> {
child: Text(
Singleton.textDelegate.confirm,
style: TextStyle(
color: theme.textTheme.bodyLarge?.color,
color: Theme.of(context).textTheme.bodyLarge?.color,
fontSize: 17,
fontWeight: FontWeight.normal,
),
Expand Down Expand Up @@ -402,15 +402,20 @@ class CameraPickerViewerState extends State<CameraPickerViewer> {
deletePreviewFileIfConfigured();
}
},
child: Material(
color: Colors.black,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
buildPreview(context),
buildForeground(context),
if (isSavingEntity) buildLoading(context),
],
child: Theme(
data: theme,
child: Builder(
builder: (context) => Material(
color: Colors.black,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
buildPreview(context),
buildForeground(context),
if (isSavingEntity) buildLoading(context),
],
),
),
),
),
);
Expand Down
8 changes: 5 additions & 3 deletions lib/src/widgets/camera_focus_point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class CameraFocusPoint extends StatelessWidget {
});

final double size;
final Color color;
final Color? color;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -51,7 +51,7 @@ final class CameraFocusPointPainter extends CustomPainter {
final double size;
final double radius;
final double strokeWidth;
final Color color;
final Color? color;

Radius get _circularRadius => Radius.circular(radius);

Expand All @@ -61,8 +61,10 @@ final class CameraFocusPointPainter extends CustomPainter {
final double lineLength = dividedSize.width - radius;
final Paint paint = Paint()
..style = PaintingStyle.stroke
..color = color
..strokeWidth = strokeWidth;
if (color != null) {
paint.color = color!;
}

final Path path = Path()
// Move to the start of the arc-line group at the left-top.
Expand Down
1 change: 1 addition & 0 deletions lib/src/widgets/camera_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class CameraPicker extends StatefulWidget {
selectionColor: themeColor.withAlpha(100),
selectionHandleColor: themeColor,
),
// ignore: deprecated_member_use
indicatorColor: themeColor,
appBarTheme: const AppBarTheme(
systemOverlayStyle: SystemUiOverlayStyle(
Expand Down
2 changes: 2 additions & 0 deletions lib/src/widgets/camera_picker_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CameraPickerViewer extends StatefulWidget {
/// 跳转至选择预览的静态方法
static Future<AssetEntity?> pushToViewer(
BuildContext context, {
Key? key,
required CameraPickerConfig pickerConfig,
required CameraPickerViewType viewType,
required XFile previewXFile,
Expand All @@ -53,6 +54,7 @@ class CameraPickerViewer extends StatefulWidget {
).push<AssetEntity?>(
PageRouteBuilder<AssetEntity?>(
pageBuilder: (_, __, ___) => CameraPickerViewer._(
key: key,
viewType: viewType,
previewXFile: previewXFile,
pickerConfig: pickerConfig,
Expand Down